From 40ea3d5bb62479d22199cc8cdcb4a325e2a0c0bd Mon Sep 17 00:00:00 2001 From: Diego Quintana Date: Wed, 11 Sep 2024 19:20:19 -0300 Subject: [PATCH 1/3] Update constraints.md Adds a reference to `{{ target.schema }}`, useful when defining `foreign_key` constraints. --- website/docs/reference/resource-properties/constraints.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/reference/resource-properties/constraints.md b/website/docs/reference/resource-properties/constraints.md index b8111ef0adb..b24a5b430d6 100644 --- a/website/docs/reference/resource-properties/constraints.md +++ b/website/docs/reference/resource-properties/constraints.md @@ -23,6 +23,8 @@ The structure of a constraint is: - `name` (optional): Human-friendly name for this constraint. Supported by some data platforms. - `columns` (model-level only): List of column names to apply the constraint over +When using `foreign_key`, the schema of the relation being referenced needs to be set explicitly. You can use `{{ target.schema }}` to let dbt pass the schema used by the target being used. + ```yml @@ -62,6 +64,8 @@ models: + + ## Platform-specific support In transactional databases, it is possible to define "constraints" on the allowed values of certain columns, stricter than just the data type of those values. For example, Postgres supports and enforces all the constraints in the ANSI SQL standard (`not null`, `unique`, `primary key`, `foreign key`), plus a flexible row-level `check` constraint that evaluates to a boolean expression. From f32abca9be9b65771d367bc8679c6274642bfc29 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:31:43 +0100 Subject: [PATCH 2/3] Update website/docs/reference/resource-properties/constraints.md --- website/docs/reference/resource-properties/constraints.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/website/docs/reference/resource-properties/constraints.md b/website/docs/reference/resource-properties/constraints.md index b24a5b430d6..33d4c5afa3c 100644 --- a/website/docs/reference/resource-properties/constraints.md +++ b/website/docs/reference/resource-properties/constraints.md @@ -23,7 +23,13 @@ The structure of a constraint is: - `name` (optional): Human-friendly name for this constraint. Supported by some data platforms. - `columns` (model-level only): List of column names to apply the constraint over -When using `foreign_key`, the schema of the relation being referenced needs to be set explicitly. You can use `{{ target.schema }}` to let dbt pass the schema used by the target being used. + + +When using `foreign_key`, you need to manually specify the schema of the referenced table. Use `{{ target.schema }}` in the `expression` field to automatically pass the schema used by the target environment. Note that versions of dbt will have more efficient ways of handling this. + +For example: `expression: "{{ target.schema }}.customers(customer_id)"` + + From 9e68a5abe76960bc8968b4c06e9a1ce9832bfffb Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:02:02 +0100 Subject: [PATCH 3/3] Update website/docs/reference/resource-properties/constraints.md --- website/docs/reference/resource-properties/constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/resource-properties/constraints.md b/website/docs/reference/resource-properties/constraints.md index 33d4c5afa3c..ff52a1fbcf4 100644 --- a/website/docs/reference/resource-properties/constraints.md +++ b/website/docs/reference/resource-properties/constraints.md @@ -25,7 +25,7 @@ The structure of a constraint is: -When using `foreign_key`, you need to manually specify the schema of the referenced table. Use `{{ target.schema }}` in the `expression` field to automatically pass the schema used by the target environment. Note that versions of dbt will have more efficient ways of handling this. +When using `foreign_key`, you need to specify the referenced table's schema manually. Use `{{ target.schema }}` in the `expression` field to automatically pass the schema used by the target environment. Note that later versions of dbt will have more efficient ways of handling this. For example: `expression: "{{ target.schema }}.customers(customer_id)"`