pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedJoe Celko's method to "generate_series" not working?
2+ messages / 1 participants
[nested] [flat]
* Joe Celko's method to "generate_series" not working?
@ 2007-05-03 00:17 Richard Broersma Jr <rabroersma@yahoo.com>
2007-05-03 00:35 ` Re: Joe Celko's method to "generate_series" not working? Richard Broersma Jr <rabroersma@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: Richard Broersma Jr @ 2007-05-03 00:17 UTC (permalink / raw)
To: pgsql-sql
Well, I am about a book and a-half away from reading all of the Joe Celko's books that I know of.
I just came across an nice looking way to generate a series using a set oriented construct.
However, I am not able to get it to work in PostgreSQL.
The method follows from the SQL Programming Style p.164:
SELECT hundred * 100 + ten * 10 + unit + 1
FROM ( VALUES( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) AS Units( unit )
CROSS JOIN
( VALUES( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) AS Tens( ten )
CROSS JOIN
( VALUES( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) AS Hundreds( hundred );
but I am getting:
?column?
----------
1
(1 row)
which isn't close to the 1000 rows that I am expecting.
Is Mr. Celko mistaken? Does anyone know if PostgreSQL has any functions that I can turn these
VALUES rows into columns so that the CROSS JOINS will work?
Regards,
Richard Broersma Jr.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Joe Celko's method to "generate_series" not working?
2007-05-03 00:17 Joe Celko's method to "generate_series" not working? Richard Broersma Jr <rabroersma@yahoo.com>
@ 2007-05-03 00:35 ` Richard Broersma Jr <rabroersma@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: Richard Broersma Jr @ 2007-05-03 00:35 UTC (permalink / raw)
To: Richard Broersma Jr <rabroersma@yahoo.com>; pgsql-sql
--- Richard Broersma Jr <rabroersma@yahoo.com> wrote:
> Is Mr. Celko mistaken? Does anyone know if PostgreSQL has any functions that I can turn these
> VALUES rows into columns so that the CROSS JOINS will work?
Having posted, I just realized what the correct syntax is:
SELECT hundred * 100 + ten * 10 + unit + 1
FROM ( VALUES( 0 ), ( 1 ), ( 2 ), ( 3 ),
( 4 ), ( 5 ), ( 6 ), ( 7 ),
( 8 ), ( 9 )
) AS Units( unit )
CROSS JOIN
( VALUES( 0 ), ( 1 ), ( 2 ), ( 3 ),
( 4 ), ( 5 ), ( 6 ), ( 7 ),
( 8 ), ( 9 )
) AS Tens( ten )
CROSS JOIN
( VALUES( 0 ), ( 1 ), ( 2 ), ( 3 ),
( 4 ), ( 5 ), ( 6 ), ( 7 ),
( 8 ), ( 9 )
) AS Hundreds( hundred )
ORDER BY hundred * 100 + ten * 10 + unit + 1 ;
Sorry for the noise. :o(
Regards,
Richard Broersma Jr.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-05-03 00:35 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-05-03 00:17 Joe Celko's method to "generate_series" not working? Richard Broersma Jr <rabroersma@yahoo.com>
2007-05-03 00:35 ` Richard Broersma Jr <rabroersma@yahoo.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox