X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7D10C9DCAA3 for ; Fri, 24 Mar 2006 16:55:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47460-05 for ; Fri, 24 Mar 2006 16:55:10 -0400 (AST) X-Greylist: delayed 00:23:18.57531 by SQLgrey- Received: from outmx011.isp.belgacom.be (outmx011.isp.belgacom.be [195.238.5.3]) by postgresql.org (Postfix) with ESMTP id 2C0679DCDD2 for ; Fri, 24 Mar 2006 16:55:06 -0400 (AST) Received: from outmx011.isp.belgacom.be (localhost [127.0.0.1]) by outmx011.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with ESMTP id k2OKt7bC019580 for ; Fri, 24 Mar 2006 21:55:07 +0100 (envelope-from ) Received: from [10.8.0.2] (62-162.244.81.adsl.skynet.be [81.244.162.62]) by outmx011.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with ESMTP id k2OKt2iD019528 for ; Fri, 24 Mar 2006 21:55:02 +0100 (envelope-from ) From: MaXX To: pgsql-sql@postgresql.org Subject: Re: generate_series to return row that doesn't exist in Date: Fri, 24 Mar 2006 21:54:28 +0100 User-Agent: KMail/1.9.1 References: <200603242130.57851.bs139412@skynet.be> <1143232952.3625.6.camel@state.g2switchworks.com> In-Reply-To: <1143232952.3625.6.camel@state.g2switchworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200603242154.29175.bs139412@skynet.be> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200603/392 X-Sequence-Number: 24738 On Friday 24 March 2006 21:42, Scott Marlowe wrote: > More than likely you need a left join and a case statement. > > select , 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