0

I'm trying to upsert a record with a select:

INSERT INTO global_search (entity_id, entity_type, search_content)
SELECT id, 'user', "username"
FROM "user"
WHERE "id" = 1
ON CONFLICT (entity_id) DO UPDATE
SET search_content = excluded.username

But I'm getting the following error:

ERROR:  column excluded.username does not exist
LINE 8: SET search_content = excluded.username

This seems like it should work per this question. If I remove the ON CONFLICT bit it works fine. Normal upserts with values lists work fine as well.

I'm running postgresql 13.4.

1
  • 1
    Are you trying to bulk change rows? Probably it worth checking the new MERGE feature on PostgresSQL >= v15 It would be something like: MERGE INTO s1 USING s2 ON id WHEN MATCHED THEN UPDATE .... WHEN NO MATCHED THEN INSERT... Commented Oct 14, 2022 at 9:25

1 Answer 1

1

That would be EXCLUDED.search_content. The column name is that of the target column in the table into which you INSERT.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.