我正在尝试将选择查询的输出作为列列表传递给另一个选择查询。
select ARRAY_TO_STRING(ARRAY(SELECT distinct COLUMN_NAME::VARCHAR(50)
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='products' AND
COLUMN_NAME NOT IN ('code') ), ', ');
上面的查询将输出如下面的给出,
array_to_string
---------------------------
name, price, manufacturer
现在我需要将此输出作为列列表传递给另一个选择查询。所以我试着这样做,
select ( select ARRAY_TO_STRING(ARRAY(SELECT distinct
COLUMN_NAME::VARCHAR(50) FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME='products' AND COLUMN_NAME NOT IN ('code') ), ', ') )
from products;
但它无法正常工作。它给出了如下输出:
?column?
---------------------------
name, price, manufacturer
name, price, manufacturer
name, price, manufacturer
而不是,
name | price | manufacturer
-----------------+-------+--------------
Hard drive | 240 | 5
Memory | 120 | 6
ZIP drive | 150 | 4
那么,我该如何解决这个问题?