Jonathan
Jonathan

Reputation: 8901

Expand column into multiple columns in postgres

Basically this is the result that I get from the fiddle that you can find here: http://sqlfiddle.com/#!17/48a30/59

My question is how can you turn the result below

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

into the following

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

Upvotes: 0

Views: 306

Answers (1)

klin
klin

Reputation: 121774

Basically, functions which return set of rows should be called in the FROM clause. In this way you will get regular columns instead of records in the resultset.

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.

Upvotes: 1

Related Questions