Re: type casting a subselect as an interval

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: type casting a subselect as an interval
Дата
Msg-id 14940.1045841644@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: type casting a subselect as an interval  (Karel Zak <zakkr@zf.jcu.cz>)
Ответы Re: type casting a subselect as an interval
Список pgsql-general
Karel Zak <zakkr@zf.jcu.cz> writes:
> On Fri, Feb 21, 2003 at 07:59:19PM +0900, Jean-Christian Imbeault wrote:
>> How can I cast the return value of a sub-select as an interval?
>> select current_timestamp - interval '(select days from T) days'

>  You can cast it in the subselect:

>  select current_timestamp - (select (days::text || 'd')::interval from T);

A better way of converting numeric values to intervals is to rely on the
interval-times-float8 operator:

  select current_timestamp - (select days from T) * interval '1 day';

This is readable, efficient, and easily adapted to other units (second,
month, etc).

            regards, tom lane

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

Предыдущее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: Problem with aliasing
Следующее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: Problem with aliasing