当前位置:  开发笔记 > 前端 > 正文

Postgres向CONCAT函数传递了100多个参数

如何解决《Postgres向CONCAT函数传递了100多个参数》经验,为你挑选了1个好方法。

我有以下查询:

SELECT
"external_id" AS EVENT_ID,
"uuid"        AS EVENT_VERSION_ID,
"timestamp"   AS EVENT_VERSION_TIMESTAMP,
CONCAT('{',
'"timestamp": ', COALESCE(timestamp, NULL), ',',
'"uuid": ',   COALESCE("uuid", '"' || "uuid" || '"', 'null'), ',',
'"fraud": ',   COALESCE("fraud",'true','false', NULL), ',',
'"score": ', COALESCE("score", NULL), ',',
'"scoreTracking": ', COALESCE("scoreTracking", NULL), ',',
'"domain": ',   COALESCE("domain", '"' || "domain" || '"', NULL), ',',
'"event_occurred_at": ', COALESCE("event_occurred_at", NULL), ',',
'"event_received_at": ', COALESCE("event_received_at", NULL), ',',
'"event_type": ',   COALESCE("event_type", '"' || "event_type" || '"',     NULL), ',',
'"event_is_update": ',   COALESCE("event_is_update",'true', 'false', NULL), ',',
'"transaction_id": ',   COALESCE("transaction_id", '"' || "transaction_id" || '"', NULL), ',',
'"transaction_created_at": ', COALESCE("transaction_created_at", NULL), ',',
'"transaction_updated_at": ', COALESCE("transaction_updated_at", NULL), ',',
'"transaction_type": ',   COALESCE("transaction_type", '"' || "transaction_type" || '"', NULL), ',',
.
.
.
.
.
186 fields to concat......) AS EVENT_FIELDS;

然而,postgres不允许我传递超过100个参数.我在网上查了一下,发现了关于"variadic"参数的内容.但是,我不确定如何在这种情况下使用它.

提前谢谢了.



1> Vivek S...:

row_to_json() 是获得输出的最佳方式 {"timestamp:2017-01-01","uuid: 1255784",...}

SELECT "external_id" AS EVENT_ID
      ,"uuid" AS EVENT_VERSION_ID
      ,"timestamp" AS EVENT_VERSION_TIMESTAMP
      ,row_to_json(( --{"timestamp:2017-01-01","uuid: 1255784",...}
            SELECT t
            FROM (
                SELECT timestamp
                      ,uuid
                      ,fraud
                      ,score
                      ,event_occurred_at
                ) t
            )) AS EVENT_DATA
FROM your_table

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有