Re: generate_series to return row that doesn't exist in

From: MaXX <bs139412(at)skynet(dot)be>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: generate_series to return row that doesn't exist in
Date: 2006-03-24 20:54:28
Message-ID: 200603242154.29175.bs139412@skynet.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Friday 24 March 2006 21:42, Scott Marlowe wrote:
> More than likely you need a left join and a case statement.
>
> select <selectlist>, case when a.date is null then 0 else a.date end
> from (select * from generate_series() -- magic to get dates goes here)
> as p left join maintable as a on (p.date=a.date);
>
> There may be some small syntax error in there, as I've not tested it.
> The relavent pages are:
>
> case:
> http://www.postgresql.org/docs/8.1/static/functions-conditional.html
>
> joins:
> http://www.postgresql.org/docs/8.1/static/queries-table-expressions.html
Perfect!!
Time to RTFM again...

Thanks,
--
MaXX

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-03-24 20:58:10 Re: Custom type
Previous Message Rod Taylor 2006-03-24 20:46:55 Re: Find min and max values across two columns?