From 89344e3633b4febe62c66af3d01acf0587d06cd4 Mon Sep 17 00:00:00 2001 From: uiro-bi Date: Wed, 11 Sep 2024 10:53:49 -0300 Subject: [PATCH] feat: re insert materialization logic --- models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql | 4 +++- models/br_ms_sia/br_ms_sia__psicossocial.sql | 4 +++- 2 files changed, 6 insertions(+), 2 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 04a75d45..785f509a 100644 --- a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql +++ b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql @@ -238,6 +238,8 @@ select * from sia {% if is_incremental() %} - where date(cast(ano as int64), cast(mes as int64), 1) > date(2024, 3, 1) + 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 }}) {% endif %} diff --git a/models/br_ms_sia/br_ms_sia__psicossocial.sql b/models/br_ms_sia/br_ms_sia__psicossocial.sql index 6d43ae0a..920be430 100644 --- a/models/br_ms_sia/br_ms_sia__psicossocial.sql +++ b/models/br_ms_sia/br_ms_sia__psicossocial.sql @@ -148,5 +148,7 @@ select safe_cast(qtdpcn as string) quantidade_pacientes, from sia_add_municipios as t {% if is_incremental() %} - where date(cast(ano as int64), cast(mes as int64), 1) > date(2024, 3, 1) + 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 }}) {% endif %}