| From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
|---|---|
| To: | Eagna <eagna(at)protonmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: How to add a variable to a timestamp. |
| Date: | 2022-10-29 20:10:24 |
| Message-ID: | 3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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(dot)klaver(at)aklaver(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2022-10-29 22:13:54 | Re: How to add a variable to a timestamp. |
| Previous Message | Erik Wienhold | 2022-10-29 18:35:30 | Re: How to add a variable to a timestamp. |