textの場合
postgres=# CREATE TABLE test (
sample text CONSTRAINT check_invalid_char CHECK (sample !~ 'a')
);
postgres=# INSERT INTO test VALUES ('hoge');
postgres=# INSERT INTO test VALUES ('hage');
ERROR: new row for relation "test" violates check constraint "check_invalid_char"
DETAIL: Failing row contains (hage).
text配列の場合
postgres=# CREATE FUNCTION check_text_value (
vals text[]
) RETURNS boolean AS $$
SELECT bool_and (t !~ 'a') FROM unnest(vals) AS t
$$ LANGUAGE sql IMMUTABLE
postgresql=# CREATE TABLE test (
text[] vals CHECK (check_text_value (vals))
);
参考