Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 81549AD3D77 for ; Wed, 29 Feb 2012 19:21:55 -0400 (AST) Received: from outbound.icp-qv1-irony-out6.iinet.net.au ([203.59.1.109]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2sqI-0006wd-0z for pgsql-sql@postgresql.org; Wed, 29 Feb 2012 23:21:55 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAMOyTk98lStA/2dsb2JhbAAMOLBxhXcBAQEEOEARCw0LCRYPCQMCAQIBRQYNCAEBwXCNLgICBwYEAwQDCAQKIQMDAwKFC4QdBJU/hgGNBA X-IronPort-AV: E=Sophos;i="4.73,506,1325433600"; d="scan'208";a="306588457" Received: from unknown (HELO [192.168.0.2]) ([124.149.43.64]) by outbound.icp-qv1-irony-out6.iinet.net.au with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 01 Mar 2012 07:21:37 +0800 Message-ID: <4F4EB305.7010409@iinet.net.au> Date: Thu, 01 Mar 2012 10:21:41 +1100 From: Peter Faulks User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1 MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: Re: date arithmetic with columns References: <4F4E818F.9030402@iinet.net.au> In-Reply-To: <4F4E818F.9030402@iinet.net.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/22 X-Sequence-Number: 36417 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? >