dbTalk Databases Forums  

[BUGS] multiple SRFs in SELECT clause.

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] multiple SRFs in SELECT clause. in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kris Jurka
 
Posts: n/a

Default [BUGS] multiple SRFs in SELECT clause. - 11-27-2006 , 05:28 AM







I'm getting some odd results when running two generate_series calls in a
SELECT. When the two calls return the same number of rows you get that
many rows out:

# SELECT generate_series(1,3), generate_series(1,3);
generate_series | generate_series
-----------------+-----------------
1 | 1
2 | 2
3 | 3
(3 rows)

When the row counts differ you get the least common multiple number of
rows.

# SELECT generate_series(1,4), generate_series(1,2);
generate_series | generate_series
-----------------+-----------------
1 | 1
2 | 2
3 | 1
4 | 2
(4 rows)

I was personally expecting a cross join between them that would be
equivalent to

# SELECT * FROM generate_series(1,4) a, generate_series(1,2) b;
a | b
---+---
1 | 1
1 | 2
2 | 1
2 | 2
3 | 1
3 | 2
4 | 1
4 | 2
(8 rows)

Tested on 8.1.3 and CVS HEAD.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] multiple SRFs in SELECT clause. - 11-27-2006 , 07:31 PM






Kris Jurka <books (AT) ejurka (DOT) com> writes:
Quote:
I'm getting some odd results when running two generate_series calls in a
SELECT ...
When the row counts differ you get the least common multiple number of
rows.
Yup, this is the expected or at least historical behavior. It's not
entirely clear what you *should* get, which is one reason we ought to
deprecate SRFs in SELECT lists.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.