I want to create a function in Postgres along the lines of this:
CREATE OR REPLACE FUNCTION public.getAvailableForms (
get_form_names TEXT[]
) RETURNS TABLE (
id INTEGER,
name TEXT,
location TEXT,
created TIMESTAMP
) AS $$
BEGIN
RETURN QUERY
SELECT *
FROM form
WHERE form.name IN get_form_names;
END;
$$ LANGUAGE plpgsql
SECURITY DEFINER;
However, it tells me that WHERE form.name IN get_form_names is syntactically incorrect.
I can't find any documentation on how to use array variables in a postgres function call.
Anyway, is it possible to use an array value passed as a function argument in a WHERE ... IN?
Use any:
where form.name = any (get_form_names)
in would be for a discrete list of items, but any is used for an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With