How can I use MERGE or UPDATE in BigQuery for data with RECORD or ARRAY date types?

157 Views Asked by At

I want to merge sale details, using a sql query in BigQuery where it should update when a MLM identifier aready exists, and insert otherwise.But when executing with the Variation array(Record), it wont insert anything to the table,even though ther is no data.Also no errors are given.I have used another method but it only inserts data ,whithout checking if the data already exists.

I used this code in python, i have searched the google documentation but it only shows me ways to insert,data without MERGE or UPDATE:

merge_query = f"""
                MERGE `olimpo-gaon.OLIMPO_DB.Products_MLB_aux` T
                USING (
                SELECT 
                '{MLM}' as MLM, 
                '{ID_Sub_Category}' as Sub_Category_ID,
                {Oficial_Store_ID} as Store_ID,
                '{Title}' as Title_Products,
                {Offer_Price} as Offer_Price,
                {Original_Price} as Original_Price, 
                {Sold_Quantity} as Sold_Quantity,
                {Available_Quantity} as Available_Quantity,
                '{Permalink}' as Permalink,
                '{Campaign}' as Campaign,
                '{Status_Product}' as Status_Product,
                '{Status_Product_Motivo}' as Status_Motive,
                '{Variations}' as Variations
                ) S
                ON T.MLM = S.MLM
                WHEN MATCHED THEN 
                UPDATE SET T.Sub_Category_ID = S.Sub_Category_ID, T.Store_ID = S.Store_ID, T.Title_Products = S.Title_Products,
                             T.Offer_Price = S.Offer_Price, T.Original_Price = S.Original_Price, T.Sold_Quantity = S.Sold_Quantity,
                             T.Available_Quantity = S.Available_Quantity, T.Permalink = S.Permalink, T.Campaign = S.Campaign,
                             T.Status_Product = S.Status_Product, T.Status_Motive = S.Status_Motive, T.Variations = S.Variations
                WHEN NOT MATCHED THEN 
                INSERT (MLM, Sub_Category_ID, Store_ID, Title_Products, Offer_Price, Original_Price, Sold_Quantity, Available_Quantity,
                          Permalink, Campaign, Status_Product, Status_Motive, Variations)
                  VALUES (MLM, Sub_Category_ID, Store_ID, Title_Products, Offer_Price, Original_Price, Sold_Quantity, Available_Quantity,
                          Permalink, Campaign, Status_Product, Status_Motive, Variations)
                """
0

There are 0 best solutions below