使用选择的结果进行Postgres upsert [英] Postgres upsert using results from select
本文介绍了使用选择的结果进行Postgres upsert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用select的值对postgres进行增补。看起来像这样:
I'm trying to upsert with postgres using values from a select. It looks like:
INSERT INTO foo (a, b, c)
SELECT a_, b_, c_
-- hairy sql
ON CONFLICT (...condition...) DO UPDATE
SET "c"=???
发生冲突时,我想使用select语句中的值之一,但是我不能找到正确的语法对其进行别名。我该如何使用Postgres?
On conflict, I want to use one of the values from my select statement, but I can't find the right syntax to alias it. How can I do this with Postgres?
推荐答案
使用 excluded
关键字:
INSERT INTO foo (a, b, c)
SELECT a_, b_, c_
-- hairy sql
ON CONFLICT (...condition...) DO UPDATE
SET c = excluded.c;
这篇关于使用选择的结果进行Postgres upsert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文