Skip site navigation (1) Skip section navigation (2)

Re: [SQL] sql date functions

From: Aleksey Dashevsky <postgres(at)luckynet(dot)co(dot)il>
To: BD Postgres <postgres(at)master(dot)abrente(dot)es>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] sql date functions
Date: 1998-07-06 11:26:22
Message-ID: Pine.LNX.3.96.SK.980706141824.9426A-100000@kesha.luckynet.co.il (view raw or flat)
Thread:
Lists: 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 );



In response to

Responses

pgsql-sql by date

Next:From: BarracudaDate: 1998-07-06 12:09:46
Subject: Thanks
Previous:From: BD PostgresDate: 1998-07-06 11:09:22
Subject: Re: [SQL] sql date functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group