-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
Make it easier to fix out-of-sync sequences via Mathesar UI #4100
Comments
@polymathematic The issue you're facing is due to the default behaviour of PostgreSQL's sequences. When inserting rows into PostgreSQL tables, if values are manually specified for columns with sequences, the sequences might go out-of-sync. When combined with PK or unique keys, this might cause duplicate key errors. Let me first try to explain the cause, and then I'll provide ways to resolve it. Cause
Ways to resolve this for your usecaseApproach 1 (Recommended)In your scripts, do not manually specify values for the ✅ Use: INSERT INTO authors (name) VALUES ('somename'); ❌ instead of: INSERT INTO authors VALUES (1, 'somename'); If you maintain a different id of sorts, eg., StudentID, it is recommended to create a different column for it instead of using the default 'id' column. Approach 2 (only if you have to specify a value for
|
I'm updating the title to better describe what we can do in Mathesar. |
Thank you for the detailed response. This makes total sense and I learned something new about Postgres today. |
Description
My workflow requires me to interact with a particular Postgres table with two tools: first a script to create new records and then Mathesar to manually update details about those records. I noticed today that for this table, when I attempt to create a new record with the Mathesar interface, that the primary key column does not populate, and therefore the record cannot be created due to the PK constraint.
Expected behavior
I expected the primary key field to populate a new, unique value for the table even after other tools have inserted rows.
To Reproduce
Create a table in Mathesar. Add new records using the interface to validate normal behavior. Create a new row using an INSERT script. Attempt to create additional rows in the Mathesar interface to validate the PK is no longer populating automatically for new records.
The text was updated successfully, but these errors were encountered: