pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Tille <tillea@rki.de>
Cc: PostgreSQL SQL <pgsql-sql@hub.org>
Subject: Re: Date of creation and of change
Date: Fri, 25 Aug 2000 13:06:07 +0200 (CEST)
Message-ID: <Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de> (raw)
In-Reply-To: <39A3E145.55A6F495@lexbase.net>

On Wed, 23 Aug 2000, hlefebvre wrote:

> Yes. The keywords NEW / OLD are available only in triggers
> see
> http://www.postgresql.org/users-lounge/docs/7.0/user/c40874113.htm#AEN4286
Well, I believe that, but


CREATE FUNCTION changed_at_timestamp() RETURNS OPAQUE AS '
    BEGIN
        ChangedAt := timestamp(''now'');
        RETURN NEW;
    END;
' LANGUAGE 'plpgsql';

CREATE TABLE WebSeite (
	IdWebSeite int4 DEFAULT nextval('seqwebseite'::text) NOT NULL,
	CreatedAt timestamp DEFAULT now(),
	changedat timestamp DEFAULT now(),
        ...
);

CREATE TABLE Menu (
	IdMenu int4 DEFAULT nextval('seqmenu'::text) NOT NULL,
	CreatedAt timestamp DEFAULT now(),
	ChangedAt timestamp DEFAULT now(),
        ...
);

CREATE TABLE MenuItem (
	IdMenu int4 DEFAULT nextval('seqmenu'::text) NOT NULL,
	CreatedAt timestamp DEFAULT now(),
	ChangedAt timestamp DEFAULT now(),
        ...
);

CREATE TRIGGER webseite_changed_at_timestamp BEFORE INSERT OR UPDATE ON WebSeite
    FOR EACH ROW EXECUTE PROCEDURE changed_at_timestamp();
CREATE TRIGGER menu_changed_at_timestamp BEFORE INSERT OR UPDATE ON Menu
    FOR EACH ROW EXECUTE PROCEDURE changed_at_timestamp();
CREATE TRIGGER menuitem_changed_at_timestamp BEFORE INSERT OR UPDATE ON MenuItem
    FOR EACH ROW EXECUTE PROCEDURE changed_at_timestamp();



web=# insert into menu (IdMenu, ...) values (3, ... );
ERROR:  parser: parse error at or near "changedat"


What's the problem here.  Is there a conflict between the definition with
DEFAULT now() and the TRIGGER BEFORE INSERT OR UPDATE.  Should perhaps
be the DEFAULT in the definition be removed or just the INSERT in
the TRIGGER?  Or is there a completely different problem?

Kind regards

         Andreas.




view thread (15+ messages)  latest in thread

Message-ID: <Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de>
Permalink:  ../Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de/
Also on:    postgresql.org/message-id/Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de

 · 

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: tillea@rki.de, pgsql-sql@hub.org
  Subject: Re: Date of creation and of change
  In-Reply-To: <Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de>
  References: <39A3E145.55A6F495@lexbase.net> <Pine.LNX.4.21.0008251303310.4746-100000@wr-linux02.rki.de>

* 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