On 26/2/19 5:11 μ.μ., Campbell, Lance wrote:
PostgreSQL 10.x
What is the best way to restrict the values on a text field to make sure they only contain particular values: Example: The field “type” can only contain the values of “X”, “Y” and “Z”. Would a trigger be the best strategy? Or is there a special SQL type I should use in this particular case?
Easy with a CHECK CONSTRAINT, like :
create table baba (type varchar(10) CHECK (type in ('X','Y','Z')));
--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt