Re: Datetime operators (was: Re: [SQL] Another Date question) - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: Datetime operators (was: Re: [SQL] Another Date question)
Date
Msg-id 3847E653.AAF97645@alumni.caltech.edu
Whole thread Raw
In response to Datetime operators (was: Re: [SQL] Another Date question)  (Karel Zak - Zakkr <zakkr@zf.jcu.cz>)
Responses Re: Datetime operators (was: Re: [SQL] Another Date question)
Re: Datetime operators (was: Re: [SQL] Another Date question)
List pgsql-hackers
> > I'd like to create a table with a datetime field that defaults to +60
> > days.
> > mydate datetime default 'now() +@60 days',
> > ...
> Where is a problem?

You have enclosed your default values into a large string, rather than
letting them be evaluated as an expression:
 mydate datetime default (now() + '60 days')

where the outer parens are optional.

>      datetime + '10 day' or
>      datetime + '2 year' ..etc.
> But I'm not sure what is better or exists it in other SQL.

afaik this is the simplest and most direct way to do it. Note that you
can include other timespan fields in the constant:
 mydate datetime default (now() + '60 days 10 hours')

HTH
                     - Thomas

-- 
Thomas Lockhart                lockhart@alumni.caltech.edu
South Pasadena, California


pgsql-hackers by date:

Previous
From: "Hiroshi Inoue"
Date:
Subject: RE: [HACKERS] Re: [GENERAL] drop/rename table and transactions
Next
From: Karel Zak - Zakkr
Date:
Subject: Re: Datetime operators (was: Re: [SQL] Another Date question)