Hi !! I try tro get the number of affected rows on a post_hook query and getting this error:
dbt.context.providers.RuntimeDatabaseWrapper.
Is thiss the better way or exists another ? Thanks !
My macro is:
{% macro teste_log_post_hook() %}
{% if execute %}
{% set cod_processamento_var = log_processamento_inicializa('teste_post_hook') %}
{% set update_query = "update mydataset.mytable set value_column = 'changed';" %}
{% set affected_rows = get_affected_rows(update_query) %}
{% set log_debug = '**** Debug **** ' ~ affected_rows %}
{{ log(log_debug, info=True) }}
{% endif %}
{% endmacro %}```
and my second macro to run a query is:
{% macro get_affected_rows(query) %}
{% set sql = adapter.quote_as_config(query) %}
{% set result = run_query(sql) %}
{% set affected_rows = result.num_rows_affected %}
{{ return(affected_rows) }}
{% endmacro %}```
Thanks @Surya ! I have success using a call statement. I’ll leave it here on record. My database is BigQuery:
{%- call statement ('atualiza_teste',fetch_result=true) -%}
update mydataset.mytable set valor = "mudou" where 1=1;
{%- endcall -%}
{%- set states = load_result('atualiza_teste') -%}
{{ log(states['response'].rows_affected,info=true) }}