From bd90f89baf66292362e4aca4ba63f4c708fb2370 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Wed, 21 Sep 2022 21:09:48 -0600 Subject: [PATCH 1/8] Array macros --- .../cross-database-macros.md | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 8d16e8dfae3..587f19edec8 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -18,6 +18,9 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression ## All functions (alphabetical) - [any_value](#any_value) +- [array_append](#array_append) +- [array_concat](#array_concat) +- [array_construct](#array_construct) - [bool_or](#bool_or) - [cast_bool_to_text](#cast_bool_to_text) - [concat](#concat) @@ -56,6 +59,11 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [except](#except) - [intersect](#intersect) +[**Array functions**](#array-functions) +- [array_append](#array_append) +- [array_concat](#array_concat) +- [array_construct](#array_construct) + [**String functions**](#string-functions) - [concat](#concat) - [hash](#hash) @@ -241,6 +249,83 @@ __Args__: intersect ``` +[**Array functions**](#array-functions) +- [array_append](#array_append) +- [array_concat](#array_concat) +- [array_construct](#array_construct) + +## Array functions + +### array_append +__Args__: + + * `array` (required): The array to append to. + * `new_element` (required): The element to be appended. This element must *match the data type of the existing elements* in the array in order to match Postgres functionality and *not null* to match Bigquery functionality. + +This macro appends an element to the end of an array and returns the appended array. + +**Usage**: + +```sql +{{ array_append("array_column", "element_column") }} +{{ array_append("array_column", "5") }} +{{ array_append("array_column", "'blue'") }} +``` + +**Sample Output (PostgreSQL)**: + +```sql +array_append(array_column, element_column) +array_append(array_column, 5) +array_append(array_column, 'blue') +``` + +### array_concat +__Args__: + + * `array_1` (required): The array to append to. + * `array_2` (required): The array to be appended to `array_1`. This array must match the data type of `array_1` in order to match Postgres functionality. + +This macro returns the concatenation of two arrays. + +**Usage**: + +```sql +{{ array_concat("array_column_1", "array_column_2") }} +``` + +**Sample Output (PostgreSQL)**: + +```sql +array_cat(array_column_1, array_column_2) +``` + +### array_construct +__Args__: + + * `inputs` (optional): The list of array contents. If not provided, this macro will create an empty array. All inputs must be the *same data type* in order to match Postgres functionality and *not null* to match BigQuery functionality. + * `data_type` (optional): Specifies the data type of the constructed array. This is only relevant when creating an empty array (will otherwise use the data type of the inputs). If `inputs` are `data_type` are both not provided, this macro will create an empty array of type integer. + +This macro returns an array constructed from a set of inputs. + +**Usage**: + +```sql +{{ array_construct(["column_1", "column_2", "column_3"]) }} +{{ array_construct([], "integer") }} +{{ array_construct([1, 2, 3, 4]) }} +{{ array_construct(["'blue'", "'green'"]) }} +``` + +**Sample Output (PostgreSQL)**: + +```sql +array[ column_1 , column_2 , column_3 ] +array[]::integer[] +array[ 1 , 2 , 3 , 4 ] +array[ 'blue' , 'green' ] +``` + ## String functions ### concat From 31b558d525b27984d53929d90373704f75001c62 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Wed, 21 Sep 2022 21:11:49 -0600 Subject: [PATCH 2/8] Update database names --- .../reference/dbt-jinja-functions/cross-database-macros.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 587f19edec8..e029c773068 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -260,7 +260,7 @@ intersect __Args__: * `array` (required): The array to append to. - * `new_element` (required): The element to be appended. This element must *match the data type of the existing elements* in the array in order to match Postgres functionality and *not null* to match Bigquery functionality. + * `new_element` (required): The element to be appended. This element must *match the data type of the existing elements* in the array in order to match PostgreSQL functionality and *not null* to match BigQuery functionality. This macro appends an element to the end of an array and returns the appended array. @@ -284,7 +284,7 @@ array_append(array_column, 'blue') __Args__: * `array_1` (required): The array to append to. - * `array_2` (required): The array to be appended to `array_1`. This array must match the data type of `array_1` in order to match Postgres functionality. + * `array_2` (required): The array to be appended to `array_1`. This array must match the data type of `array_1` in order to match PostgreSQL functionality. This macro returns the concatenation of two arrays. @@ -303,7 +303,7 @@ array_cat(array_column_1, array_column_2) ### array_construct __Args__: - * `inputs` (optional): The list of array contents. If not provided, this macro will create an empty array. All inputs must be the *same data type* in order to match Postgres functionality and *not null* to match BigQuery functionality. + * `inputs` (optional): The list of array contents. If not provided, this macro will create an empty array. All inputs must be the *same data type* in order to match PostgreSQL functionality and *not null* to match BigQuery functionality. * `data_type` (optional): Specifies the data type of the constructed array. This is only relevant when creating an empty array (will otherwise use the data type of the inputs). If `inputs` are `data_type` are both not provided, this macro will create an empty array of type integer. This macro returns an array constructed from a set of inputs. From 02c78a5f3652f6617ae22dfe00c89dda05485003 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Wed, 21 Sep 2022 21:18:54 -0600 Subject: [PATCH 3/8] type_boolean macro --- .../cross-database-macros.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index e029c773068..56e8bf2fd57 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -41,6 +41,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [split_part](#split_part) - [string_literal](#string_literal) - [type_bigint](#type_bigint) +- [type_boolean](#type_boolean) - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) @@ -49,6 +50,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression [**Data type functions**](#data-type-functions) - [type_bigint](#type_bigint) +- [type_boolean](#type_boolean) - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) @@ -113,6 +115,25 @@ This macro yields the database-specific data type for a `BIGINT`. bigint ``` +### type_boolean +__Args__: + + * None + +This macro yields the database-specific data type for a `BOOLEAN`. + +**Usage**: + +```sql +{{ type_boolean() }} +``` + +**Sample Output (PostgreSQL)**: + +```sql +BOOLEAN +``` + ### type_float __Args__: From 1b9b2475e1c20ca32e65b5c792f7b670e26591a1 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Wed, 21 Sep 2022 21:31:16 -0600 Subject: [PATCH 4/8] Versioning components --- .../cross-database-macros.md | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 56e8bf2fd57..c48f96050f4 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -18,9 +18,11 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression ## All functions (alphabetical) - [any_value](#any_value) + - [array_append](#array_append) - [array_concat](#array_concat) - [array_construct](#array_construct) + - [bool_or](#bool_or) - [cast_bool_to_text](#cast_bool_to_text) - [concat](#concat) @@ -41,7 +43,9 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [split_part](#split_part) - [string_literal](#string_literal) - [type_bigint](#type_bigint) + - [type_boolean](#type_boolean) + - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) @@ -50,7 +54,9 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression [**Data type functions**](#data-type-functions) - [type_bigint](#type_bigint) + - [type_boolean](#type_boolean) + - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) @@ -61,11 +67,15 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [except](#except) - [intersect](#intersect) + + [**Array functions**](#array-functions) - [array_append](#array_append) - [array_concat](#array_concat) - [array_construct](#array_construct) + + [**String functions**](#string-functions) - [concat](#concat) - [hash](#hash) @@ -115,6 +125,8 @@ This macro yields the database-specific data type for a `BIGINT`. bigint ``` + + ### type_boolean __Args__: @@ -134,6 +146,8 @@ This macro yields the database-specific data type for a `BOOLEAN`. BOOLEAN ``` + + ### type_float __Args__: @@ -270,10 +284,7 @@ __Args__: intersect ``` -[**Array functions**](#array-functions) -- [array_append](#array_append) -- [array_concat](#array_concat) -- [array_construct](#array_construct) + ## Array functions @@ -347,6 +358,8 @@ array[ 1 , 2 , 3 , 4 ] array[ 'blue' , 'green' ] ``` + + ## String functions ### concat From d5ef1713094ec3861b8e176d4d8aa9ec7c1c8b45 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Fri, 23 Sep 2022 14:35:18 -0600 Subject: [PATCH 5/8] Updated versioning components --- .../cross-database-macros.md | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index c48f96050f4..25806d4f42d 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -16,13 +16,44 @@ These macros benefit three different user groups: Please make sure to take a look at the [SQL expressions section](#sql-expressions) to understand quoting syntax for string values and date literals. ::: + + ## All functions (alphabetical) - [any_value](#any_value) +- [bool_or](#bool_or) +- [cast_bool_to_text](#cast_bool_to_text) +- [concat](#concat) +- [dateadd](#dateadd) +- [datediff](#datediff) +- [date_trunc](#date_trunc) +- [escape_single_quotes](#escape_single_quotes) +- [except](#except) +- [hash](#hash) +- [intersect](#intersect) +- [last_day](#last_day) +- [length](#length) +- [listagg](#listagg) +- [position](#position) +- [replace](#replace) +- [right](#right) +- [safe_cast](#safe_cast) +- [split_part](#split_part) +- [string_literal](#string_literal) +- [type_bigint](#type_bigint) +- [type_float](#type_float) +- [type_int](#type_int) +- [type_numeric](#type_numeric) +- [type_string](#type_string) +- [type_timestamp](#type_timestamp) + + + +## All functions (alphabetical) +- [any_value](#any_value) - [array_append](#array_append) - [array_concat](#array_concat) - [array_construct](#array_construct) - - [bool_or](#bool_or) - [cast_bool_to_text](#cast_bool_to_text) - [concat](#concat) @@ -43,26 +74,39 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [split_part](#split_part) - [string_literal](#string_literal) - [type_bigint](#type_bigint) - - [type_boolean](#type_boolean) - - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) - [type_string](#type_string) - [type_timestamp](#type_timestamp) + + + + [**Data type functions**](#data-type-functions) - [type_bigint](#type_bigint) +- [type_float](#type_float) +- [type_int](#type_int) +- [type_numeric](#type_numeric) +- [type_string](#type_string) +- [type_timestamp](#type_timestamp) + + + +[**Data type functions**](#data-type-functions) +- [type_bigint](#type_bigint) - [type_boolean](#type_boolean) - - [type_float](#type_float) - [type_int](#type_int) - [type_numeric](#type_numeric) - [type_string](#type_string) - [type_timestamp](#type_timestamp) + + [**Set functions**](#set-functions) - [except](#except) - [intersect](#intersect) From 2fe7782903c21d2b0d0db60f0f50a08b0639ca16 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Fri, 23 Sep 2022 14:49:03 -0600 Subject: [PATCH 6/8] Start _and_ end for applicable versioning components --- .../reference/dbt-jinja-functions/cross-database-macros.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 25806d4f42d..8bffb45cf25 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -16,7 +16,7 @@ These macros benefit three different user groups: Please make sure to take a look at the [SQL expressions section](#sql-expressions) to understand quoting syntax for string values and date literals. ::: - + ## All functions (alphabetical) - [any_value](#any_value) @@ -83,7 +83,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - + [**Data type functions**](#data-type-functions) - [type_bigint](#type_bigint) From f26d0406df1fbfe5f68bbf1bf130a9f02faee9f9 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Fri, 23 Sep 2022 18:14:49 -0600 Subject: [PATCH 7/8] Add dbt namespace to examples for all cross-database macros --- .../cross-database-macros.md | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 8bffb45cf25..3d8d57e38e0 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -160,7 +160,7 @@ This macro yields the database-specific data type for a `BIGINT`. **Usage**: ```sql -{{ type_bigint() }} +{{ dbt.type_bigint() }} ``` **Sample Output (PostgreSQL)**: @@ -181,7 +181,7 @@ This macro yields the database-specific data type for a `BOOLEAN`. **Usage**: ```sql -{{ type_boolean() }} +{{ dbt.type_boolean() }} ``` **Sample Output (PostgreSQL)**: @@ -202,7 +202,7 @@ This macro yields the database-specific data type for a `FLOAT`. **Usage**: ```sql -{{ type_float() }} +{{ dbt.type_float() }} ``` **Sample Output (PostgreSQL)**: @@ -221,7 +221,7 @@ This macro yields the database-specific data type for an `INT`. **Usage**: ```sql -{{ type_int() }} +{{ dbt.type_int() }} ``` **Sample Output (PostgreSQL)**: @@ -241,7 +241,7 @@ This macro yields the database-specific data type for a `NUMERIC`. **Usage**: ```sql -{{ type_numeric() }} +{{ dbt.type_numeric() }} ``` **Sample Output (PostgreSQL)**: @@ -260,7 +260,7 @@ This macro yields the database-specific data type for `TEXT`. **Usage**: ```sql -{{ type_string() }} +{{ dbt.type_string() }} ``` **Sample Output (PostgreSQL)**: @@ -279,7 +279,7 @@ This macro yields the database-specific data type for a `TIMESTAMP` (which may o **Usage**: ```sql -{{ type_timestamp() }} +{{ dbt.type_timestamp() }} ``` **Sample Output (PostgreSQL)**: @@ -300,7 +300,7 @@ __Args__: **Usage**: ```sql -{{ except() }} +{{ dbt.except() }} ``` **Sample Output (PostgreSQL)**: @@ -319,7 +319,7 @@ __Args__: **Usage**: ```sql -{{ intersect() }} +{{ dbt.intersect() }} ``` **Sample Output (PostgreSQL)**: @@ -343,9 +343,9 @@ This macro appends an element to the end of an array and returns the appended ar **Usage**: ```sql -{{ array_append("array_column", "element_column") }} -{{ array_append("array_column", "5") }} -{{ array_append("array_column", "'blue'") }} +{{ dbt.array_append("array_column", "element_column") }} +{{ dbt.array_append("array_column", "5") }} +{{ dbt.array_append("array_column", "'blue'") }} ``` **Sample Output (PostgreSQL)**: @@ -367,7 +367,7 @@ This macro returns the concatenation of two arrays. **Usage**: ```sql -{{ array_concat("array_column_1", "array_column_2") }} +{{ dbt.array_concat("array_column_1", "array_column_2") }} ``` **Sample Output (PostgreSQL)**: @@ -387,10 +387,10 @@ This macro returns an array constructed from a set of inputs. **Usage**: ```sql -{{ array_construct(["column_1", "column_2", "column_3"]) }} -{{ array_construct([], "integer") }} -{{ array_construct([1, 2, 3, 4]) }} -{{ array_construct(["'blue'", "'green'"]) }} +{{ dbt.array_construct(["column_1", "column_2", "column_3"]) }} +{{ dbt.array_construct([], "integer") }} +{{ dbt.array_construct([1, 2, 3, 4]) }} +{{ dbt.array_construct(["'blue'", "'green'"]) }} ``` **Sample Output (PostgreSQL)**: @@ -416,10 +416,10 @@ This macro combines a list of strings together. **Usage**: ```sql -{{ concat(["column_1", "column_2"]) }} -{{ concat(["year_column", "'-'" , "month_column", "'-'" , "day_column"]) }} -{{ concat(["first_part_column", "'.'" , "second_part_column"]) }} -{{ concat(["first_part_column", "','" , "second_part_column"]) }} +{{ dbt.concat(["column_1", "column_2"]) }} +{{ dbt.concat(["year_column", "'-'" , "month_column", "'-'" , "day_column"]) }} +{{ dbt.concat(["first_part_column", "'.'" , "second_part_column"]) }} +{{ dbt.concat(["first_part_column", "','" , "second_part_column"]) }} ``` **Sample Output (PostgreSQL)**: @@ -441,8 +441,8 @@ This macro provides a hash (such as [MD5](https://en.wikipedia.org/wiki/MD5)) of **Usage**: ```sql -{{ hash("column") }} -{{ hash("'Pennsylvania'") }} +{{ dbt.hash("column") }} +{{ dbt.hash("'Pennsylvania'") }} ``` **Sample Output (PostgreSQL)**: @@ -467,7 +467,7 @@ This macro calculates the number of characters in a string. **Usage**: ```sql -{{ length("column") }} +{{ dbt.length("column") }} ``` **Sample Output (PostgreSQL)**: @@ -489,8 +489,8 @@ This macro searches for the first occurrence of `substring_text` within `string_ **Usage**: ```sql -{{ position("substring_column", "text_column") }} -{{ position("'-'", "text_column") }} +{{ dbt.position("substring_column", "text_column") }} +{{ dbt.position("'-'", "text_column") }} ``` **Sample Output (PostgreSQL)**: @@ -517,8 +517,8 @@ This macro updates a string and replaces all occurrences of one substring with a **Usage**: ```sql -{{ replace("string_text_column", "old_chars_column", "new_chars_column") }} -{{ replace("string_text_column", "'-'", "'_'") }} +{{ dbt.replace("string_text_column", "old_chars_column", "new_chars_column") }} +{{ dbt.replace("string_text_column", "'-'", "'_'") }} ``` **Sample Output (PostgreSQL)**: @@ -548,8 +548,8 @@ This macro returns the N rightmost characters from a string. **Usage**: ```sql -{{ right("string_text_column", "length_column") }} -{{ right("string_text_column", "3") }} +{{ dbt.right("string_text_column", "length_column") }} +{{ dbt.right("string_text_column", "3") }} ``` **Sample Output (PostgreSQL)**: @@ -580,8 +580,8 @@ This macro splits a string of text using the supplied delimiter and returns the When referencing a column, use one pair of quotes. When referencing a string, use single quotes enclosed in double quotes. ```sql -{{ split_part(string_text='column_to_split', delimiter_text='delimiter_column', part_number=1) }} -{{ split_part(string_text="'1|2|3'", delimiter_text="'|'", part_number=1) }} +{{ dbt.split_part(string_text='column_to_split', delimiter_text='delimiter_column', part_number=1) }} +{{ dbt.split_part(string_text="'1|2|3'", delimiter_text="'|'", part_number=1) }} ``` **Sample Output (PostgreSQL)**: @@ -614,8 +614,8 @@ To escape quotes for column values, consider a macro like [replace](#replace) or **Usage**: ```sql -{{ escape_single_quotes("they're") }} -{{ escape_single_quotes("ain't ain't a word") }} +{{ dbt.escape_single_quotes("they're") }} +{{ dbt.escape_single_quotes("ain't ain't a word") }} ``` **Sample Output (PostgreSQL)**: @@ -637,7 +637,7 @@ To cast column values to a string, consider a macro like [safe_cast](#safe_cast) **Usage**: ```sql -select {{ string_literal("Pennsylvania") }} +select {{ dbt.string_literal("Pennsylvania") }} ``` **Sample Output (PostgreSQL)**: @@ -658,7 +658,7 @@ This macro returns some value of the expression from the group. The selected val **Usage**: ```sql -{{ any_value("column_name") }} +{{ dbt.any_value("column_name") }} ``` **Sample Output (PostgreSQL)**: @@ -677,10 +677,10 @@ This macro returns the logical `OR` of all non-`NULL` expressions -- `true` if a **Usage**: ```sql -{{ bool_or("boolean_column") }} -{{ bool_or("integer_column = 3") }} -{{ bool_or("string_column = 'Pennsylvania'") }} -{{ bool_or("column1 = column2") }} +{{ dbt.bool_or("boolean_column") }} +{{ dbt.bool_or("integer_column = 3") }} +{{ dbt.bool_or("string_column = 'Pennsylvania'") }} +{{ dbt.bool_or("column1 = column2") }} ``` **Sample Output (PostgreSQL)**: @@ -707,7 +707,7 @@ This macro returns the concatenated input values from a group of rows separated Note: If there are instances of `delimiter_text` within your `measure`, you cannot include a `limit_num`. ```sql -{{ listagg(measure="column_to_agg", delimiter_text="','", order_by_clause="order by order_by_column", limit_num=10) }} +{{ dbt.listagg(measure="column_to_agg", delimiter_text="','", order_by_clause="order by order_by_column", limit_num=10) }} ``` **Sample Output (PostgreSQL)**: @@ -734,12 +734,12 @@ This macro casts a boolean value to a string. **Usage**: ```sql -{{ cast_bool_to_text("boolean_column_name") }} -{{ cast_bool_to_text("false") }} -{{ cast_bool_to_text("true") }} -{{ cast_bool_to_text("0 = 1") }} -{{ cast_bool_to_text("1 = 1") }} -{{ cast_bool_to_text("null") }} +{{ dbt.cast_bool_to_text("boolean_column_name") }} +{{ dbt.cast_bool_to_text("false") }} +{{ dbt.cast_bool_to_text("true") }} +{{ dbt.cast_bool_to_text("0 = 1") }} +{{ dbt.cast_bool_to_text("1 = 1") }} +{{ dbt.cast_bool_to_text("null") }} ``` **Sample Output (PostgreSQL)**: @@ -781,9 +781,9 @@ For databases that support it, this macro will return `NULL` when the cast fails **Usage**: ```sql -{{ safe_cast("column_1", api.Column.translate_type("string")) }} -{{ safe_cast("column_2", api.Column.translate_type("integer")) }} -{{ safe_cast("'2016-03-09'", api.Column.translate_type("date")) }} +{{ dbt.safe_cast("column_1", api.Column.translate_type("string")) }} +{{ dbt.safe_cast("column_2", api.Column.translate_type("integer")) }} +{{ dbt.safe_cast("'2016-03-09'", api.Column.translate_type("date")) }} ``` **Sample Output (PostgreSQL)**: @@ -808,8 +808,8 @@ This macro adds a time/day interval to the supplied date/timestamp. Note: The `d **Usage**: ```sql -{{ dateadd(datepart="day", interval=1, from_date_or_timestamp="'2016-03-09'") }} -{{ dateadd(datepart="month", interval=-2, from_date_or_timestamp="'2016-03-09'") }} +{{ dbt.dateadd(datepart="day", interval=1, from_date_or_timestamp="'2016-03-09'") }} +{{ dbt.dateadd(datepart="month", interval=-2, from_date_or_timestamp="'2016-03-09'") }} ``` **Sample Output (PostgreSQL)**: @@ -831,9 +831,9 @@ This macro calculates the difference between two dates. **Usage**: ```sql -{{ datediff("column_1", "column_2", "day") }} -{{ datediff("column", "'2016-03-09'", "month") }} -{{ datediff("'2016-03-09'", "column", "year") }} +{{ dbt.datediff("column_1", "column_2", "day") }} +{{ dbt.datediff("column", "'2016-03-09'", "month") }} +{{ dbt.datediff("'2016-03-09'", "column", "year") }} ``` **Sample Output (PostgreSQL)**: @@ -858,9 +858,9 @@ This macro truncates / rounds a timestamp to the first instant for the given [da **Usage**: ```sql -{{ date_trunc("day", "updated_at") }} -{{ date_trunc("month", "updated_at") }} -{{ date_trunc("year", "'2016-03-09'") }} +{{ dbt.date_trunc("day", "updated_at") }} +{{ dbt.date_trunc("month", "updated_at") }} +{{ dbt.date_trunc("year", "'2016-03-09'") }} ``` **Sample Output (PostgreSQL)**: @@ -884,8 +884,8 @@ This macro gets the last day for a given date and datepart. - This macro currently only supports dateparts of `month` and `quarter`. ```sql -{{ last_day("created_at", "month") }} -{{ last_day("'2016-03-09'", "year") }} +{{ dbt.last_day("created_at", "month") }} +{{ dbt.last_day("'2016-03-09'", "year") }} ``` **Sample Output (PostgreSQL)**: From da38078027e98c5f4cfb909a10e5969dfb3e7cb6 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Sat, 24 Sep 2022 06:12:30 -0600 Subject: [PATCH 8/8] Prevent duplication of heading in right menu --- .../reference/dbt-jinja-functions/cross-database-macros.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 3d8d57e38e0..a7d8f2bc54b 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -16,9 +16,10 @@ These macros benefit three different user groups: Please make sure to take a look at the [SQL expressions section](#sql-expressions) to understand quoting syntax for string values and date literals. ::: +## All functions (alphabetical) + -## All functions (alphabetical) - [any_value](#any_value) - [bool_or](#bool_or) - [cast_bool_to_text](#cast_bool_to_text) @@ -49,7 +50,6 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression -## All functions (alphabetical) - [any_value](#any_value) - [array_append](#array_append) - [array_concat](#array_concat)