pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: Herouth Maoz <herouth@oumail.openu.ac.il>
To: pere@td.org.uit.no
To: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] Problems with default date 'now'
Date: Wed, 10 Jun 1998 10:14:44 -0500
Message-ID: <F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail> (raw)

> > 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



view thread (7+ messages)  latest in thread

Message-ID: <F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail>
Permalink:  ../F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail/
Also on:    postgresql.org/message-id/F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: djackson@cpsgroup.com, herouth@oumail.openu.ac.il, pere@td.org.uit.no
  Subject: Re: [SQL] Problems with default date 'now'
  In-Reply-To: <F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail>
  References: <F10BB1FAF801D111829B0060971D839F2CDDC3@cpsmail>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox