Skip to content

Commit

Permalink
feat: implement the concat macro
Browse files Browse the repository at this point in the history
  • Loading branch information
cverhoef committed Dec 13, 2022
1 parent fd5c07b commit de8b2bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ This dbt package contains macros for SQL functions to run the dbt project on mul
- [test_unique_combination_of_columns](#test_unique_combination_of_columns-source)
- [test_unique](#test_unique-source)
- [Generic](#Generic)
- [optional](#optional-source)
- [concat](#concat-source)
- [left_from_char](#left_from_char-source)
- [optional](#optional-source)
- [Process mining tables](#Process-mining-tables)
- [generate_edge_table](#generate_edge_table-source)
- [generate_variant](#generate_variant-source)
Expand Down Expand Up @@ -402,6 +403,15 @@ models:

### Generic

#### concat ([source](macros/generic/concat.sql))
This macro concatenates two or more strings together. In case a value is `null` it is concatenated as the empty string `''`.

Usage:
`{{ pm_utils.concat('"Field_A"', '"Field_B"') }}`

To pass a string as argument, make sure to use double quotes:
`{{ pm_utils.concat('"Field_A"', "' - '", '"Field_B"') }}`

#### left_from_char ([source](macros/generic/left_from_char.sql))
This macro extracts the string left from the character.

Expand Down
12 changes: 12 additions & 0 deletions macros/generic/concat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{%- macro concat() -%}

concat(
{%- for argument in varargs -%}
coalesce({{ argument }}, '')
{%- if not loop.last -%}
,
{%- endif -%}
{%- endfor -%}
)

{%- endmacro -%}

0 comments on commit de8b2bc

Please sign in to comment.