Vertica SQL Update Subquery used as an expression returned m

Moderator: NorbertKrupa

Post Reply
clv100
Beginner
Beginner
Posts: 27
Joined: Tue Oct 16, 2012 6:04 pm

Vertica SQL Update Subquery used as an expression returned m

Post by clv100 » Thu Jun 20, 2013 2:45 pm

Scenario: Data Warehouse fact table being updated by values in staging table matching on keys.

This works fine:

UPDATE non_sales.f_retail_history
SET

prm_retail_prc = (select s.prm_retail_prc from non_sales.stage_f_retail_history as s where non_sales.f_retail_history.week_gen_key = s.week_gen_key AND
non_sales.f_retail_history.item_gen_key = s.item_gen_key AND non_sales.f_retail_history.comp_gen_key = s.comp_gen_key)

BUT

We do NOT want to update the column if the value in the staging table is a NULL - we want to retain the value in the fact table column. We have tried NUMEROUS SQL statements to solve this problem but always get a subquery error:

prm_retail_prc = (select case when stg_prm_retail_prc is null and fct_prm_retail_prc is not null then fct_prm_retail_prc else stg_prm_retail_prc end as prm_retail_prc from (select s.prm_retail_prc as stg_prm_retail_prc, f.prm_retail_prc as fct_prm_retail_prc from non_sales.f_retail_history f, non_sales.stage_f_retail_history s where f.week_gen_key = s.week_gen_key and f.item_gen_key = s.item_gen_key and f.comp_gen_key = s.comp_gen_key)x)

I would appreciate any help with this since this is PARAMOUNT in our production processing. I have written a python script but the processing time is untenable for our daily production.
Thanks,
clv100

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Vertica SQL Update Subquery used as an expression return

Post by id10t » Fri Jun 21, 2013 8:28 am

Hi!

Try merge

Post Reply

Return to “Vertica SQL”