docs: document upserts which "do nothing" to return row
See original GitHub issueRight now when you use an upsert mutation and there is a conflict, you’re unable to return the row. For example:
mutation update_participants {
insert_participants(objects: {user_id: "1"}, on_conflict: {constraint: participants_user_id_sprint_token_key, update_columns: []}) {
returning {
id
user_id
}
}
}
Will return:
{
"data": {
"insert_participants": {
"returning": []
}
}
}
Instead, what it should return:
{
"data": {
"insert_participants": {
"returning": [{
id: 1,
user_id: 1
}]
}
}
}
Right now if you want to mimic this behavior you need to run a query to see if a record exists followed by a mutation to create if it doesn’t.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
query of type "INSERT ON CONFLICT DO NOTHING ...
The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted (or updated, if an ON CONFLICT...
Read more >Upsert in SQL: What is an upsert, and when should you use ...
In this example, the primary key value of 2 already exists in the table, so the UPSERT operation updated that row with the...
Read more >Why doesn't the insert/upsert rows endpoint return addedRowIds
Why doesn't the insert/upsert rows API endpoint return addedRowIds when keyColumns is not set ? This behaviour is documented, but it' odd.
Read more >UPSERT - PostgreSQL wiki
Committed version's INSERT documentation: ... UPDATE that existing row instead, while safely giving little to no further thought to ...
Read more >Timescale Documentation | Upsert data
Either updating the existing row, or doing nothing, if a matching row already exists. Upserts only work when you have a unique index...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@timminkov Unfortunately empty
update_columns
translates to Postgres’son conflict do nothing
and that doesn’t return any results. So a simple work around is to update one of the columns from the unique constraint (update_columns: [user_id]
).This forces you to set some bizarre permissions on a db level ie the least dangerous column to update in your unique constraint. Therefore, we really need a real upsert mutation - not an insert on conflict: https://hasura.io/docs/latest/graphql/core/databases/postgres/mutations/upsert.html.