dbt-codegen icon indicating copy to clipboard operation
dbt-codegen copied to clipboard

How to generate data types that include size, precision, scale, etc.

Open dbeatty10 opened this issue 1 year ago • 0 comments

Describe the feature

Describe and document how to generate data types that include size, precision, and/or scale, like this:

models:
  - name: my_model
    columns:
      - name: id
        data_type: varchar(10)

Here's how to do it:

Create either of both of these macros within your local project:

{% macro default__data_type_format_model(column) %}
    {{ return(column.data_type | lower) }}
{% endmacro %}
{% macro default__data_type_format_source(column) %}
    {{ return(column.data_type | lower) }}
{% endmacro %}

Assuming your project is named my_project, then add the dispatch configuration to dbt_project.yml:

dispatch:
  - macro_namespace: codegen
    search_order: ['my_project', 'codegen']

Describe alternatives you've considered

Leaving this undocumented.

Additional context

This came up in a conversation with @jenna-jordan

Who will this benefit?

Anyone that wants to include precision & scale within their model contracts and doesn't want to add them by hand.

Are you interested in contributing this feature?

dbeatty10 avatar Jan 13 '24 00:01 dbeatty10