goqu
goqu copied to clipboard
Upsert constraint violations
I'm always frustrated when I need to do UPSERT
in PostgreSQL. It all works well when I need to do something like in examples. Unfortunately, I didn't find any way to use additional clauses, e.g. I didn't find any way to use ...ON CONFLICT .. ON CONSTRAINT..
. Also, DoUpdate(target string, update interface{})
supports only one target field. How to use It if I need something like this:
ON CONFLICT (a, b) ....
?
Describe the solution you'd like
I would like to have a solution which I can use to handle constraint conflicts while UPSERT
Dialect
- postgres
Any movement here? I noticed that DoNothing()
does not support an action. So you cannot express INSERT INTO ... ON CONFLICT my_unique_constraint DO NOTHING
.
Hi I have the same question. I want to do "on conflict (field1, field2) do nothing or update....
Is there a way to do this now?
I'm looking to do add to my query
ON CONFLICT ON CONSTRAINT unique_constraint DO UPDATE SET count = p.count + EXCLUDED.count
But I'm struggling to figure out how to do this. Is this currently not supported by goqu?
Just to summarize this very old issue, there's no way to express the target in INSERT ... ON CONFLICT (target) DO NOTHING
, since DoNothing()
does not support a target name.
@doug-martin The logical solution seems to be do make doNothingConflict
support a target, just like conflictUpdate
, and update onConflictSQL()
to handle it.
I stumbled on this issue. Here's the expression I want to build for PostgreSQL:
... ON CONFLICT (user_id, method, network, identifier) WHERE deletion_ts IS NULL DO NOTHING
Here is my escape:
dialect.Insert("some_table").Cols("col1", "col2", "col3").Vals(vals...).
OnConflict(goqu.DoUpdate(
"ON CONSTRAINT smth_unique",
goqu.C("col1").Set(goqu.L("EXCLUDED.col1")),
))