# Macro triggering order

**URL:** <https://discourse.getdbt.com/t/macro-triggering-order/3065>\
**Category:** Archive\
**Created:** [September 16, 2021, 7:11pm UTC](https://discourse.getdbt.com/t/macro-triggering-order/3065 "2021-09-16T19:11:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discourse.getdbt.com/u/gayathri)\
**Post date:** [September 16, 2021, 7:11pm UTC](https://discourse.getdbt.com/t/macro-triggering-order/3065/1 "2021-09-16T19:11:44Z")

</div>

All,

In my project we build a model and update the max(created\_date) into another table where we record all running times and dates. I followed the following steps -

1. Build model (select statement for table\_1)
2. In the config section of the model specify a macro for post\_hook
3. In the macro, insert into table\_2.

My `dbt compile` failed as it checked the macro and complained table\_1 didn’t exist.  
So, I looked up the documentation and used

```auto
{%- set source_relation = adapter.get_relation(
        database=obj.database ,
        schema=obj.schema,
        identifier=obj.name) -%}

    {% set table_exists=source_relation is not none %}

    {% if table_exists %}

```

This did away with the error, but I realised that the initial run never inserts into table\_2. Only the subsequent runs seem to bring records into this table.

My assumption was `CREATE TABLE` is a `DDL` and the `post_hook` triggers after it so finding the object in the db should be ok.  
However, looking into the logs I realised the macro was being fired before the create table.  
Can someone point out what I am missing? Is there a macro triggering order reference for dbt?

Thanks
