1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How output single quote in dbt post hook macros with jinja?

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 10:02.

  1. Stack

    Stack Membro Participativo

    Here is post hook for dbt model:

    {{
    config(
    post_hook=[
    '{{ execute_if_exists("delete from " ~ this ~ " where day = date('' " ~ var("mydatevar") ~ " '')") }}',
    ]
    )
    }}


    Please note the '' in the string. Next:

    {% macro execute_if_exists(query) -%}
    {{ query }}
    {%- endmacro %}


    And I got

    delete from catalog.myschema.mytable where day = date( 2024-10-02 )


    While expected is:

    delete from catalog.myschema.mytable where day = date(' 2024-10-02 ')


    I have tried \' and got error. I have switched " and ' again no effect.

    UPDATED

    1. '{{ execute_if_exists("delete from " ~ this ~ " where day = date(' " ~ var("mydatevar") ~ " ')") }} - compilation error
    2. "{{ execute_if_exists('delete from ' ~ this ~ ' where day = date(' ' ~ var('mydatevar') ~ ' ')') }}" - same effect
    3. "{{ execute_if_exists('delete from ' ~ this ~ ' where day = date(' ' ~ var('mydatevar') ~ ' ')') }}" - also compilation error

    Continue reading...

Compartilhe esta Página