【问题标题】:Postgres Upsert with SelectPostgres Upsert 与 Select
【发布时间】:2021-12-14 03:33:11
【问题描述】:

我正在尝试使用 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

但我收到以下错误:

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

这似乎应该按照this question 工作。如果我删除 ON CONFLICT 位,它工作正常。带有值列表的普通 upsert 也可以正常工作。

我正在运行 postgresql 13.4。

【问题讨论】:

    标签: postgresql subquery upsert


    【解决方案1】:

    那就是EXCLUDED.search_content。列名是您INSERT 所在表中目标列的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 1970-01-01
      • 2018-03-04
      相关资源
      最近更新 更多