在postgres中将列展开为多个列

时间:2017-08-29 22:24:37

标签: sql postgresql

基本上这是我从小提琴中得到的结果:http://sqlfiddle.com/#!17/48a30/59

我的问题是如何将结果转换为

update_record
(1,t)
(null)
(3,t)
(null)
(5,t)
(null)

进入以下

col1 | col2
-----+-----
1    | t
3    | t
5    | t

1 个答案:

答案 0 :(得分:1)

基本上,应该在FROM子句中调用返回行集的函数。通过这种方式,您将获得常规列而不是结果集中的记录。

SELECT upd.*
FROM input,
update_record(input) AS upd
WHERE upd.id IS NOT NULL

 id | certified 
----+-----------
  1 | t
  3 | t
  5 | t
(3 rows)

SQLFiddle.

相关问题