pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Wienhold <ewie@ewie.name>
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 20:35:30 +0200 (CEST)
Message-ID: <629544703.694927.1667068530445@office.mailbox.org> (raw)
In-Reply-To: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com>
References: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com>

> On 29/10/2022 19:35 CEST Eagna <eagna@protonmail.com> wrote:
>
> 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.

Create the interval with make_interval(days => d.i, hours => h.i).

https://www.postgresql.org/docs/15/functions-datetime.html#id-1.5.8.15.6.2.2.28.1.1.1

--
Erik





view thread (4+ messages)  latest in thread

Message-ID: <629544703.694927.1667068530445@office.mailbox.org>
Permalink:  ../629544703.694927.1667068530445@office.mailbox.org/
Also on:    postgresql.org/message-id/629544703.694927.1667068530445@office.mailbox.org

 · 

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: ewie@ewie.name, eagna@protonmail.com
  Subject: Re: How to add a variable to a timestamp.
  In-Reply-To: <629544703.694927.1667068530445@office.mailbox.org>
  References: <xXb-4R7uS7KbJF86CCk3x54iPj_ZoDNpAE33QlL7UUD27u0POej_mrycXGj9wYvc_N9XSP5Ed2cw5YF9YLGynDEWAq0aMY_7NkzO4BykQnw=@protonmail.com> <629544703.694927.1667068530445@office.mailbox.org>

* 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