Re: What is the syntax for setting a default date in PostgreSQL

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: What is the syntax for setting a default date in PostgreSQL
Date: 2006-02-20 16:59:12
Message-ID: 20060220165912.GB6402@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

lists(at)adontendev(dot)net <lists(at)adontendev(dot)net> schrieb:

>
>
> This issue always stumps me. I need to set the default date for a column in
> postgres. A value for today, today + x days, now (timestamp), now + x amount of
> days.

test=# select current_date;
date
------------
2006-02-20
(1 row)

test=# select current_date + '5 days'::interval;
?column?
---------------------
2006-02-25 00:00:00
(1 row)

test=# select now();
now
-------------------------------
2006-02-20 17:56:24.136771+01
(1 row)

test=# select now() + '5 days'::interval;
?column?
-------------------------------
2006-02-25 17:56:29.780316+01
(1 row)

test=# create table foo (id int, datum date default current_date + '5 days'::interval);
CREATE TABLE
test=# insert into foo (id) values (1);
INSERT 0 1
test=# select * from foo;
id | datum
----+------------
1 | 2006-02-25

HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2006-02-20 17:39:55 How to determine number of established connections
Previous Message Tony Caduto 2006-02-20 16:47:41 Postgresql win32 vs MySql win32