MERGE Statement with FILTER

0

Hello Team, I am trying to use a merge statement to merge data from the glue catalog to redshift tabes. The requirement is to merge records and have a filter clause

For example: Here where the clause does not work MERGE INTO target_table USING <glue catalog table - which gets copied into temp table> WHERE source_table.column = 'value' ON ...


I also tried using and as a predicate but it merged the record with id 0001230

MERGE INTO TARGET TABLE USING #temp_table src ON TARGET.id = src.id and src.id != '0001230' WHEN MATCHED THEN UPDATE SET

how should I add a filter in the merge statement?

asked 2 months ago115 views
2 Answers
0

Hi,

Currently Redshift MERGE statements do not allow for the source table to be a view, subquery, or CTE (created by a WITH statement). If you need to perform some filtering on the source table before applying the MERGE you will need to create a permanent or temporary table to be used as the source.

Alternatively you can use UPDATE and INSERT statements.

profile pictureAWS
EXPERT
answered 2 months ago
-1

I would just use a WITH clause before the merge to filter the source table before the merge.

profile pictureAWS
EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions