pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Faulks <faulksp@iinet.net.au>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: date arithmetic with columns
Date: Thu, 01 Mar 2012 10:21:41 +1100
Message-ID: <4F4EB305.7010409@iinet.net.au> (raw)
In-Reply-To: <4F4E818F.9030402@iinet.net.au>
References: <4F4E818F.9030402@iinet.net.au>

Bit more googling and I came up with:

r.utc + CAST( tz.diffmins || ' ' || 'minutes' AS interval)

It works, but is it the best way?

On 1/03/2012 6:50 AM, Peter Faulks wrote:
> 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?
>




view thread (5+ messages)  latest in thread

Message-ID: <4F4EB305.7010409@iinet.net.au>
Permalink:  ../4F4EB305.7010409@iinet.net.au/
Also on:    postgresql.org/message-id/4F4EB305.7010409@iinet.net.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: faulksp@iinet.net.au
  Subject: Re: date arithmetic with columns
  In-Reply-To: <4F4EB305.7010409@iinet.net.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox