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

Insert only if Unique. #332

Open
robertmkjeffrey opened this issue Feb 10, 2022 · 0 comments
Open

Insert only if Unique. #332

robertmkjeffrey opened this issue Feb 10, 2022 · 0 comments

Comments

@robertmkjeffrey
Copy link

Hi all,

I am using ODBC.load to push updated data into a database. This unfortunately fails if the dataframe contains elements already present in the database.

It would be great is ODBC.load had a "skip existing" option which ignored rows for which the primary key already exists. This would likely require passing the unique column names to the function as well.

Example of the error:

ERROR: LoadError: 40002: [MonetDB][ODBC Driver 11.43.5]INSERT INTO: PRIMARY KEY constraint 'weather_history.weather_history_station_id_date_pkey' violated
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] execute(stmt::ODBC.API.Handle)
   @ ODBC.API C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\API.jl:114
 [3] execute(stmt::ODBC.Statement, params::Tables.Row{DataFrameRow{DataFrame, DataFrames.Index}}; debug::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ODBC C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\dbinterface.jl:164
 [4] (::ODBC.var"#46#47"{Bool, Int64, ODBC.Connection})()
   @ ODBC C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\load.jl:102
 [5] transaction(f::ODBC.var"#46#47"{Bool, Int64, ODBC.Connection}, conn::ODBC.Connection)
   @ ODBC C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\load.jl:112
 [6] load(itr::DataFrame, conn::ODBC.Connection, name::String; append::Bool, quoteidentifiers::Bool, debug::Bool, limit::Int64, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ODBC C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\load.jl:96
 [7] load(itr::DataFrame, conn::ODBC.Connection, name::String)
   @ ODBC C:\Users\rjeffrey003\.julia\packages\ODBC\qhwMX\src\load.jl:76
 [8] top-level scope
   @ c:\Users\rjeffrey003\Documents\Work\1 - Weather Data\main.jl:211
in expression starting at c:\Users\rjeffrey003\Documents\Work\1 - Weather Data\main.jl:211
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