rewriting values with before trigger - Mailing list pgsql-general

From Robert Treat
Subject rewriting values with before trigger
Date
Msg-id 1051201544.4753.522.camel@camel
Whole thread Raw
Responses Re: [SQL] rewriting values with before trigger
Re: rewriting values with before trigger
List pgsql-general
Is there a way to use triggers to rewrite data before determining if the
data for that field is valid?

postgres=# create table foo (
postgres(# bar timestamptz
postgres(# );
CREATE
postgres=# create or replace function test() returns opaque as '
postgres'# begin
postgres'# NEW.bar := NULL;
postgres'# return NEW;
postgres'# end;
postgres'# ' language 'plpgsql';
CREATE
postgres=# create trigger baz before insert on foo for each row execute
procedure test();
CREATE
postgres=# insert into foo values (now());
INSERT 411474706 1
postgres=# select * from foo;
 bar
-----

(1 row)

postgres=# insert into foo values ('');
ERROR:  Bad timestamp external representation ''

Is there anyway to do be able to change the '' into NULL before data
validity is checked with a trigger?

(FWIW this is 7.2, if this would actually work in 7.3 please lmk)


TIA,
Robert Treat


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [NOVICE] Postgres Remote Syslog
Next
From: Peter Eisentraut
Date:
Subject: Re: default locale considered harmful? (was Re: Using