# \#macros

**URL:** https://discourse.getdbt.com/tag/macros/89.md

[Latest](https://discourse.getdbt.com/latest.md) · [Categories](https://discourse.getdbt.com/categories.md) · [Tags](https://discourse.getdbt.com/tags.md)

---

## [I want to Redact Names in my feedback column how can i achieve this in DBT Macro?](https://discourse.getdbt.com/t/i-want-to-redact-names-in-my-feedback-column-how-can-i-achieve-this-in-dbt-macro/20882)

<div class="topic-metadata">

**Author:** [@SAIKARTHIK](https://discourse.getdbt.com/u/SAIKARTHIK)\
**Replies:** 0\
**Last updated:** [July 23, 2026, 10:52am UTC](https://discourse.getdbt.com/t/i-want-to-redact-names-in-my-feedback-column-how-can-i-achieve-this-in-dbt-macro/20882 "2026-07-23T10:52:18Z")

</div>

The problem I’m having: I want to Redact Names in my feedback column how can i achieve this in dbt Macro? The context of why I’m trying to do this: to redact the PII data like user names What I’ve already tried: tried …

---

## [Resolving source data county name mismatches against a reference table using a seed override table and a normalized join key](https://discourse.getdbt.com/t/resolving-source-data-county-name-mismatches-against-a-reference-table-using-a-seed-override-table-and-a-normalized-join-key/20863)

<div class="topic-metadata">

**Author:** [@Kayla](https://discourse.getdbt.com/u/Kayla)\
**Replies:** 0\
**Last updated:** [July 10, 2026, 9:24pm UTC](https://discourse.getdbt.com/t/resolving-source-data-county-name-mismatches-against-a-reference-table-using-a-seed-override-table-and-a-normalized-join-key/20863 "2026-07-10T21:24:12Z")

</div>

The problem Joining CMS hospital data to a FIPS county reference table should be straightforward — until you discover that CMS county names diverge from the standardized reference in ways that are too numerous and too c…

---

## [using doc macro in yml file is not executed on macro](https://discourse.getdbt.com/t/using-doc-macro-in-yml-file-is-not-executed-on-macro/20620)

<div class="topic-metadata">

**Author:** [@msaeli](https://discourse.getdbt.com/u/msaeli)\
**Replies:** 9\
**Last updated:** [March 11, 2026, 8:16am UTC](https://discourse.getdbt.com/t/using-doc-macro-in-yml-file-is-not-executed-on-macro/20620 "2026-03-11T08:16:06Z")

</div>

The problem I’m having I am using the doc macro in my YML file. I need to use the column definition (retrieve the doc() result) into a custom macro, but the doc is undefined. The context of why I’m trying to do this I …

---

## [Have you struggled recreating salesforce formula from fivetran in Snowflake ?](https://discourse.getdbt.com/t/have-you-struggled-recreating-salesforce-formula-from-fivetran-in-snowflake/20581)

<div class="topic-metadata">

**Author:** [@munmridul](https://discourse.getdbt.com/u/munmridul)\
**Replies:** 0\
**Last updated:** [February 13, 2026, 3:32pm UTC](https://discourse.getdbt.com/t/have-you-struggled-recreating-salesforce-formula-from-fivetran-in-snowflake/20581 "2026-02-13T15:32:18Z")

</div>

Introducing the new package that you can use to materialize formula and rollup summary fields from Salesforce using Fivetran. Although Fivetran offers their own dbt package for it, my solution is pretty much simpler and …

---

## [Macro called in post hook does not use the correct schema](https://discourse.getdbt.com/t/macro-called-in-post-hook-does-not-use-the-correct-schema/20421)

<div class="topic-metadata">

**Author:** [@WorkWork](https://discourse.getdbt.com/u/WorkWork)\
**Replies:** 0\
**Last updated:** [November 13, 2025, 7:07pm UTC](https://discourse.getdbt.com/t/macro-called-in-post-hook-does-not-use-the-correct-schema/20421 "2025-11-13T19:07:43Z")

</div>

The problem I’m having Calling a macro in a posthook does not return the correct schema. For some reason in the posthook the schema being used is the default one instead of the custom one defined in the dbt\_project.yml f…

---

## [dbt Mesh training - show data types macro not working](https://discourse.getdbt.com/t/dbt-mesh-training-show-data-types-macro-not-working/20409)

<div class="topic-metadata">

**Author:** [@FreeRangeDingo](https://discourse.getdbt.com/u/FreeRangeDingo)\
**Replies:** 0\
**Last updated:** [November 6, 2025, 11:19pm UTC](https://discourse.getdbt.com/t/dbt-mesh-training-show-data-types-macro-not-working/20409 "2025-11-06T23:19:14Z")

</div>

The problem I’m having I am doing the dbt Mesh training on dbt Learn. In the section on model contracts, a macro is provided to show you the data types in a give model. I have put this macro into a new file and replaced …

---

## [target db/schema and profile is hidden or uncomprehending](https://discourse.getdbt.com/t/target-db-schema-and-profile-is-hidden-or-uncomprehending/20218)

<div class="topic-metadata">

**Author:** [@Fhashmi](https://discourse.getdbt.com/u/Fhashmi)\
**Replies:** 0\
**Last updated:** [September 9, 2025, 11:39pm UTC](https://discourse.getdbt.com/t/target-db-schema-and-profile-is-hidden-or-uncomprehending/20218 "2025-09-09T23:39:34Z")

</div>

The problem I’m having can be explained by the attached screenshots. The profile in the dbt\_project.yml is default. While there is a macro that decides which DB and schema is chosen for building the objects in. The pro…

---

## [Call macro within another macro](https://discourse.getdbt.com/t/call-macro-within-another-macro/12976)

<div class="topic-metadata">

**Author:** [@needlearn](https://discourse.getdbt.com/u/needlearn)\
**Replies:** 1\
**Last updated:** [July 31, 2025, 12:43pm UTC](https://discourse.getdbt.com/t/call-macro-within-another-macro/12976 "2025-07-31T12:43:52Z")

</div>

Need to pass the value from a DB query in one macro and call this first macro inside another macro to pass the values dynamically. Trying to read values from a databricks table through macro1 and passing them in source y…

---

## [Rendering Macro within Macro](https://discourse.getdbt.com/t/rendering-macro-within-macro/20001)

<div class="topic-metadata">

**Author:** [@Priest](https://discourse.getdbt.com/u/Priest)\
**Replies:** 0\
**Last updated:** [July 31, 2025, 12:41pm UTC](https://discourse.getdbt.com/t/rendering-macro-within-macro/20001 "2025-07-31T12:41:30Z")

</div>

The problem I’m having Hi, I’m trying to dynamically build the columns in the “SELECT” query utilizing a customer macro and the model’s YML file. And I’m getting ‘macro’ undefined error. The context of why I’m trying…

---

## [Unit testing a macro with separate models](https://discourse.getdbt.com/t/unit-testing-a-macro-with-separate-models/19975)

<div class="topic-metadata">

**Author:** [@cmartin28](https://discourse.getdbt.com/u/cmartin28)\
**Replies:** 0\
**Last updated:** [July 29, 2025, 9:19am UTC](https://discourse.getdbt.com/t/unit-testing-a-macro-with-separate-models/19975 "2025-07-29T09:19:25Z")

</div>

Hello, I have a macro called age\_binning that is essentially a CASE statement that looks like this # age\_binning.sql {%- macro age\_binning(age\_column) -%} case when {{ age\_column }} between 10 and 19 then …

---

## [Preventing run\_query Execution During Compilation](https://discourse.getdbt.com/t/preventing-run-query-execution-during-compilation/19887)

<div class="topic-metadata">

**Author:** [@mfog](https://discourse.getdbt.com/u/mfog)\
**Replies:** 1\
**Last updated:** [July 18, 2025, 4:04pm UTC](https://discourse.getdbt.com/t/preventing-run-query-execution-during-compilation/19887 "2025-07-18T16:04:47Z")

</div>

Dynamically generate view query I’m trying to dynamically generate the columns of a dbt view, let’s call it DYNAMIC\_VIEW, by querying another table, VIEW\_FIELDS. The goal is to have a macro, get\_fields, that gets invoke…

---

## [output the failing test query](https://discourse.getdbt.com/t/output-the-failing-test-query/12180)

<div class="topic-metadata">

**Author:** [@mganop](https://discourse.getdbt.com/u/mganop)\
**Replies:** 1\
**Last updated:** [June 12, 2025, 4:10pm UTC](https://discourse.getdbt.com/t/output-the-failing-test-query/12180 "2025-06-12T16:10:29Z")

</div>

The problem I’m having I am running a test on a model that checks for the existance of certain data in a join with other tables ; if the any rows are returned, the test fails. I want to see the results of the rows that a…

---

## [How to use the comments/descriptions in schema file into the database](https://discourse.getdbt.com/t/how-to-use-the-comments-descriptions-in-schema-file-into-the-database/19295)

<div class="topic-metadata">

**Author:** [@xpegenaute](https://discourse.getdbt.com/u/xpegenaute)\
**Replies:** 2\
**Last updated:** [June 11, 2025, 6:48pm UTC](https://discourse.getdbt.com/t/how-to-use-the-comments-descriptions-in-schema-file-into-the-database/19295 "2025-06-11T18:48:43Z")

</div>

The problem I’m having I have defined some table and columns descriptions as stated in the documentation. It properly generates the documentation with dbt docs generate. But I would like that when I run the model, when t…

---

## [Saving compiled macro to be run afterwards to avoid nested jinja](https://discourse.getdbt.com/t/saving-compiled-macro-to-be-run-afterwards-to-avoid-nested-jinja/19378)

<div class="topic-metadata">

**Author:** [@ungvaritomi](https://discourse.getdbt.com/u/ungvaritomi)\
**Replies:** 1\
**Last updated:** [May 14, 2025, 1:43pm UTC](https://discourse.getdbt.com/t/saving-compiled-macro-to-be-run-afterwards-to-avoid-nested-jinja/19378 "2025-05-14T13:43:58Z")

</div>

The problem I’m having I’m trying to create a macro that creates CTE’s inside based on the number of seed files it finds with a specific pattern in their name while using ref function to have lineage. If I try to do this…

---

## [Customizing an adapter - persist\_docs - comments on tables/columns](https://discourse.getdbt.com/t/customizing-an-adapter-persist-docs-comments-on-tables-columns/19344)

<div class="topic-metadata">

**Author:** [@xpegenaute](https://discourse.getdbt.com/u/xpegenaute)\
**Replies:** 1\
**Last updated:** [May 13, 2025, 10:25am UTC](https://discourse.getdbt.com/t/customizing-an-adapter-persist-docs-comments-on-tables-columns/19344 "2025-05-13T10:25:47Z")

</div>

The problem I’m having My updates on the persist\_docs macros are not executed. The context of why I’m trying to do this I am using the Vertica Adapter with this commit. What I’ve already tried I tried the execution of …

---

## [How to read model columns in sql](https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157)

<div class="topic-metadata">

**Author:** [@seeker](https://discourse.getdbt.com/u/seeker)\
**Replies:** 1\
**Last updated:** [April 25, 2025, 10:13pm UTC](https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157 "2025-04-25T22:13:41Z")

</div>

The problem I’m having I need to create a incremental model which queries itself. In this case I can utilize the is\_incremental() to point to itself with {{ this }} if it the table is not created yet or for full-refres…

---

## [dbt-external-tables FAILS interacting with Snowflake](https://discourse.getdbt.com/t/dbt-external-tables-fails-interacting-with-snowflake/19046)

<div class="topic-metadata">

**Author:** [@aleppek](https://discourse.getdbt.com/u/aleppek)\
**Replies:** 18\
**Last updated:** [April 17, 2025, 12:23am UTC](https://discourse.getdbt.com/t/dbt-external-tables-fails-interacting-with-snowflake/19046 "2025-04-17T00:23:21Z")

</div>

I’m trying to use the dbt-external-tables package with my Snowflake account, through dbt Cloud. This should create raw tables for me, using S3 as the source. Below is my source configuration: version: 2 sources: - na…

---

## [dbt-snowflake adapter 1.7.0 & 1.8.4 have different macro behaviour for Dynamic Tables.](https://discourse.getdbt.com/t/dbt-snowflake-adapter-1-7-0-1-8-4-have-different-macro-behaviour-for-dynamic-tables/19027)

<div class="topic-metadata">

**Author:** [@JJJJJ](https://discourse.getdbt.com/u/JJJJJ)\
**Replies:** 0\
**Last updated:** [April 15, 2025, 3:31am UTC](https://discourse.getdbt.com/t/dbt-snowflake-adapter-1-7-0-1-8-4-have-different-macro-behaviour-for-dynamic-tables/19027 "2025-04-15T03:31:28Z")

</div>

The problem I’m having dbt-snowflake adapter 1.7.0 & 1.8.4 have different behaviour for Dynamic Tables. In 1.7.0, when running dbt run -s \<dynamic-table\>, it is trying to Applying REPLACE → DROP → CREATE; While in 1.8.…

---

## [Macro to create Redshfit stored proc failing when run with on-run-start hook](https://discourse.getdbt.com/t/macro-to-create-redshfit-stored-proc-failing-when-run-with-on-run-start-hook/18937)

<div class="topic-metadata">

**Author:** [@zbrown](https://discourse.getdbt.com/u/zbrown)\
**Replies:** 1\
**Last updated:** [April 6, 2025, 9:38am UTC](https://discourse.getdbt.com/t/macro-to-create-redshfit-stored-proc-failing-when-run-with-on-run-start-hook/18937 "2025-04-06T09:38:20Z")

</div>

The problem I’m having We’ve got a few User Defined Functions and Stored Procedures in Redshift that I’m trying to check into our dbt repo (as detailed here: Using dbt to manage user defined functions). When I run my mac…

---

## [configurable data cleaning rules](https://discourse.getdbt.com/t/configurable-data-cleaning-rules/18793)

<div class="topic-metadata">

**Author:** [@Wen](https://discourse.getdbt.com/u/Wen)\
**Replies:** 0\
**Last updated:** [March 25, 2025, 1:54pm UTC](https://discourse.getdbt.com/t/configurable-data-cleaning-rules/18793 "2025-03-25T13:54:13Z")

</div>

The problem I’m having Hi, in our team we handle a lot of data sources from external vendors, and we experience a lot of data issues like the end start is smaller than the start date. Sometimes it is slow to wait for ext…

---

## [dbt core - snowflake - Running pre hook to capture query table before running dbt test](https://discourse.getdbt.com/t/dbt-core-snowflake-running-pre-hook-to-capture-query-table-before-running-dbt-test/18751)

<div class="topic-metadata">

**Author:** [@gnirs](https://discourse.getdbt.com/u/gnirs)\
**Replies:** 0\
**Last updated:** [March 22, 2025, 3:04am UTC](https://discourse.getdbt.com/t/dbt-core-snowflake-running-pre-hook-to-capture-query-table-before-running-dbt-test/18751 "2025-03-22T03:04:36Z")

</div>

Running Snowflake models and tests in dbt-core Have a pre-hook macro generate\_query\_tags to add query\_tags in Snowflake containing DAG ID and Run ID. dbt\_projects.yml contents: name: “financials” version: “1.0.0” co…

---

## [How to declare the while loop and then to use that loop in different models, does it used in macro, kindly provide with an example](https://discourse.getdbt.com/t/how-to-declare-the-while-loop-and-then-to-use-that-loop-in-different-models-does-it-used-in-macro-kindly-provide-with-an-example/18536)

<div class="topic-metadata">

**Author:** [@jagadeesh9](https://discourse.getdbt.com/u/jagadeesh9)\
**Replies:** 3\
**Last updated:** [March 13, 2025, 11:28pm UTC](https://discourse.getdbt.com/t/how-to-declare-the-while-loop-and-then-to-use-that-loop-in-different-models-does-it-used-in-macro-kindly-provide-with-an-example/18536 "2025-03-13T23:28:29Z")

</div>

How to declare the while loop and then to use that loop in different models, does it used in macro, kindly provide with an example?

---

## [Having different value for 'THIS' variable when passing to macro using Post hook](https://discourse.getdbt.com/t/having-different-value-for-this-variable-when-passing-to-macro-using-post-hook/18534)

<div class="topic-metadata">

**Author:** [@Ayush](https://discourse.getdbt.com/u/Ayush)\
**Replies:** 0\
**Last updated:** [March 7, 2025, 7:05am UTC](https://discourse.getdbt.com/t/having-different-value-for-this-variable-when-passing-to-macro-using-post-hook/18534 "2025-03-07T07:05:19Z")

</div>

The problem I’m having Hi, I am having a question regarding the 'this ’ variable value actually when i passed the this variable to macro using post hook it is given different schema name which is mentioned in profiles.ym…

---

## [How to customize macros in dbt packages within the CodeGen](https://discourse.getdbt.com/t/how-to-customize-macros-in-dbt-packages-within-the-codegen/18455)

<div class="topic-metadata">

**Author:** [@habtamu.demissie](https://discourse.getdbt.com/u/habtamu.demissie)\
**Replies:** 1\
**Last updated:** [March 3, 2025, 5:01pm UTC](https://discourse.getdbt.com/t/how-to-customize-macros-in-dbt-packages-within-the-codegen/18455 "2025-03-03T17:01:29Z")

</div>

---

## [Using Delta Live Tables Sink as a Custom Materialization in dbt](https://discourse.getdbt.com/t/using-delta-live-tables-sink-as-a-custom-materialization-in-dbt/18436)

<div class="topic-metadata">

**Author:** [@Schuetzi](https://discourse.getdbt.com/u/Schuetzi)\
**Replies:** 0\
**Last updated:** [February 27, 2025, 10:20am UTC](https://discourse.getdbt.com/t/using-delta-live-tables-sink-as-a-custom-materialization-in-dbt/18436 "2025-02-27T10:20:18Z")

</div>

We are using Databricks and would like to implement all data transformations—both streaming and batch—entirely within dbt. Currently, dbt supports Streaming Tables in Databricks, which internally create Delta Live Table…

---

## [Diacritic Characters in Macro](https://discourse.getdbt.com/t/diacritic-characters-in-macro/18419)

<div class="topic-metadata">

**Author:** [@psha](https://discourse.getdbt.com/u/psha)\
**Replies:** 0\
**Last updated:** [February 26, 2025, 9:14am UTC](https://discourse.getdbt.com/t/diacritic-characters-in-macro/18419 "2025-02-26T09:14:01Z")

</div>

The problem I’m having I have a snowflake function that I’m trying to convert to a dbt macro. I don’t think dbt has the capability to do it. I want to have the functionality inside dbt and not calling a function within …

---

## [Calling DBT tests like a macro (plus unit tests for data tests)](https://discourse.getdbt.com/t/calling-dbt-tests-like-a-macro-plus-unit-tests-for-data-tests/18356)

<div class="topic-metadata">

**Author:** [@mroy](https://discourse.getdbt.com/u/mroy)\
**Replies:** 2\
**Last updated:** [February 22, 2025, 2:58am UTC](https://discourse.getdbt.com/t/calling-dbt-tests-like-a-macro-plus-unit-tests-for-data-tests/18356 "2025-02-22T02:58:26Z")

</div>

Note: there is an existing thread here, but it has no resolution other than using dbt build (and it is now closed). Solution Edit: The solution is very simple… just scroll to the bottom to see it. The problem I’m havin…

---

## [Access a list of all defined variables in dbt\_project.yml](https://discourse.getdbt.com/t/access-a-list-of-all-defined-variables-in-dbt-project-yml/18297)

<div class="topic-metadata">

**Author:** [@markus](https://discourse.getdbt.com/u/markus)\
**Replies:** 0\
**Last updated:** [February 19, 2025, 4:18pm UTC](https://discourse.getdbt.com/t/access-a-list-of-all-defined-variables-in-dbt-project-yml/18297 "2025-02-19T16:18:29Z")

</div>

Hi dbt-Community, I want to extract a list of all user defined variables from the dbt-project.yml so that I can iterate over them in a loop. The names of the variables are not known to me in advance. I have read the do…

---

## [Do all columns in target have to be in the model](https://discourse.getdbt.com/t/do-all-columns-in-target-have-to-be-in-the-model/17995)

<div class="topic-metadata">

**Author:** [@LiterallyJustAGirl](https://discourse.getdbt.com/u/LiterallyJustAGirl)\
**Replies:** 4\
**Last updated:** [February 3, 2025, 10:21am UTC](https://discourse.getdbt.com/t/do-all-columns-in-target-have-to-be-in-the-model/17995 "2025-02-03T10:21:32Z")

</div>

My model does not contain all the rows that are in my target table, and when i try running it it fails with an unrecognised name error I am trying to make it so that my model runs and populates only the columns in the m…

---

## [dbt cannot resolve my custom macro inside my custom dbt package when using dispatch](https://discourse.getdbt.com/t/dbt-cannot-resolve-my-custom-macro-inside-my-custom-dbt-package-when-using-dispatch/15403)

<div class="topic-metadata">

**Author:** [@opkzcn](https://discourse.getdbt.com/u/opkzcn)\
**Replies:** 1\
**Last updated:** [January 8, 2025, 12:43pm UTC](https://discourse.getdbt.com/t/dbt-cannot-resolve-my-custom-macro-inside-my-custom-dbt-package-when-using-dispatch/15403 "2025-01-08T12:43:57Z")

</div>

The problem I’m having Cannot resolve the macro inside my custom dbt package when using dispatch in root dbt\_project.yml. I loaded the custom dbt package using dbt deps command. I am using dbt-sqlserver The context of w…

[Next page](https://discourse.getdbt.com/tag/macros/89.md?match_all_tags=true&page=1&tags%5B%5D=macros)
