Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



lists@xxxxxxxxxxxxxx <lists@xxxxxxxxxxxxxx> 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°


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux