I have a table with the following fields and sample records:
sample_date customer active 25/12/2010 12356 N 01/12/2012 12356 N 05/11/2013 12356 N 05/07/2014 12356 Y
I want to enforce 2 constraints:
- Just one "ACTIVE" set to "Y" per CUSTOMER (but, several "N" are allowed)
- Just one SAMPLE_DATE per CUSTOMER
So that it refuses to save any other line for this customer with a ACTIVE value of "Y" unless the old one is first set to 'N'.
Any idea on how to achieve that?
Thanks a lot!
booleanfor youractivecolumn? postgresql.org/docs/current/static/datatype-boolean.html