sql - do not update if exists postgres -
i have table has unique constraint on (uid,client_fact). when try update client_fact raise error on constraint obvious because if update client_fact value 2 user_id 1 , if there combination of these 2 column raise exception. there way can skip , continue updating others.
the query using is
update user_ft set client_fact_id = 779, client_fact_id in (select client_fact_id user_ft client_fact_id = 778 , updated_date::date =< '2015-05-28') , not exists (select uid ,client_fact_id user_ft client_fact_id = 779)
i used not exists clause handle case have combination of user , factid sitting in table. ran didn't updated anything.
got ... don't need use not exists. .. result skipping rows canged query have if user in table combination don't consider user in query. see below corrected query
update user_ft set client_fact_id = 779 client_fact_id in (select client_fact_id user_ft client_fact_id = 778 , updated_date::date =< '2015-05-28') , uid not in (select uid user_ft client_fact_id = 779)
thanks
Comments
Post a Comment