SQLite "UPSERT" issue -


being db noob, i'm trying generate sqlite statements import records "first_reported" , "last_reported" datestamps, can't seem "first_reported" working correctly.

i have few years worth of scans i'm trying import. there'll plenty of duplicates, want update "last_reported" column if record exists. if not, create record.

i've searched , have tried following of other solutions (sqlite - upsert *not* insert or replace), can't seem right. i'm not sure if i'm going wrong way, or fat fingered something?

any suggestions? hundreds of thousands of rows, should using else? i'm looking efficiency , don't want "just works". want "right" way.

i created table such;

create table scan_results (first_reported text, last_reported text, hostname text, ipaddress text, network text, osinformation text, displaypath text, testname text, message text, findingobject text, findingresult text, findingexpr text, unique (hostname, ipaddress, network, osinformation, displaypath, testname, message, findingobject, findingresult, findingexpr)); 

and i'm trying insert/update rows this;

with new (first_reported, last_reported, hostname, ipaddress, network, osinformation, displaypath, testname, message, findingobject, findingresult, findingexpr) ( values('2017-08-15', '2017-08-30', 'somehost', 'someip', 'somenet', 'someos', 'somedisplay', 'sometest', 'somemessage', 'someobject', 'someresult', 'someexpr') ) insert or replace scan_results (first_reported, last_reported, hostname, ipaddress, network, osinformation, displaypath, testname, message, findingobject, findingresult, findingexpr) select old.first_reported, new.last_reported, new.hostname, new.ipaddress, new.network, new.osinformation, new.displaypath, new.testname, new.message, new.findingobject, new.findingresult, new.findingexpr new left join scan_results old on new.hostname = old.hostname; 

i seem have figured out (maybe?) formatting differently. made little easier noob me read. it's 1 of answers tried before. other question still stands. "proper" way of dealing hundreds of thousands of records? or there more efficient way of doing this?

replace scan_results (   first_reported,   last_reported,   hostname,   ipaddress,   network,   osinformation,   displaypath,   testname,   message,   findingobject,   findingresult,   findingexpr) select   ifnull(old.first_reported,"05/01/2015"),   "12/01/2017",   "somehost",   "someip",   "somenetwork",   "someos",   "somemessage",   "someobject",   "somemessage",   "someobject",   "someresult",   "someexpr" scan_results  left join scan_results old on old.hostname = "somehost"; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -