In a table with a field code
, I want to authorize the user to choose one value among a list.
Here is a sample of the values of the list :
A|AG|AL|AS|B|C|D|DA
I added a constraint on code
like this :
ALTER TABLE mytable
ADD CONSTRAINT verif_code CHECK (code::text ~ '(A|AG|AL|AS|B|C|D|DA)')
Despite of this, I can add an extra value after a first one picked up in the list.
ALY accepted -> :(
Y rejected -> :)
How to avoid the possibility of adding a value in the second position that is not in the list?
(I could use a IN
operator but at the end, the authorized values for code
will be a combinaison of three sets of lists.)