Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBwk7-0006Ct-DE for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 23:53:15 +0000 Received: from new2-smtp.messagingengine.com ([66.111.4.224]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBwk4-0005M0-Pr for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 23:53:15 +0000 Received: from compute6.internal (compute6.nyi.mail.srv.osa [10.202.2.46]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id B516A90 for ; Wed, 12 Sep 2012 19:53:10 -0400 (EDT) Received: from web1.nyi.mail.srv.osa ([10.202.2.211]) by compute6.internal (MEProxy); Wed, 12 Sep 2012 19:53:10 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.fm; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:subject:date; s=mesmtp; bh=PNGYlcsv1Q+KcYqYck9j2Ly GLP4=; b=MTNQvNrD4JABhxUogu/9AkadtnpD6G6YNxZCzC4v4msQv8YJlmWvvbG fkOoCL6P1VES5zcJwnxako8LuulRxkC+9938Pp79EKGgkwPi9H+L+el4VdJZk023 dF1YytvWLd57EsHxo4wmody+GAMOtUrlUyIb+Q/gSS6SNIzF9C+k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:subject:date; s=smtpout; bh=PNGYlcsv1Q+KcYqYck9j2LyGLP4=; b=McLwdJ9VPiPaS9yzZ3QPv+fwIavK EO9WvzfyAWMWMzjuAMvEQAZFr487s2IQQehNbyjDrCV5ax1iG9x+CZdJEflANvuW ++GxmjQJy94gQCVdFrFZE5yl4T0WN8la5eWuipy7WnNsnBunVfCirWv/2DfI6TA5 5xjdEkgWIqrUcu0= Received: by web1.nyi.mail.srv.osa (Postfix, from userid 99) id 62B66A0016C; Wed, 12 Sep 2012 19:53:10 -0400 (EDT) Message-Id: <1347493990.25573.140661127188777.1658803C@webmail.messagingengine.com> X-Sasl-Enc: rYSKbu/p669O/zqEeD8eeIbSB7Cd+dt+SJ+9Q4USFXfs 1347493990 From: Wolfe Whalen To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface Subject: generate_series() with TSTZRANGE Date: Wed, 12 Sep 2012 16:53:10 -0700 X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201209/30 X-Sequence-Number: 36832 Hi everyone! I'm new around here, so please forgive me if this is a bit trivial. It seems that generate_series() won't generate time stamp ranges. I googled around and didn't see anything handy, so I wrote this out and thought I'd share and see if perhaps there was a better way to do it: 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; 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