culebrón
culebrón

Reputation: 36453

Call table-returning function on each row in Postgres

I have a table with an unknown amount of rows, let's say

-----
geom
-----
0123
3216
6549
...

And a function that returns table:

> select * from myFunc('line(1 2, 3 4, 5 6)'::geometry);
----------
val1 val2
----------
10   98
75   65

So I want to call this function for each row in the table above and union them. How do I do this?

Upvotes: 0

Views: 953

Answers (1)

Mike T
Mike T

Reputation: 43622

If myFunc is a set-returning function, you can move it from the FROM part to the SELECT part, while referencing each member of the set returning record type that you want.

SELECT the_table_with_geom.some_primary_key,
       (myFunc(geom)).val1, (myFunc(geom)).val2
FROM the_table_with_geom;

Upvotes: 1

Related Questions