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

What is the syntax for setting a default date in PostgreSQL

From
lists@adontendev.net
Date:

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.

I never seem to be able to locate it in the documentation or online. Can anyone
post it here once and for all for posterity?

I will be much obliged :)

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

From
Andreas Kretschmer
Date:
lists@adontendev.net <lists@adontendev.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°