Skip site navigation (1) Skip section navigation (2)

date arithmetic with columns

From: Peter Faulks <faulksp(at)iinet(dot)net(dot)au>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: date arithmetic with columns
Date: 2012-02-29 19:50:39
Message-ID: 4F4E818F.9030402@iinet.net.au (view raw or flat)
Thread:
Lists: pgsql-sql
I have two columns in two distinct tables, one is the starting time of 
an event, timestamp without time zone. Data is the utc datetime (for 
sorting across time zones), the other is the number of minutes to add.

I am migrating from Firebird. One of the queries uses the dateadd 
function to build a local starting time thus:

SELECT CAST(DATEADD(tz.diffmins MINUTE TO r.utc) AS TIME) AS ts
FROM races r JOIN tracks t ON t.trk = r.trk
              JOIN timezones tz on tz.state = t.state....

The equivalent postgres would be along the lines of

SELECT r.utc + INTERVAL '480 minutes'

How can I substitute the hard-coded 480 for the tz.diffmins?


Responses

pgsql-sql by date

Next:From: Peter FaulksDate: 2012-02-29 23:21:41
Subject: Re: date arithmetic with columns
Previous:From: Richard KlinglerDate: 2012-02-29 16:14:21
Subject: Re: Natural sort order

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group