Received: from bjke.com (firewall-user@[144.210.8.38]) by hub.org (8.8.8/8.7.5) with ESMTP id LAA05684 for ; Wed, 10 Jun 1998 11:14:33 -0400 (EDT) Received: by bjke.com; id LAA19097; Wed, 10 Jun 1998 11:12:06 -0400 (EDT) Received: from cpsmail.cpsgroup.com(144.210.12.11) by gauntlet.bjke.com via smap (3.2) id xmab18666; Wed, 10 Jun 98 11:11:32 -0400 Received: by cpsmail with Internet Mail Service (5.0.1458.49) id ; Wed, 10 Jun 1998 10:14:44 -0500 Message-ID: From: "Jackson, DeJuan" To: Herouth Maoz , pere@td.org.uit.no, pgsql-sql@postgreSQL.org Subject: RE: [SQL] Problems with default date 'now' Date: Wed, 10 Jun 1998 10:14:44 -0500 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1458.49) Content-Type: text/plain > > Nope, that did not work. > > > > I get this reply from psql: > > > > WARN:parser: parse error at or near "current_date" > > > > What is wrong. Is this something new in PostgreSQL after v6.2.1? > > Yes, it's something new. I still work with 6.2.1, so here's the deal: > > Using a constant default value for a column causes the constant to be > evaluated once, at the creation of the table. That value is then kept > with > the table schema, which means each row will be stamped with the same > date. > > In order to avoid that, you have to use a function as a default value. > Functions are evaluated each time a column is created. For this > purpose, I > created an SQL function like this: > > CREATE FUNCTION current_datetime() RETURNS datetime > AS 'SELECT ''now''::datetime' > LANGUAGE 'sql'; > > And I define the table as (in my case): > > CREATE TABLE session > ( > session int4 > DEFAULT nextval( 'sess_no' ) > NOT NULL, > created datetime > DEFAULT current_datetime() -- See here > NOT NULL, > webuser char(30) > ); > > You can define the function once, and use it for all the applications > using > the same database. > > Herouth > Why don't you just use the function version of now (I'm not familiar with 6.2.1 so it could be that it doesn't exist). received_date DATE DEFAULT NOW() just a thought, -DEJ