# How to control dbt model's column datatype?

**URL:** <https://discourse.getdbt.com/t/how-to-control-dbt-models-column-datatype/13782>\
**Category:** Help\
**Tags:** snowflake, dbt-core\
**Created:** [June 12, 2024, 7:51am UTC](https://discourse.getdbt.com/t/how-to-control-dbt-models-column-datatype/13782 "2024-06-12T07:51:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![irfan](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@irfan](https://discourse.getdbt.com/u/irfan)\
**Post date:** [June 12, 2024, 7:51am UTC](https://discourse.getdbt.com/t/how-to-control-dbt-models-column-datatype/13782/1 "2024-06-12T07:51:09Z")

</div>

## Problem

We are in the process of migrating the transformation logic written in stored procedures to dbt. One of the challenges that we have already identified as part of migration is the dbt model’s column datatype not matching with the one currently being transformed through stored procedure. In stored procedures, we are just transforming the data whereas the schema of any table is defined upfront by the database admins. But I believe when we shift to dbt, the schema of a dbt model is controlled within dbt itself since it re-creates the table (everytime or during full-refreshes depending on the materialization) with the datatypes based on the data returned by the model query.

## Example

For example, one of the column datatype is `NUMBER(38,0)` originally. When migrated to dbt, the same column datatype is `NUMBER(18,5)`. For now, we have done explicit datatype casting in the model sql. But this seems to be too much of effort when we take into consideration many of the tables have such issues.

Are there any better alternatives to have control over column datatypes and the overall schema of a model in dbt?

---

<div class="post-metadata">

**Author:** ![brunoszdl](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/brunoszdl/32/4113_2.png) [@brunoszdl](https://discourse.getdbt.com/u/brunoszdl)\
**Post date:** [June 12, 2024, 2:28pm UTC](https://discourse.getdbt.com/t/how-to-control-dbt-models-column-datatype/13782/2 "2024-06-12T14:28:44Z")

</div>

You could try using contracts with data types [contract | dbt Developer Hub](https://docs.getdbt.com/reference/resource-configs/contract)

But now I am not sure if it will cast your column to the right type, or just tell you if it matches the defined data type. Anyway, I would give it a try
