Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B38AB632A0A for ; Wed, 8 Sep 2010 12:24:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 79293-10 for ; Wed, 8 Sep 2010 15:24:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id C07C0632957 for ; Wed, 8 Sep 2010 12:24:38 -0300 (ADT) Received: by bwz11 with SMTP id 11so192695bwz.19 for ; Wed, 08 Sep 2010 08:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:message-id:from:to :subject:in-reply-to:references:user-agent:organization:mime-version :content-type; bh=e0e7GvsAB8oa4SIvy5k+5R2LqUPJrOZSOh4Umz8rFek=; b=PLvq+DboMavGk9ev9GUwkk/blLklFdVrtCMbFRk3M6YvqqAjhGGCUuLbKiD5ZT8ShB V8KDFOn7p9XjrGxhDSaGG9PLVnvyqPdE/Znyl7jO0UKzbP+RYms/2WeV9g7tm7hP6Xv4 tbn4mDUlAjFvFKbtE12py/tozlPnanz6jyBuY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:message-id:from:to:subject:in-reply-to:references:user-agent :organization:mime-version:content-type; b=ZyJivNllcirG5MiibOeNSgzLar80+HxTiup33UsKh7uYp/l+jXvnjqzOEc/iG0JSLH PH0Hmrrx4iMr6/nKpPTI6HN0yfNDxAq1qni+lflkNwQSHA/uw7QVZcFlFCrFa0I7tO7Z G2SanwqPcd1v5L49PVPi8jhVFi194PR8Z4CYI= Received: by 10.204.85.90 with SMTP id n26mr632742bkl.109.1283959476849; Wed, 08 Sep 2010 08:24:36 -0700 (PDT) Received: from kaos.gmail.com (f053197202.adsl.alicedsl.de [78.53.197.202]) by mx.google.com with ESMTPS id s34sm127016bkk.1.2010.09.08.08.24.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 08 Sep 2010 08:24:35 -0700 (PDT) Date: Wed, 08 Sep 2010 17:24:39 +0200 Message-ID: <8739tkdzrc.wl%tim@we-are-teh-b.org> From: Tim Schumacher To: pgsql-sql@postgresql.org Subject: Re: Generating Rows from a date and a duration In-Reply-To: References: <4C80C282.700@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) EMIKO/1.14.1 (Choanoflagellata) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 EasyPG/1.0.0 Emacs/23.1.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: Secret Conspiracy MIME-Version: 1.0 (generated by EMIKO 1.14.1 - "Choanoflagellata") Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.89 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_FRT_BELOW2=0.01 X-Spam-Level: X-Archive-Number: 201009/18 X-Sequence-Number: 34549 Hi Brian, Hi List, At Sat, 4 Sep 2010 09:20:53 -0400, Brian Sherwood wrote: > On Fri, Sep 3, 2010 at 5:40 AM, Tim Schumacher < > tim.daniel.schumacher@gmail.com> wrote: > > > I'm kinda stuck situation, I have a timestamp which resambles a > > startdate and a duration in days and I want to bloat this, so I have a > > row for every day beginning from the startdate. I have created an > > example bellow, maybe I'm doing it on the wrong angle and you can come > > up with some better ideas: > > > > BEGIN TRANSACTION; > > > > CREATE TABLE example > > ( > > id serial NOT NULL, > > startdate timestamp without time zone, > > duration int_unsigned NOT NULL, > > CONSTRAINT pq_example_id PRIMARY KEY (id) > > ) WITH (OIDS=FALSE) > > ; > > > > insert into example(id,startdate,duration) values (1,'2010-09-03',4); > > insert into example(id,startdate,duration) values (2,'2010-09-03',6); > > > > CREATE OR REPLACE FUNCTION bloat_duration(IN id integer, > > IN startdate timestamp > > without time zone, > > IN duration integer, > > OUT id integer, > > OUT duration_date date) > > RETURNS SETOF RECORD AS > > $$ > > BEGIN > > RETURN QUERY SELECT > > id,to_date(to_char(startdate,'YYYY-MM-DD'),'YYYY-MM-DD')+s.a AS > > stockdate FROM generate_series(0,duration-1) AS s(a); > > END; > > $$ > > LANGUAGE 'plpgsql'; > > > > -- This works, but not what I want > > SELECT * FROM bloat_duration(1,'2010-09-03',4); > > > > -- This does not work > > > > SELECT * FROM example AS ex > > INNER JOIN bloat_duration(ex.id,ex.startdate,ex.duration) AS bd ON bd.id > > = ex.id > > > > ROLLBACK TRANSACTION; > Take a look at the generate_series function in the "set returning functions" > section of the manual. > http://www.postgresql.org/docs/8.4/interactive/functions-srf.html As you can see in my example, I'm already using it and this is my dilemma. Since I can not bring the values of the FROM-Table to the parameters of my function. Greetings Tim -- Compassion -- that's the one things no machine ever had. Maybe it's the one thing that keeps men ahead of them. -- McCoy, "The Ultimate Computer", stardate 4731.3