Skip to content

Instantly share code, notes, and snippets.

@jtcohen6
Last active June 7, 2024 20:30
Show Gist options
  • Save jtcohen6/2426ec9614828b09bc67ee7a83423517 to your computer and use it in GitHub Desktop.
Save jtcohen6/2426ec9614828b09bc67ee7a83423517 to your computer and use it in GitHub Desktop.
{% macro my_custom_dispatched_macro() %}
{{ adapter.dispatch('my_custom_dispatched_macro')() }}
{% endmacro %}
{% macro postgres__my_custom_dispatched_macro() %}
{{ return() }}
{% endmacro %}
{% macro default__my_custom_dispatched_macro() %}
{{ exceptions.raise_compiler_error("I was expecting to use the Postgres version") }}
{% endmacro %}
-- {{ my_custom_dispatched_macro() }}
select 1 as id

Running dbt-redshift@main:

$ dbt run
20:26:38  Running with dbt=1.9.0-a1
20:26:39  Registered adapter: redshift=1.9.0-a1
20:26:39  Unable to do partial parsing because profile has changed
20:26:39  Unable to do partial parsing because a project dependency has been added
20:26:39  Unable to do partial parsing because a project config has changed
20:26:40  Found 1 model, 482 macros
20:26:40
20:26:49  Concurrency: 1 threads (target='dev')
20:26:49
20:26:49  1 of 1 START sql view model dbt_jcohen.my_model ................................ [RUN]
20:26:54  1 of 1 OK created sql view model dbt_jcohen.my_model ........................... [SUCCESS in 5.06s]
20:26:56
20:26:56  Finished running 1 view model in 0 hours 0 minutes and 16.13 seconds (16.13s).
20:26:56
20:26:56  Completed successfully
20:26:56
20:26:56  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1

Running dbt-redshift@remove-dbt-postgres-dependency:

(env) 22:26:57 ~/dev/scratch/testy $ dbt run
20:27:07  Running with dbt=1.9.0-a1
20:27:07  Registered adapter: redshift=1.9.0-a1
20:27:08  Encountered an error:
Compilation Error in model my_model (models/my_model.sql)
  I was expecting to use the Postgres version

  > in macro default__my_custom_dispatched_macro (macros/overrides.sql)
  > called by macro my_custom_dispatched_macro (macros/overrides.sql)
  > called by model my_model (models/my_model.sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment