stored procedure and timestamp - Mailing list pgsql-general

From Soma Interesting
Subject stored procedure and timestamp
Date
Msg-id 5.0.2.1.0.20010328155912.026bfe90@pop.telus.net
Whole thread Raw
Responses Re: stored procedure and timestamp
List pgsql-general
I have the following trigger/stored procedure:

CREATE FUNCTION memb_num () RETURNS opaque AS '
         BEGIN
                 NEW.member_num := date_part(''epoch'', timestamp ''now'');
                 RETURN NEW;
         END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER memb_num_trigger BEFORE INSERT
         ON members FOR EACH ROW
         EXECUTE PROCEDURE memb_num();


I get the following error when I attempt to insert any records beyond the
first:
"Cannot insert a duplicate key into unique index members_member_num_key"

So the function isn't inserting "live" timestamps. I believe this means the
function is not trying to set NEW.member_num to the timestamp of when the
function gets called, which is what I expected. I'm guessing the function
is evaluating the timestamp at the moment of adding the function to the
database - then inserting that stored timestamp repeatedly?


pgsql-general by date:

Previous
From: 100.179370@germanynet.de (Martin Jacobs)
Date:
Subject: Re: String REPLACE function
Next
From: will trillich
Date:
Subject: composite data types