Home > Mobile >  Postgres Upsert with Select
Postgres Upsert with Select

Time:10-30

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.

CodePudding user response:

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

  • Related