Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query of type "INSERT ON CONFLICT DO NOTHING RETURNING" returns nothing

The "returning" statement returns 0 rows, but I want the row that couldn't be inserted because of the conflict. Something I am missing there?

detail: table users_strategies got primary keys (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)
like image 744
Rodrigo Formighieri Avatar asked Oct 19 '25 06:10

Rodrigo Formighieri


1 Answers

DO NOTHING does not apply to 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).

reference

like image 164
Ancoron Avatar answered Oct 21 '25 09:10

Ancoron