# How to specify target schema for udfs?

**URL:** <https://discourse.getdbt.com/t/how-to-specify-target-schema-for-udfs/1294>\
**Category:** Help\
**Tags:** udf\
**Created:** [June 19, 2020, 2:52am UTC](https://discourse.getdbt.com/t/how-to-specify-target-schema-for-udfs/1294 "2020-06-19T02:52:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_unsw](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@alex\_unsw](https://discourse.getdbt.com/u/alex_unsw)\
**Post date:** [June 19, 2020, 2:52am UTC](https://discourse.getdbt.com/t/how-to-specify-target-schema-for-udfs/1294/1 "2020-06-19T02:52:16Z")

</div>

Hi all,

I started implementing the approach illustrated in this [post](https://discourse.getdbt.com/t/using-dbt-to-manage-user-defined-functions-redshift/18) for BigQuery.

```sql
-- macros/udfs/file_name.sql
{% set schema = 'schema_name' %}

{% macro macro_name() %}
CREATE OR REPLACE FUNCTION {{target.schema}}.function_name(input STRING) 
RETURNS 
...

```

I was hoping the schema variable defined at the top could be passed into `{{ target.schema}}` block, but it seem didn’t work as expected (no function created in my target schema).

Two questions here:

- How to set target schema for udf macro like how we did for model config?
- Does compiled macro go into somewhere like `target/`?

---

<div class="post-metadata">

**Author:** ![alex\_unsw](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@alex\_unsw](https://discourse.getdbt.com/u/alex_unsw)\
**Post date:** [June 26, 2020, 1:30am UTC](https://discourse.getdbt.com/t/how-to-specify-target-schema-for-udfs/1294/2 "2020-06-26T01:30:17Z")

</div>

As @claire replied in this [thread](https://discourse.getdbt.com/t/using-dbt-to-manage-user-defined-functions/18/13)

After surrounding macro name with `run_query` block like this

```auto
{% macro create_udfs() %}
...
{% do run_query(fn_metadata_header()) %}
...
{% endmacro %}

```

The macro is successfully executed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [September 13, 2022, 3:53am UTC](https://discourse.getdbt.com/t/how-to-specify-target-schema-for-udfs/1294/3 "2022-09-13T03:53:45Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
