pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Eagna <eagna@protonmail.com>
To: 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 13:10:24 -0700
Message-ID: <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com> (raw)
In-Reply-To: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com>
References: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com>

On 10/29/22 10:35, Eagna wrote:
> 
> Hi,
> 
> I'm trying to do something like this.
> 
> SELECT
>    d.i,
>    h.i,
> 
>   '2022-10-31 00:00:00'::TIMESTAMP  + INTERVAL 'd.i DAY'
> FROM
>    GENERATE_SERIES(0,  6) AS d(i),
>    GENERATE_SERIES(0, 23) AS h(i);
> 
> where I add d.i days (and also h.i hours) to a timestamp.
> 
> I can't seem to get this to work. Any ideas appreciated.

SELECT
   d.i,
   h.i,
  '2022-10-31 00:00:00'::TIMESTAMP  + (d.i::text || ' DAY ' || h.i::text 
|| ' HOUR')::interval
FROM
   GENERATE_SERIES(0,  6) AS d(i),
   GENERATE_SERIES(0, 23) AS h(i);

> 
> 
> E.
> 
> Sent with Proton Mail <https://proton.me/; secure email.
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (4+ messages)  latest in thread

Message-ID: <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com>
Permalink:  ../3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com/
Also on:    postgresql.org/message-id/3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com

 · 

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: adrian.klaver@aklaver.com, eagna@protonmail.com
  Subject: Re: How to add a variable to a timestamp.
  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>

* 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