david.g.johnston@xxxxxxxxx wrote:bryn@xxxxxxxxxxxx wrote:
Thanks, David. Thanks, too, to pavel.stehule@xxxxxxxxx for your separate reply that also says that I can rely on seeing the order in which I produce the rows in the function's implementation. And yes, I realize that Postgres table functions are not pipelined in the way that they can be, if you choose this, in Oracle Database. Given that the order is pre-calculated, it seems that "with ordinality" can add line numbering "after the fact" reliably and with minimum clutter when it's needed. I tried these two variants: create function f1() returns setof text language sql as $body$ values ('skiing'), ('cycling'), ('running'); $body$; and: create function f2() returns table(r text) language plpgsql as $body$ begin r := 'skiing'; return next; r := 'cycling'; return next; r := 'running'; return next; end; $body$; select t.line_no, t.report_text from f1() with ordinality as t(report_text, line_no); Each supports this same query select t.line_no, t.report_text from fN() with ordinality as t(report_text, line_no); and gets this same result: line_no | report_text ---------+------------- 1 | skiing 2 | cycling 3 | running |