I have a parallel unnest that requires an upsert:
CREATE FUNCTION public.sort_category(category_ids integer[], sort integer[])
RETURNS void
AS $$
INSERT INTO upsert (user_id, category_id, sort)
SELECT sessions.user_id, category_id, sort_index
FROM UNNEST($1, $2) as input(category_id, sort_index), sessions
WHERE sessions.session_token = 'a'
ON CONFLICT (user_id, category_id)
DO
UPDATE SET sort = sort_index;
$$ LANGUAGE sql VOLATILE STRICT;
From my command line, I receive this error:
ERROR: column "sort_index" does not exist LINE 11: UPDATE SET sort = sort_index;
HINT: There is a column named "sort_index" in table "SELECT", but it cannot be referenced from this part of the query.
Fiddle is here, please. Error is different on fiddle, but function is same: