Snippets

Brian Medley Very cool Pg generate_series function

Created by Brian Medley
[bpm@bmedley] c:~>sudo -u postgres /usr/pgsql-9.3/bin/psql test
could not change directory to "/home/bpm": Permission denied
psql (9.3.9)
Type "help" for help.

test=# \d buu
      Table "public.buu"
 Column |  Type   | Modifiers 
--------+---------+-----------
 str    | text    | 
 count  | integer | 

test=# select * from buu;
 str | count 
-----+-------
 foo |     4
(1 row)

test=# with count_stuff as (select * from buu, generate_series(1, buu.count)) select buu.str, generate_series from buu, count_stuff;
 str | generate_series 
-----+-----------------
 foo |               1
 foo |               2
 foo |               3
 foo |               4
(4 rows)

test=# 

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.