Re: abnormal behaviour of a CHECK CONSTRAINT with a regular - Mailing list pgsql-bugs

From Daniel Struck
Subject Re: abnormal behaviour of a CHECK CONSTRAINT with a regular
Date
Msg-id 20040210170858.4cf42b6d.struck.d@retrovirology.lu
Whole thread Raw
In response to Re: abnormal behaviour of a CHECK CONSTRAINT with a regular expression when a trigger is added  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
> I don't see any bug here; it's just that CHECK constraints are applied
> after any BEFORE triggers are run.  Since the triggers could change the
> data to be inserted, the reverse order would be insecure.


Ups, it did make some false assumptions.

Thank you for the clarification.


If I understood now correctly, first the type, then the trigger and last th=
e check constraint is checked.

This makes it also impossible to change the type of a value by a trigger?

Say I would want to change the input of a user to a date, this wouldn't be =
possible, because in first instance the type is not a date.

Here is an example I tried out:

CREATE TABLE test(datum DATE);

CREATE OR REPLACE FUNCTION function_test()
RETURNS trigger
AS 'BEGIN

new.datum :=3D (''15.06.'' || new.datum)::date;

RETURN new;
END;'
LANGUAGE plpgsql;

CREATE TRIGGER trigger_test
                          BEFORE INSERT OR UPDATE
                          ON test FOR EACH ROW
                          EXECUTE PROCEDURE function_test();

INSERT INTO test VALUES('2003');


Best regards,
Daniel

--=20
Retrovirology Laboratory Luxembourg
Centre Hospitalier de Luxembourg
4, rue E. Barbl=E9
L-1210 Luxembourg

phone: +352-44116105
fax:   +352-44116113
web: http://www.retrovirology.lu
e-mail: struck.d@retrovirology.lu

pgsql-bugs by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: abnormal behaviour of a CHECK CONSTRAINT with a regular
Next
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1077: install-strip does not work for MacOS X 10.2.8