Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCDvR-0002IM-Cj for pgsql-sql@postgresql.org; Thu, 13 Sep 2012 18:14:05 +0000 Received: from new2-smtp.messagingengine.com ([66.111.4.224]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCDvO-0001rq-Or for pgsql-sql@postgresql.org; Thu, 13 Sep 2012 18:14:04 +0000 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 298A6120; Thu, 13 Sep 2012 14:14:00 -0400 (EDT) Received: from web6.nyi.mail.srv.osa ([10.202.2.216]) by compute1.internal (MEProxy); Thu, 13 Sep 2012 14:14:00 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:cc:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=YszHRuihSUUYq1A07woPp03lxyI=; b=Lyt BvtzVY6iGHdnLfh1h0RCIH+V4U1M7z3HCRhxZwFdTMLmQZHKgSSIeoOyXsUMyzid w8qeo3Cl4SCfQH07vTrGnB1Xwqnx3GsjBQnzFQfgDM2T9nWKx+FQnhHPLQKXno0I Ik91sB44149+krFdpifHgR8cL8MMeR0jc+2bd9G4= Received: by web6.nyi.mail.srv.osa (Postfix, from userid 99) id A4C6868362C; Thu, 13 Sep 2012 14:13:59 -0400 (EDT) Message-Id: <1347560039.7008.140661127553573.6B093229@webmail.messagingengine.com> X-Sasl-Enc: hY/wVpr8TNbEck4EqFnHqCQDuEkn6SeDQvcKzQ5Hfwm/ 1347560039 From: Wolfe Whalen To: Sergey Konoplev Cc: Postgres SQL List MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: References: <1347493990.25573.140661127188777.1658803C@webmail.messagingengine.com> Subject: Re: generate_series() with TSTZRANGE Date: Thu, 13 Sep 2012 11:13:59 -0700 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/37 X-Sequence-Number: 36839 That's much better, thank you! -- Wolfe Whalen wolfe@quios.net On Thu, Sep 13, 2012, at 06:52 AM, Sergey Konoplev wrote: > On Thu, Sep 13, 2012 at 3:53 AM, Wolfe Whalen > wrote: > > SELECT tstzrange((lag(a) OVER()), a, '[)') > > FROM generate_series('2012-09-16 12:00:00'::timestamp, '2012-09-17 > > 12:00:00', '1 hour') > > AS a OFFSET 1; > > What about this form? > > select tstzrange(a, a + '1 hour'::interval, '[)') > from generate_series( > '2012-09-16'::timestamp, > '2012-09-16 23:00'::timestamp, > '1 hour'::interval) as a; > > > > > Basically, it's generating a series of time stamps one hour apart, then > > using the previous record and the current record to construct the > > TSTZRANGE value. It's offset 1 to skip the first record, since there is > > no previous record to pair with it. > > > > If you were looking at Josh Berkus' example at > > http://lwn.net/Articles/497069/ you might use it like this to generate > > data for testing and experimentation: > > > > INSERT INTO room_reservations > > SELECT 'F104', 'John', 'Another Talk', > > tstzrange((lag(a) OVER()), a, '[)') > > FROM generate_series('2012-09-16 12:00:00'::timestamp, '2012-09-17 > > 12:00:00', '1 hour') > > AS a OFFSET 1; > > > > Thanks! > > > > -- > > Wolfe Whalen > > wolfe@quios.net > > > > > > -- > > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-sql > > > > -- > Sergey Konoplev > > a database and software architect > http://www.linkedin.com/in/grayhemp > > Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204