diff --git a/README.md b/README.md index b3c7470..24edbbf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ This dbt package contains macros for SQL functions to run the dbt project on mul - [date_from_timestamp](#date_from_timestamp-source) - [datediff](#datediff-source) - [generate_id](#generate_id-source) + - [id](#id-source) - [min_boolean](#min_boolean-source) - [string_agg](#string_agg-source) - [timestamp_from_date](#timestamp_from_date-source) @@ -103,6 +104,8 @@ Usage: `{{ pm_utils.datediff('[datepart]', '[start_date_expression]', '[end_date_expression]') }}` #### generate_id ([source](macros/multiple_databases/generate_id.sql)) +**Note:** this macro is deprecated and will be removed in a future release. To create an ID, the `id()` macro should be used. + This macro generates an id field for the current model. This macro can only be used in a dbt post-hook. With the argument you specify the name of the id field which can be referenced in next transformations like any other field. Usage: @@ -112,6 +115,12 @@ Usage: ) }} ``` +#### id ([source](macros/multiple_databases/id.sql)) +This macro generates an id field that can be used as a column for the current model. + +Usage: +`{{ pm_utils.id() }}` + #### min_boolean ([source](macros/multiple_databases/min_boolean.sql)) This macro selects the minimum of the records in an aggregate expression for boolean fields. diff --git a/dbt_project.yml b/dbt_project.yml index de91130..e33cb32 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,5 +1,5 @@ name: 'pm_utils' -version: '0.14.5' +version: '0.15.0' config-version: 2 require-dbt-version: [">=1.0.0", "<2.0.0"] diff --git a/macros/multiple_databases/generate_id.sql b/macros/deprecated/generate_id.sql similarity index 100% rename from macros/multiple_databases/generate_id.sql rename to macros/deprecated/generate_id.sql diff --git a/macros/multiple_databases/id.sql b/macros/multiple_databases/id.sql new file mode 100644 index 0000000..32acd93 --- /dev/null +++ b/macros/multiple_databases/id.sql @@ -0,0 +1,5 @@ +{%- macro id() -%} + +row_number() over (order by (select null)) + +{%- endmacro -%}