dbt-labs / dbt-codegen

Macros that generate dbt code
https://hub.getdbt.com/dbt-labs/codegen/latest/
Apache License 2.0
459 stars 99 forks source link

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

Closed dbeatty10 closed 1 month ago

dbeatty10 commented 7 months ago

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?

github-actions[bot] commented 1 month ago

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

github-actions[bot] commented 1 month ago

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.