Can I run update with select in Athena ICEBERG?

0

Hi, I'm using Athena Table - ICEBERG type. I would like to update with Select statement in order to update bunch of records at a time. For example: UPDATE skus_market_share_sum1 SET sales_kpis_sales_7d_agg = s.new_values FROM (SELECT SKU, new_values FROM other_table) s WHERE skus_market_share_sum1.SKU = s.SKU;

Currently I'm getting an error about the FROM statement. Is there any other option to update bunch of records using SQL and ICEBERG?

moshe
질문됨 5달 전529회 조회
2개 답변
3

Hello,

Update might not be suitable for changing/updating multiple rows in a transaction as Athena Iceberg UPDATE writes Iceberg position delete files and newly updated rows as data files in the same transaction. So, you can try using merge into statement for this approach. Details are given here.

MERGE INTO skus_market_share_sum1 m
USING other_table o 
ON o.SKU = m.SKU
WHEN MATCHED THEN 
  UPDATE SET m.sales_kpis_sales_7d_agg = o.new_values;

This will perform an update where rows match between the two tables based on the ON condition.

AWS
지원 엔지니어
답변함 5달 전
  • Thank you. Is there an option to use Merge into with specific select? like: select * from ( select *, row_number() over (.....) rn from <table>
    ) where rn = 1

    Thank you

2

Could run Merge into with Select, example below

MERGE INTO skus_market_share_sum1 t 
USING (
    select *
	from (
                       <>
                    )
                where rn = 1 AND category LIKE '%NNN%'
) s
ON (t.sku = s.sku)
WHEN MATCHED 
    THEN UPDATE 
        SET sales_kpis_sales_7d_agg = s.sales_kpis_sales_7d_agg
moshe
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠