Re: Re: Date of creation and of change - Mailing list pgsql-sql

From hlefebvre
Subject Re: Re: Date of creation and of change
Date
Msg-id 39A3E145.55A6F495@lexbase.net
Whole thread Raw
In response to Re: Date of creation and of change  (Andreas Tille <tillea@rki.de>)
Responses Re: Date of creation and of change  (Andreas Tille <tillea@rki.de>)
List pgsql-sql

Andreas Tille wrote:

> I tried:
> 
> web=# CREATE FUNCTION changed_at_timestamp () RETURNS OPAQUE AS '
> web'#     BEGIN
> web'#         ChangeDate := timestamp(''now'');
> web'#         RETURN NEW;
> web'#     END;
> web'# ' LANGUAGE 'plpgsql';
> CREATE
> web=# select changed_at_timestamp () ;
> ERROR:  typeidTypeRelid: Invalid type - oid = 0
> web=#
> 
> Is this just the wrong way to test the function?

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

> As a beginner I try to validate each new step I do and so I wonder
> if I insert the Trigger you mentioned
> 
> > CREATE TRIGGER myt_stamp BEFORE INSERT OR UPDATE ON mytable
> >     FOR EACH ROW EXECUTE PROCEDURE myt_stamp();
> 
> the function could cause errors.
> 
> Sorry, I'm not very familiar with this function stuff :-(.
> 
> Kind regards
> 
>           Andreas.


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Null function parameters
Next
From: Tom Lane
Date:
Subject: Re: Using SETOF in plpgsql function