2

Currently my query is like:

select *
from crosstab(
     $$ select name,id,date,flag from x $$,
     select i::date from generate_series('2017-03-28','2017-03-29','1 day'::interval) i $$)
     as final_result(name text, id numeric, "2017-03-28" numeric,"2017-03-29" numeric);

i was thinking if it is possible to give date column name dynamically as i have to do this for lots of dates

table x
name    id     date        flag
x       1      2017-01-02    1
y       2      2017-01-02    2
z       3      2017-01-02    1
x       1      2017-01-03    1
y       2      2017-01-03    2
z       3      2017-01-03    1
x       1      2017-01-04    1
y       2      2017-01-04    2
z       3      2017-01-04    1

output:
name     id     2017-01-02    2017-01-03       2017-01-04   .....more dates
x        1        1             1                1
y        2        2             2                2
z        3        1             1                1
...more rows

and i want the dates to be dynamically called between two specified dates and have the respective date as column name.

Bhawesh Chandola
  • 511
  • 5
  • 19

0 Answers0