pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Eagna <eagna@protonmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to add a variable to a timestamp.
Date: Sat, 29 Oct 2022 18:13:54 -0400
Message-ID: <85459.1667081634@sss.pgh.pa.us> (raw)
In-Reply-To: <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com>
References: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com>
	<3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com>

Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 10/29/22 10:35, Eagna wrote:
>> I'm trying to do something like this.
>>   '2022-10-31 00:00:00'::TIMESTAMP + INTERVAL 'd.i DAY'

That will not work.  A literal is a literal, you can't expect that
the system will interpret parts of it as variable references.

>   '2022-10-31 00:00:00'::TIMESTAMP  + (d.i::text || ' DAY ' || h.i::text 
> || ' HOUR')::interval

That'll work, but my what a kluge.  More recommendable is

'2022-10-31 00:00:00'::TIMESTAMP + d.i * '1 day'::interval
+ h.i * '1 hour'::interval

(Or you can spell the constants like INTERVAL '1 day',
if you prefer.)

			regards, tom lane





view thread (4+ messages)

Message-ID: <85459.1667081634@sss.pgh.pa.us>
Permalink:  ../85459.1667081634@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/85459.1667081634@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, eagna@protonmail.com
  Subject: Re: How to add a variable to a timestamp.
  In-Reply-To: <85459.1667081634@sss.pgh.pa.us>
  References: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com> <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com> <85459.1667081634@sss.pgh.pa.us>

* 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