Set returning functions in the SELECT list

From: Ryan Kelly <rpkelly22(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Set returning functions in the SELECT list
Date: 2012-11-16 14:14:33
Message-ID: 20121116141433.GA3716@llserver.lakeliving.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a question about the behavior of SRFs in the SELECT list.
Consider the following example:

select
generate_series(1,2),
generate_series(1,2)
;

And its output:

generate_series | generate_series
-----------------+-----------------
1 | 1
2 | 2

And then this example:

select
generate_series(1,2),
generate_series(1,3)
;

generate_series | generate_series
-----------------+-----------------
1 | 1
2 | 2
1 | 3
2 | 1
1 | 2
2 | 3

My question is "why?" I actually expected the second behavior in both
cases. Also, I'm not sure where this difference in behavior is
documented. I looked at:
http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET
but it doesn't seem to be explicitly mentioned there.

And yes, I understand doing this is deprecated and my results would
probably be better achieved with LATERAL when 9.3 comes out.

-Ryan Kelly

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2012-11-16 15:28:32 Re: High SYS CPU - need advise
Previous Message David Johnston 2012-11-16 13:26:04 Re: Aggeregate funtion calculating the average value of each same index of an array column in a table