商店选择查询在在Postgres一个阵列输出 [英] Store select query's output in one array in postgres
本文介绍了商店选择查询在在Postgres一个阵列输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的code是
select column_name from information.schema.columns where table_name='aean'
它返回表中的列名 aean
。结果
现在,我宣布一个数组:
It returns column names of table aean
.
Now I have declared an array:
DECLARE colnames text[]
我如何选择存储在colnames阵列的输出。结果
是否有任何需要初始化colnames?
How can I store select's output in colnames array.
Is there any need to initialize colnames?
推荐答案
有两种方式。一是聚合:
There are two ways. One is to aggregate:
select array_agg(column_name::text)
from information.schema.columns
where table_name='aean'
另一种方法是使用数组()运算符:
The other is to use the array() operator:
select array(
select column_name
from information.schema.columns
where table_name='aean'
)
我是presuming这是PLPGSQL。在这种情况下,你可以指定它是这样的:
I'm presuming this is for plpgsql. In that case you can assign it like this:
colnames := array(
select column_name
from information.schema.columns
where table_name='aean'
);
这篇关于商店选择查询在在Postgres一个阵列输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文