sql - single-row subquery returns more than one row in Redshift when I try to use CASE in UPDATE -
i trying use case statement sub query in update statement facing issue
single-row sub query returns more than
please find query tried
update r_gl.ac set meeting_cost = case currency_code when 'ind' amount else round(tgt.amount) r_gl.ac tgt join ( select distinct a.frm_cur, a.to_cur, a.exch_rate b_gl.currncy_conv_dim join r_gl.ac b on (a.frm_cur = 123 , a.to_cur = b.cur_cd , f_rate = 'abc') join b_gl.int_fg on b.in_s=c.in_s , a.cal_sk = trunc(c.intact_dt_key,-2) ) src on tgt.cur_cd=src.to_cur ) end
please me solve issue
your current case
expression missing end
. aside, see bigger problems update
statement. redshift based on old version of postgres, , hence expect adhere same syntax postgres use update join:
update table1 t1 set some_column = t2.some_other_column table2 t2 t1.id = t2.id
applying syntax current query along fix case
expression leaves following:
update r_gl.ac tgt set meeting_cost = case when currency_code = 'ind' tgt.amount else round(tgt.amount) end ( select distinct a.frm_cur, a.to_cur, a.exch_rate b_gl.currncy_conv_dim inner join r_gl.ac b on (a.frm_cur = 123 , a.to_cur = b.cur_cd , f_rate = 'abc') inner join b_gl.int_fg on b.in_s=c.in_s , a.cal_sk = trunc(c.intact_dt_key,-2) ) src tgt.cur_cd = src.to_cur
the table joining r_gl.ac
has no effect on data being used update, rather affect update targeting rows. if not intended logic, might have rethink entire query.
Comments
Post a Comment