Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EE9BA2E0079 for ; Thu, 20 Mar 2008 00:04:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 08047-05 for ; Thu, 20 Mar 2008 00:04:01 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id 0F9252E0045 for ; Thu, 20 Mar 2008 00:03:59 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so178086ana.33 for ; Wed, 19 Mar 2008 20:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=O6oM2Qf9L+cXVqwbyUj39Ngi8XvTLR0//4n41WezqKo=; b=N1U5/u8krO3yCxmGUMBdlPpnx465PRCuxUt/EuX+Gm9mMyn19kDoKub8QCp0vMmLhu0zqdHqbVSuXPORYpNR0kEYSOc7P4SR6R8FIclo4m/kzP/HJqpm3P6Rs+2KInl4VL1CXDlBHnb9NJZDS51WOLGSR4z8bRib+9451e5roLY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=KK9PJSYRwMuQ1MFYoWf+wrpWiW0KUs+CP672+4CqjhiBt9w265oPRjQTac+wL1CV/gyAvpAZt2/wv4NN/x+adcqiHn+D7qmrxuAyqUnBAgu//dmUukcjH9eWaK6vWDU/nNUSHzPOCaFUTkwAodil/8VKT4O6TiTRuA2Pk14v72s= Received: by 10.100.249.9 with SMTP id w9mr4177657anh.63.1205982238529; Wed, 19 Mar 2008 20:03:58 -0700 (PDT) Received: by 10.100.122.9 with HTTP; Wed, 19 Mar 2008 20:03:58 -0700 (PDT) Message-ID: Date: Wed, 19 Mar 2008 22:03:58 -0500 From: "=?UTF-8?Q?Rodrigo_E._De_Le=C3=B3n_Plicet?=" To: "Christopher Crews" Subject: Re: Date and filling issues Cc: pgsql-sql@postgresql.org In-Reply-To: <687096.56737.qm@web52202.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <687096.56737.qm@web52202.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/130 X-Sequence-Number: 30458 On 3/19/08, Christopher Crews wrote: > and what I'm trying to do is fill in the missing dates with sales values of 0. create or replace function gen_dates(sd date, ed date) returns setof date as $$ select $1 + i from generate_series(0, $2 - $1) i; $$ language sql immutable; select d.date, sum(coalesce(sale_amount,0)) as sales from gen_dates((current_date - interval '1 month')::date, current_date) d(date) left join ej_transaction on transaction_date=d.date group by d.date order by d.date asc;