“ returning”语句返回0行,但是我希望由于冲突而无法插入的行。我在那里缺少什么?
详细信息:表users_strategies获得了主键(id_strategy,id_account)
xsignalsbot=# select * from users_strategies;
id | id_strategy | id_account | risk | active
----+-------------+------------+------+--------
1 | 1 | 48 | 0.50 | t
2 | 2 | 48 | 0.25 | f
(2 rows)
xsignalsbot=# insert into users_strategies (id_strategy,id_account)
values (1,48) on conflict (id_strategy,id_account) do nothing
returning active,risk;
active | risk
--------+------
(0 rows)
答案 0 :(得分:2)
将“不要做”更改为UPDATE SET语句(不修改最终结果)会提供所需的结果:
xsignalsbot=# insert into users_strategies (id_strategy,id_account)
values (1,48) on conflict (id_strategy,id_account) do update set
id_strategy=excluded.id_strategy returning users_strategies.active, users_strategies.risk;
active | risk
--------+------
t | 0.50
(1 row)
答案 1 :(得分:1)
<div class="container">
<div class="one">
<img src="https://picsum.photos/id/600/600/300">
</div>
<div class="two">
<img src="https://picsum.photos/id/600/601/300">
</div>
<div class="three">
This is the description for the first image
</div>
<div class="four">
This is the description for the second image
</div>
</div>
不适用于DO NOTHING
:
可选的RETURNING子句使INSERT根据实际插入的每一行计算和返回值(或更新,如果使用了ON CONFLICT DO UPDATE子句)。