I have a query that will merge the source temp table to target table when there's new row in source that not in target table. the source table used a WITH clause and ROW_NUMBER() to get a non-duplicate row from temp table. I used an ingestion-time partitioned table (day) which mean that during merge I have to specify the column name as from the official doc (Both table have the same table schema)
MERGE mydataset.myfinaltable T
USING (
WITH myNonDupSource AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY product, barcode) AS RowNumber
FROM mySourceTempTable
)
SELECT * EXCEPT (RowNumber)
FROM myNonDupSource
WHERE RowNumber = 1
) as S
ON
T.product = S.product
and T.barcode= S.barcode
WHEN NOT MATCHED THEN
INSERT (
col_a,
col_b,
col_c,
product,
barcode
)
VALUES (
S.col_a,
S.col_b,
S.col_c,
S.product,
S.barcode
);
I ran the query and it show query error: Column name _PARTITIONDATE is ambiguous at mydataset.myfinaltable.
At first I try INSERT (col_a,col_b, col_c,product, barcode) ROW; But it produced the same error.
Not sure which part that I missed, it shouldn't be ambiguous because I specified the column to be inserted but why the _PARTITIONDATE column still thrown an error