Search Postgresql Archives

Q: using generate_series to fill in the blanks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've got a desired output which looks something like this..

 vdt        | count
------------+-------
          1 |   514
          2 |    27
          3 |    15
	  4 |  <NULL>
          5 |    12
          6 |    15


the query in psql is something like this..

select vdt, count(*) from footable where c_id = '71' group by vdt order
by vdt

problem is.. since there's not data whatsoever on vdt=4 I get this..

 vdt        | count
------------+-------
          1 |   514
          2 |    27
          3 |    15
          5 |    12
          6 |    15

I tried to use generate_series


select generate_series(1,7,1), count(*) from footable where c_id = '71'
group by generate_series(1,7,1),vdt order by generate_series(1,7,1);

(note : the vdt are numbered from 1 to 7 sequence)

 generate_series | count
-----------------+-------
               1 |   514
               1 |    27
               1 |    15
               1 |    12
               1 |    15
               2 |   514
               2 |    27
               2 |    15
               2 |    12
               2 |    15
               3 |   514
               3 |    27
               3 |    15
               3 |    12
               3 |    15
               4 |   514
               4 |    27
               4 |    15
               4 |    12
               4 |    15
.....
[snip]
.....

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux