pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Treat <xzilla@users.sourceforge.net>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
To: pgsql-sql@postgresql.org
Subject: rewriting values with before trigger
Date: 24 Apr 2003 12:25:44 -0400
Message-ID: <1051201544.4753.522.camel@camel> (raw)

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




view thread (18+ messages)  latest in thread

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

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: xzilla@users.sourceforge.net, pgsql-general@postgresql.org
  Subject: Re: rewriting values with before trigger
  In-Reply-To: <1051201544.4753.522.camel@camel>

* 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