A section of a PL/pgSQL function looks like this:
INSERT INTO assistant.accesstoken
(
submission_id,
token,
expires
)
VALUES
(
v_submission_id,
assistant.pseudo_encrypt(v_submission_id),
CURRENT_TIMESTAMP + v_token_duration
)
ON CONFLICT (submission_id)
DO UPDATE SET
expires = CURRENT_TIMESTAMP + v_token_duration
RETURNING token
INTO v_accesstoken;
...and gives me a complaint:
psycopg.errors.AmbiguousColumn: column reference "submission_id" is ambiguous
LINE 13: ON CONFLICT (submission_id)
^
DETAIL: It could refer to either a PL/pgSQL variable or a table column.
QUERY: INSERT INTO assistant.accesstoken
(
submission_id,
token,
expires
)
VALUES
(
v_submission_id,
assistant.pseudo_encrypt(v_submission_id),
CURRENT_TIMESTAMP + v_token_duration
)
ON CONFLICT (submission_id)
DO UPDATE SET
expires = CURRENT_TIMESTAMP + v_token_duration
RETURNING token
CONTEXT: PL/pgSQL function assistant.evaluation_begin(character varying,character varying) line 115 at SQL statement
There is no variable named submission_id. Name only exists as a column name.
Unfortunately, it seems to be an error to specify table for the submission_id:
ERROR: syntax error at or near ")"
LINE 140: ON CONFLICT (accesstoken.submission_id)
How do I fix this then? How to prefix conflict_target for ON CONFLICT in a way that it is accepted?
Additional, can someone point me to a source where I could learn how variables and ON CONFLICT can go together? How would an INSERT be interested on a "conflict" in a PL/pgSQL variable when inserting a row, and what would it even mean? I am genuinely curious...
Does PostgreSQL have overzealous checking or something? There are no variables, anywhere ever in this application, that would not be prefixed with in_, out_, inout_, r_ or v_, ...meaning that there is no ambiguity of this kind that I could see.