-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
upsert of new row with check constraints fails #514
Comments
Huh... on that basis, it's possible my fix in 2376c45 is incomplete. I only covered the 'not null' case. |
OK, this fails silently: import sqlite_utils
db = sqlite_utils.Database(memory=True)
db.execute('''CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER,
salary REAL,
CHECK (salary is not null and salary > 0)
);''')
db["employees"].upsert({"id": 1, "name": "Bob"}, pk="id")
list(db["employees"].rows) It outputs: [] |
Applying the fix from the PR here doesn't fix the above problem either: So it looks like these kinds of |
Seeing as |
(I originally opened this in simonw/datasette-insert#20, but I see that that library depends on sqlite-utils)
In the case of a new row, upsert first adds the row, specifying only its pkeys:
sqlite-utils/sqlite_utils/db.py
Lines 2783 to 2787 in 965ca0d
This means that a table with NON NULL (or other constraint) columns that aren't part of the pkey can't have new rows upserted.
The text was updated successfully, but these errors were encountered: