# Dbt macro: create external table in bigquery

**URL:** <https://discourse.getdbt.com/t/dbt-macro-create-external-table-in-bigquery/7879>\
**Category:** In-Depth Discussions\
**Tags:** jinja, bigquery, macros\
**Created:** [April 17, 2023, 1:13pm UTC](https://discourse.getdbt.com/t/dbt-macro-create-external-table-in-bigquery/7879 "2023-04-17T13:13:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tahseen0354](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/tahseen0354/32/2600_2.png) [@Tahseen0354](https://discourse.getdbt.com/u/Tahseen0354)\
**Post date:** [April 17, 2023, 1:13pm UTC](https://discourse.getdbt.com/t/dbt-macro-create-external-table-in-bigquery/7879/1 "2023-04-17T13:13:34Z")

</div>

Hi, I am trying to execute the macro below to create external table in bigquery.

```auto
{%- macro create_external_table() -%}
    create or replace external table `dataset.table`(
        Id STRING NOT NULL,
        FirstName STRING NOT NULL,
        LastName STRING NOT NULL
    )
    OPTIONS(
        format = "CSV",
        uris = ['gs://some_folder/my_file.csv'] 
    );
{%- endmacro -%}

```

When I run `dbt run-operation create_external_table`, it does not create the table in bigquery. But then I have modified my macro like below:

```auto
{%- macro create_external_table() -%}
 {% set create_table %}
  create or replace external table `dataset.table`(
      Id STRING NOT NULL,
      FirstName STRING NOT NULL,
      LastName STRING NOT NULL
  )
  OPTIONS(
      format = "CSV",
      uris = ['gs://some_folder/my_file.csv'] 
  );
  {% endset %}

  {% do run_query(create_table) %}
{%- endmacro -%}

```

Now it works and it is creating the table in bigquery. I would like to know why the first code did not work and why the second one worked. Thanks!

---

<div class="post-metadata">

**Author:** ![red](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@red](https://discourse.getdbt.com/u/red)\
**Post date:** [July 16, 2024, 8:58am UTC](https://discourse.getdbt.com/t/dbt-macro-create-external-table-in-bigquery/7879/2 "2024-07-16T08:58:26Z")

</div>

> [@Tahseen0354](#):
>
> dbt run-operation create\_external\_table

because you created the macro but you did not execute it , you did not run it via run\_query
