Re: How to add a variable to a timestamp.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to add a variable to a timestamp.
Дата
Msg-id 85459.1667081634@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How to add a variable to a timestamp.  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: How to add a variable to a timestamp.
Следующее
От: Bryn Llewellyn
Дата:
Сообщение: Re: "peer" authentication: cannot make "pg_ident.conf" work as I believe that the doc says that it should