Re: [SQL] sql date functions

Поиск
Список
Период
Сортировка
От Aleksey Dashevsky
Тема Re: [SQL] sql date functions
Дата
Msg-id Pine.LNX.3.96.SK.980706141824.9426A-100000@kesha.luckynet.co.il
обсуждение исходный текст
Ответ на Re: [SQL] sql date functions  (BD Postgres <postgres@master.abrente.es>)
Список pgsql-sql

On Mon, 6 Jul 1998, BD Postgres wrote:

> Aleksey Dashevsky wrote:
>
> > I think you need to rewrite this query with something like:
> >
> > insert into table1 (date1,date2) values('1997-2-3'::date,'1997-2-3'::date
> >  + '1 week'::timespan);
> >
> > You can also use standard SQL-92 syntax for type casting, e.x.:
> > cast ('1 week' as timespan )
> >  etc.
>
>
> You are right, but now postgres is reporting me that there is no '+' operator
> defined for time and timespan, but I have found that I can add integers to
> dates and they are threaded as days so I can solve my problem easily.
>

Sorry, I really forgot: if you want to use date interval you need datetime
type instead of date. Unforunately, postgres can only add timespan to
datetime, but not to date, and  also it doesn't have autoconversion from
date to datetime:-(

So, you eihter need to change all mentions of date type with datetime
(don't forget to change it also in "create table"), or you need to cast
back datetime to date:

insert into table1 (date1,date2) values('1997-2-3'::date,('1997-2-3'::datetime
  + '1 week'::timespan)::date );



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

Предыдущее
От: BD Postgres
Дата:
Сообщение: Re: [SQL] sql date functions
Следующее
От: Barracuda
Дата:
Сообщение: Thanks