"INSERT ON CONFLICT DO NOTHING RETURNING" returns 类型的查询 无
query of type "INSERT ON CONFLICT DO NOTHING RETURNING" returns nothing
"returning"语句returns0行,但我想要的是因为冲突无法插入的行。我在那里缺少什么?
详细信息:table 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)
DO NOTHING
不适用于RETURNING
:
The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted (or updated, if an ON CONFLICT DO UPDATE clause was used).
将 DO NOTHING 更改为 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)
"returning"语句returns0行,但我想要的是因为冲突无法插入的行。我在那里缺少什么?
详细信息:table 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)
DO NOTHING
不适用于RETURNING
:
The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted (or updated, if an ON CONFLICT DO UPDATE clause was used).
将 DO NOTHING 更改为 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)