check constraint on insert but not delete

Started by Gauthier, Daveover 15 years ago3 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

This is a longshot, but here goes...

Is there a way to require that a check constraint be checked on insert but not update? Worth knowing is that my check constraint runs a PLPgsql proc which returns a yes/no kinf of flag which the constraint proper checks.

Thanks !

#2Vick Khera
vivek@khera.org
In reply to: Gauthier, Dave (#1)
Re: check constraint on insert but not delete

On Thu, Nov 4, 2010 at 11:03 AM, Gauthier, Dave <dave.gauthier@intel.com> wrote:

Is there a way to require that a check constraint be checked on insert but
not update?    Worth knowing is that my check constraint runs a PLPgsql proc
which returns a yes/no kinf of flag which the constraint proper checks.

Use an explicit ON INSERT trigger that calls your procedure instead of
a check constraint.

#3Richard Broersma
richard.broersma@gmail.com
In reply to: Gauthier, Dave (#1)
Re: check constraint on insert but not delete

On Thu, Nov 4, 2010 at 8:03 AM, Gauthier, Dave <dave.gauthier@intel.com> wrote:

Is there a way to require that a check constraint be checked on insert but
not update?    Worth knowing is that my check constraint runs a PLPgsql proc
which returns a yes/no kinf of flag which the constraint proper checks.

I think by definition, Check constraints cannot differentiate between
an update or insert. Its only concern is if the data is valid or not.

If you need this flexibility, you should probably look at check constraints:
http://www.postgresql.org/docs/9.0/interactive/sql-createconstraint.html

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug