Sample Header Ad - 728x90

Making use of ENUM in CONSTRAINT

0 votes
1 answer
1147 views
I am creating a PostGIS database in which a lot of schemas should have the same constraints. Meaning in the future, similar tables should have the same limitations of values entered. My constraint would be this
ALTER TABLE "Test project"."rainbow table"   -- the table I want to change
ADD CONSTRAINT values_constraint [the name of the constraint]
CHECK  (colors IN ('red', 'green', 'blue'))  -- limiting 3 values in colors
So I thought I will do this making use of enums, which I can define and alter (by re-creating after dropping if something changes) for the whole database. HOWEVER, I am struggling to call the enum values in the constraint defintion, which should be a check I believe
ALTER TABLE "Test project"."rainbow table"  -- the table I want to change
ADD CONSTRAINT values_constraint [the name of the constraint]
   CHECK  (colors IN (/*HOW TO REFERENCE THE ENUM ARRAY HERE?*/))
Asked by KoGIS (3 rep)
Jul 13, 2023, 12:53 PM
Last activity: Jul 24, 2023, 11:00 AM