Here is my code:
CREATE OR REPLACE FUNCTION public.colors(color text) RETURNS void LANGUAGE plpgsql AS $function$ DECLARE colorOptions text []; BEGIN colorOptions := '{ red, orange, yellow }'; IF color <> ANY (colorOptions) THEN raise notice 'This color is not accepted!'; END IF; END; $function$; The problem is that it raises a notice for any value I send it, irrespective of whether that value is in the array of colors or not.
For example, all of these raise a notice:
SELECT colors ('red'); SELECT colors ('black'); SELECT colors ('rubbish'); I tried using IN instead of ANY, as follows:
IF color NOT IN (colorOptions) THEN That produces the following error:
Query 1 ERROR: ERROR: operator does not exist: text <> text[] LINE 1: color NOT IN (colorOptions)
<> ALL (...)