You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using csvsql to insert into to a Postregress database, and I'd like it to ignore any errors generated from unique constraints (basically skip importing the same data twice).
In Postgres and that would be handled like this:
INSERT INTO table (num1, num2) VALUES (1,1) ON CONFLICT DO UPDATE
However, it doesn't look like any of the current csvsql options allow me to modify the insert statement like this, since --prefix would add it direcly after INSERT and --after-insert executes a seperate statement. Postgres doesn't support the 'OR IGNORE' format that MySQL does.
Seems like a --suffix option to append something to the end of the query would be useful here, or is this a fundamental issue, since agate-sql doesn't support this?
Are there any alternatives for ignoring unique constraint insert attempt errors? Even just a flag to ignore any error from an individual insert statement and keep trying would help here.
The text was updated successfully, but these errors were encountered:
Indeed. agate-sql uses SQLAlchemy, and --prefix causes it to call prefix_with(). Your feature would involve adding a CLI argument that causes it to call on_conflict_do_update or on_conflict_do_nothing.
If you write a PR for agate-sql, I can expose it in csvkit.
jpmckinney
changed the title
Support '--suffix' in csvsql (for Postgres ON CONFLICT DO NOTHING e.g.)
csvsql: Add option to use ON CONFLICT DO NOTHING/UPDATE
Dec 20, 2022
I'm using csvsql to insert into to a Postregress database, and I'd like it to ignore any errors generated from unique constraints (basically skip importing the same data twice).
In Postgres and that would be handled like this:
However, it doesn't look like any of the current csvsql options allow me to modify the insert statement like this, since
--prefix
would add it direcly after INSERT and--after-insert
executes a seperate statement. Postgres doesn't support the 'OR IGNORE' format that MySQL does.Seems like a
--suffix
option to append something to the end of the query would be useful here, or is this a fundamental issue, since agate-sql doesn't support this?Are there any alternatives for ignoring unique constraint insert attempt errors? Even just a flag to ignore any error from an individual insert statement and keep trying would help here.
The text was updated successfully, but these errors were encountered: