PostgreSQL选择行(结果)作为数组 [英] Postgresql select rows(a result) as array
本文介绍了PostgreSQL选择行(结果)作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有下表以及一些数据。
Assume I have following table, plus some data.
create table "common"."log"("id" bigserial primary key,
"level" int not null default 0);
现在,我有了这个选择查询,它将返回类似这样的内容。
select * from common.log,其中id = 147;
Now I have this select query that would return something like this.
select * from common.log where id=147;
+------+--------+
|id |level |
+------+--------+
|147 |1 |
|147 |2 |
|147 |2 |
|147 |6 |
|147 |90 |
+------+--------+
现在,我希望有类似以下内容的提示
Now I like to have something like following rather above
+------+---------------+
|id |arr_level |
+------+---------------+
|147 |{1,2,2,6,90} |
+------+---------------+
那么有没有隐式的select子句/方式来做到这一点?谢谢。
pgsql v9.3
So is there any implicit select clause/way for doing this? thanks.
pgsql v9.3
推荐答案
您可以像这样使用用户数组功能
You can user array function like this
Select '147' as id,array(select level from common.log where id=147) as arr_level;
这篇关于PostgreSQL选择行(结果)作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文