You can do what you want in more than one way. If you want to use the ALL(...)
quantifiers, you need a suitable operator. For that, you first need a function to perform what you want:
Imagine you want to check that your texts don't have any uppercase letter in them. You'd define a function like:
CREATE FUNCTION doesnt_have_uppercase(b boolean, t text)
/* Compares b to the result of `t` not having any non-lowercase character */
RETURNS boolean
IMMUTABLE
STRICT
LANGUAGE SQL
AS
$$
SELECT (t = lower(t)) = b
$$ ;
Based on it, create an operator:
CREATE OPERATOR =%= (
PROCEDURE = doesnt_have_uppercase,
LEFTARG = boolean,
RIGHTARG = text
) ;
You need this operator because the ANY
and ALL
quantifiers need the following structure:
expression operator ALL(array)
At this point, you can define:
create table foo
(
bar text[] not null,
CONSTRAINT bar_texts_cant_have_uppercase CHECK(true =%= ALL(bar))
);
Which will lead you to the following behaviour:
INSERT INTO foo
(bar)
VALUES
(ARRAY['this will pass', 'this too']) ;
1 rows affected
INSERT INTO foo
(bar)
VALUES
(ARRAY['that would pass', 'BUT THIS WILL PREVENT IT']) ;
ERROR: new row for relation "foo" violates check constraint "bar_texts_cant_have_uppercase"
DETAIL: Failing row contains ({"that would pass","BUT THIS WILL PREVENT IT"}).
Check it all at
dbfiddle here
I would most probably seek a less tortuous route, however:
CREATE FUNCTION doesnt_have_uppercase(t text[])
/* Returns true if all elements of t don't have any uppercase letter */
RETURNS boolean
IMMUTABLE
STRICT
LANGUAGE SQL
AS
$$
SELECT (NOT EXISTS (SELECT 1 FROM unnest(t) q WHERE q <> lower(q)))
$$ ;
create table foo
(
bar text[] not null,
CONSTRAINT bar_texts_cant_have_uppercase CHECK(doesnt_have_uppercase(bar))
);
This behaves exactly like the previous example (except if some of the elements of the array are NULL).
dbfiddle here