# How to read model columns in sql

**URL:** <https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157>\
**Category:** Help\
**Tags:** jinja, macros\
**Created:** [April 25, 2025, 8:53pm UTC](https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157 "2025-04-25T20:53:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeker](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@seeker](https://discourse.getdbt.com/u/seeker)\
**Post date:** [April 25, 2025, 8:53pm UTC](https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157/1 "2025-04-25T20:53:55Z")

</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-refresh.  
Example:

```auto
, cteX as (
{% if is_incremental() %}
select
     *,
  from {{ this }} join ...
  where ...
{% else %}
with cte_table as (
  select
       cast(null as id) as int,
       cast(null as name) as string,
       ...
) select * from cte_table where false
{{ endif }}
),

```

Here I don’t want to hardcode all the columns but rather utilize the schema yml with model description on which the column and datatype are already mentioned. How can I do that?

## What I’ve already tried

There is a utility available [`get_filtered_columns_in_relation`](https://docs.getdbt.com/reference/dbt-jinja-functions/adapter#get_columns_in_relation) which queries the table to fetch columns. But I want the columns to be fetched from yml description for that model. Because it will be the first run and the table won’t be available yet.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [April 25, 2025, 10:13pm UTC](https://discourse.getdbt.com/t/how-to-read-model-columns-in-sql/19157/2 "2025-04-25T22:13:41Z")

</div>

in dbt your should start with the query and then move to documentation, especially with AI that will take the types and write your documentation.

Note: `@Nick Pinfold` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1745619211780779?thread_ts=1745614458.404859&cid=CBSQTAPLG). It might not have transferred perfectly.
