From 2040619917e827f58ef4dc9b58f43a98dd34546e Mon Sep 17 00:00:00 2001 From: folhesgabriel Date: Mon, 8 Apr 2024 12:13:25 -0300 Subject: [PATCH] add new incremental logic --- .../br_ms_sia/br_ms_sia__producao_ambulatorial.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql index e5286187..65ef26b6 100644 --- a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql +++ b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql @@ -222,13 +222,13 @@ with from sia_add_municipios ) -select sia.* +select * from sia {% if is_incremental() %} - left join - {{ this }} as materialized - on sia.ano = materialized.ano - and sia.mes = materialized.mes - where materialized.ano is null and materialized.mes is null + where + date(cast(ano as int64), cast(mes as int64), 1) + > (select max(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }}) + or date(cast(ano as int64), cast(mes as int64), 1) + < (select min(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }}) {% endif %}