Hacker News new | ask | show | jobs
by urams 45 days ago
Yes, I have a similar only usage but using JSONB_EACH. You can actually replace "CROSS JOIN LATERAL" with a comma which I think is clearer.

However, it working as a lateral join is critical as you need the function to fire for every row.

1 comments

> However, it working as a lateral join is critical as you need the function to fire for every row.

Right, what I mean is, for functions in the standard expression position, e.g. `SELECT COALESCE(..., 0)`, those functions will also fire for every row. jsonb_to_recordset however needs to know the schema of the table it will output, and the only way syntactically to declare the column types output by a function returning a recordset is in LATERAL clauses [0].

[0] https://www.postgresql.org/docs/current/sql-select.html