sql - Bulk Insert Only New Rows -


i have a group of csv files i'm using populate sql database. i'm setting daily process. i've discovered though handful of files come in each day historical data, not daily updates.

when try bulk insert causes error because primary key being violated.

i thought setting ignore_dup_key = on stop non-unique records being inserted.

create table table1 ( column1 varchar(32), column2 varchar(32), column3 char(9), column4 int, column5 float(53), column6 date, constraint pk_one     primary key (column1, column2, column6)     (ignore_dup_key = on) ); 

then when try run script updates tables unhelpful error message "associated statement not prepared (0)."

i around writing results separate table, writing new rows table proper, having separate handling different tables strikes me painful, , ugly.

is there easy way tell sql write rows don't violate primary key constraint?

insert table1 (column1) value (value1)

... so, if want ignore inserts fail, insert ignore into. it'll try insert values, fail, , move on gracefully. if want replace duplicate key values new values attempted insert, check out : (below, ignore optional, depends on if want throw errors.)

insert [ignore] table1 (column1) values (value1) on duplicate key update 

so "insert ignore" answer, on inserts not on table creation. refer mysql docs. , on duplicate key update useful know.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -