Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 85CCDAD3D76 for ; Wed, 29 Feb 2012 15:51:00 -0400 (AST) Received: from outbound.icp-qv1-irony-out1.iinet.net.au ([203.59.1.106]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2pY8-0007K1-Kp for pgsql-sql@postgresql.org; Wed, 29 Feb 2012 19:50:59 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApIBAGKdSE98lStA/2dsb2JhbAAMNrZIQCkUFhgDAgECAT8MDQgBAb8sjUICAgcGBAMEAwgECiEDAwECAoULhB0ElTyFf40D X-IronPort-AV: E=Sophos;i="4.73,504,1325433600"; d="scan'208";a="838974434" Received: from unknown (HELO [192.168.0.2]) ([124.149.43.64]) by outbound.icp-qv1-irony-out1.iinet.net.au with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 01 Mar 2012 03:50:38 +0800 Message-ID: <4F4E818F.9030402@iinet.net.au> Date: Thu, 01 Mar 2012 06:50:39 +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: date arithmetic with columns Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/21 X-Sequence-Number: 36416 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?