Thread: CREATE OR REPLACE FUNCTION now validates it's dependents

CREATE OR REPLACE FUNCTION now validates it's dependents

From
jian he
Date:
hi.

The attached patch allows CREATE OR REPLACE FUNCTION to correctly update domain
constraints when the function they depend on is changed.

so this thread[1] mentioned the problem can be resolved.
for example:

create function sqlcheck(int) returns bool as 'select $1 > 0' language sql;
create domain checkedint as int check(sqlcheck(value));
select 0::checkedint;  -- fail
ERROR:  value for domain checkedint violates check constraint "checkedint_check"
create or replace function sqlcheck(int) returns bool as 'select $1 <=
0' language sql;
select 1::checkedint;  -- fail?

the last query won't fail on the master. with the patch it will fail.

I also make CREATE OR REPLACE FUNCTION validate each domain value when
the domain constraint conditions is associated the function we are
gonname changes
Of course, this will make CREATE OR REPLACE FUNCTION  take way longer time
compared to the current.



Similar to domain constraints, attached patch also apply to table
check constraints too.
Is this what we want to do?

[1]: https://postgr.es/m/12539.1544107316%40sss.pgh.pa.us

Attachment
jian he <jian.universality@gmail.com> writes:
> The attached patch allows CREATE OR REPLACE FUNCTION to correctly update domain
> constraints when the function they depend on is changed.

Why is this a problem that needs solving?

Our fundamental expectation is that domain constraints are immutable
(see the Notes section under CREATE DOMAIN [1]).  If the user changes
a function used in a constraint in a way that changes its behavior,
that's their fault not our problem.  I don't think we should add a
bunch of code (that we have to maintain) and a bunch of overhead for
every CREATE OR REPLACE FUNCTION in order to slap people on the wrist
if they get this wrong.

            regards, tom lane

[1] https://www.postgresql.org/docs/current/sql-createdomain.html