The problem I’m having
As a test I’ve copied an existing incremental materialisation from github:
https://github.com/dbt-labs/dbt-adapters/blob/main/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql
to the macros folder in my dbt project.
I’ve Renamed the materialisation from incremental to incrementalx
{% materialization incremental, default -%}
to:
{% materialization incrementalx, default -%}
And used this in a model that is set to use incremental materialisation in the model’s config block:
{{
config(
materialized=“incrementalx”,
…
Model structure:
{% if is_incremental() %}
“incremental select”
{% else %}
“inital load select”
{% endif %}
The standard incremental materialisation worked fine, the incrementalx materialisation (only a copy from git and a rename) did not, for some reason it used the select statement that was inside the
else part (so the initial load part) and used this as a basis for the merge (and that failed).
When switching the materialisation back from incrementalx to incremental the correct incremental select was used and the merge statement completed as expected.
The context of why I’m trying to do this
In order to create a custom incremental strategy whilst not altering existing functionality.
What I’ve already tried
Described above, i wanted to make sure that everything worked as expected, i wanted to use the existing materialisation as a base (since that works and i only need a small tweak)
Some example code or error messages
Described above, the incorrect select statement was used as a tmp table.
Put code inside backticks
to preserve indentation
which is especially important
for Python and YAML!