-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_partial__insert.sql
More file actions
39 lines (29 loc) · 849 Bytes
/
delete_partial__insert.sql
File metadata and controls
39 lines (29 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{{ config(
materialized='incremental',
incremental_strategy = 'merge'
)
}}
{# This is comment by jinja #}
{# delete partial data -> insert #}
{# 1. Delete Data #}
{% set query %}
delete from {{ this }} where dt = CURRENT_DATE
{% endset %}
{# In the first run, this delete macro will not be run #}
{# If we want to run in the first run, remove "if is_incremental()" block #}
{% if is_incremental() %}
{% do run_query(query) %}
{% endif %}
{# 2. Insert(append) Data #}
{# In the first run, all source data will be inserted #}
{# From the second run, the where condition will be applied #}
WITH FINAL AS (
SELECT
*
FROM
{{ source('TRVANALYT_RAW','RESERVATION_D_BOOKINGS') }}
{% if is_incremental() %}
WHERE dt >= DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY)
{% endif %}
)
SELECT * FROM FINAL