I have a table definition in Postgres. I would like to add a constraint to a column that is of Character datatype to have only 3 allowed values:
CREATE TABLE my_table
(
id character varying(255) NOT NULL,
uid character varying(255) NOT NULL,
my_text text NOT NULL,
is_enabled boolean NOT NULL
);
So I want the my_text column to contain only 'A', 'B' or 'C' as values.
Where can I find some documentation on this?
Use a check constraint:
More details in the manual: http://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-CHECK-CONSTRAINTS