Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL: INSERT ... ON CONFLICT DO NOTHING raises DbError #19

Open
moigagoo opened this issue Nov 17, 2021 · 0 comments
Open

PostgreSQL: INSERT ... ON CONFLICT DO NOTHING raises DbError #19

moigagoo opened this issue Nov 17, 2021 · 0 comments

Comments

@moigagoo
Copy link
Contributor

I'm implementing a way to ignore conflicts during insertion in Norm: moigagoo/norm#120

I've stumbled upon an issue with Postgres in ndb.

If you have an INSERT query with ON CONFLICT DO NOTHING, the query fails despite being a totally valid query with a totally normal result.

I think the root of the problem lays here: https://github.com/xzfc/ndb.nim/blob/master/ndb/postgres.nim#L705

I'm not sure what pqNfields(res), pqntuples(res), or pqgetisnull(res, 0, 0) are but it seems like this check validates that a row was created in the db and raises an error if it wasn't. However, the row shouldn't be created, this is explicitly requested with ON CONFLICT DO NOTHING clause.

In the case of ON CONFLICT DO NOTHING the values are:

  • pqNfields(res) == 1
  • pqntuples(res) == 0
  • pqgetisnull(res, 0, 0) == 1
@moigagoo moigagoo changed the title PostgrSQL: INSERT ... ON CONFLICT DO NOTHING raises DbError PostgreSQL: INSERT ... ON CONFLICT DO NOTHING raises DbError Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant