【发布时间】:2020-02-14 00:15:44
【问题描述】:
在 MySQL 中,我使用 GROUP_CONCAT() 函数,但现在我需要将其转换为 Postgres。谁能帮助我如何将此类查询转换为 Postgres?我认为唯一需要替换的是GROUP_CONCAT?
SET @sql = NULL;
SELECT CONCAT(
'SELECT ',GROUP_CONCAT(c.TABLE_NAME,'.',c.COLUMN_NAME,' AS `',c.TABLE_NAME,'.',c.COLUMN_NAME,'`'),'
from t1 AS thre
inner join t2 as ter on thre.datasource = ter.datasource
inner join t3 as ston on thre.datasource = ston.datasource
inner join t4 as diron on thre.datasource = diron.datasource'
)
INTO @sql
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.TABLE_NAME IN ('t1','t2',
't3','t4');
PREPARE sql_statement FROM @sql;
EXECUTE sql_statement;
【问题讨论】:
标签: sql postgresql string-aggregation