You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MERGE INTO {{ catalog }}.{{ schema }}.{{ table }} AS target
3
19
USING (
4
20
WITH change_query AS (
5
21
SELECT
6
22
src.*,
7
-
CASE WHEN tgt.{% if pk is iterable and pk is not string and pk is not mapping %}{{ pk | first }}{% else %}{{ pk }}{% endif %} IS NULL THEN 99
23
+
CASE WHEN tgt.{{ pk_list | first }} IS NULL THEN 99
8
24
WHEN hash({{ columns | map_fmt('src.{0}') | join(', ') }}) <> hash({{ columns | map_fmt('tgt.{0}') | join(', ') }}) THEN 1
9
25
ELSE 0 END AS data_change
10
-
FROM {% if source is defined %}{{ source | trim }}{% elif query is defined %}{{ '( {} )'.format(query) }}{% else %}{{ raise_undefined('source|query') }}{% endif %} AS src
26
+
FROM {{ source_query }} AS src
11
27
LEFT JOIN {{ catalog }}.{{ schema }}.{{ table }} AS tgt
SELECT* EXCEPT( data_change ) FROM change_query WHERE data_change IN (99, 1)
15
31
) AS source
16
-
ON{% if pk is iterable and pk is not string and pk is not mapping %}{{ pk | map_fmt('target.{0} = source.{0}') | join(' AND ') }}{% else %}{{ 'target.{0} = source.{0}'.format(pk) }}{% endif %}
0 commit comments