# getting metadata at runtime in macro

**URL:** <https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447>\
**Category:** Help\
**Tags:** macro\
**Created:** [November 30, 2022, 9:54am UTC](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447 "2022-11-30T09:54:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![obar1](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/obar1/32/1221_2.png) [@obar1](https://discourse.getdbt.com/u/obar1)\
**Post date:** [November 30, 2022, 9:54am UTC](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447/1 "2022-11-30T09:54:07Z")

</div>

Hello ppl -  
I have this case

```auto
model1 
{{ config(materialized="table", schema="clean") }}

model2
{{ config(materialized="table", schema="stg") }}

```

then

```auto
{%- macro round_percentage(col) -%}
    ROUND( {{ col }},3)
{%- endmacro -%}

```

use by model1 or 2 etc  
can I make round\_percentage able to recognise in which schema is running and and behave in accordance

```auto
{%- macro round_percentage(col) -%}
if schema = clean
    ROUND( {{ col }},3)
if schema = stg
    ROUND( {{ col }},6)
{%- endmacro -%}

```

---

<div class="post-metadata">

**Author:** ![obar1](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/obar1/32/1221_2.png) [@obar1](https://discourse.getdbt.com/u/obar1)\
**Post date:** [November 30, 2022, 9:55am UTC](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447/2 "2022-11-30T09:55:10Z")

</div>

I would like to do without passing extra paramas to macro call ofc

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [December 1, 2022, 2:10am UTC](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447/3 "2022-12-01T02:10:48Z")

</div>

Off the top of my head, `target.schema` will probably do this? Otherwise `{{ model.config.schema }}` (see [model | dbt Developer Hub](https://docs.getdbt.com/reference/dbt-jinja-functions/model) and [graph | dbt Developer Hub](https://docs.getdbt.com/reference/dbt-jinja-functions/graph#accessing-models)).

If you use the `model` variable, take careful note of the warnings on the graph documentation - the data inside of it is unreliable during the initial parse (when `execute=false`)
