postgresql - Trigger vs. check constraint -


i want add field-level validation on table. there field named "account_number" , field should pass "luhn" check. i've found function called "luhn_verify" seems work (google if interested). returns boolean. question is:

are there major performance advantages in postgresql using trigger validation vs. check constraint.

additional information:

  • postgresql 9.1
  • table not have insert trigger, have update.

disclaimers:

i feel has been answered, can't seem find distinct answer. if so, please mark duplicate , reference original question/answer.

might better questions dba board.

the rule of thumb use check constraint before resort triggers.

a check constraint faster, simpler, more portable, needs less code , less error prone. triggers can circumvented other triggers, instance.

triggers more complicated. use them when have to, more complex requirements.

if check constraint restrictive case or causes trouble reloading dump, use not valid modifier middle ground (pg 9.2+). details:


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -