sql - IF NOT EXISTS - Mariadb Syntax -


i tried either insert new row or update existing 1 if included.

i figured try indices honest not sure how hence tried if statement. unfortunatly isn't working either because says have problem syntax. using mariadb.

if not exists (select * valuation                 ticker = 'bk001eur' , depot_id =1                   , src_id =2 , valuation_date ='2009-09-09') insert valuation (ticker,depot_id,src_id,valuation_date,value)  values ('bk001eur',1,2,'2009-09-09',14999260.46)  else  update valuation  set value =14999260.46  ticker = 'bk001eur' , depot_id =1    , src_id =2 , valuation_date ='2009-09-09'); 

you use:

-- if exists update update valuation  set value =14999260.46  ticker = 'bk001eur'    , depot_id =1 , src_id =2 , valuation_date ='2009-09-09';  -- if not exist insert insert valuation (ticker,depot_id,src_id,valuation_date,value) select 'bk001eur',1,2,'2009-09-09',14999260.46 not exists (select 1                    valuation                     ticker = 'bk001eur'                       , depot_id =1                       , src_id =2 , valuation_date ='2009-09-09'); 

or better way insert on duplicate update:

insert valuation (ticker,depot_id,src_id,valuation_date,value)  values ('bk001eur',1,2,'2009-09-09',14999260.46) on duplicate key update value =14999260.46; 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -