Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions website/docs/docs/build/udfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ You can define SQL and Python UDFs in dbt. Note: Python UDFs are currently suppo
- name: a_string # required if arguments is specified
data_type: string # required if arguments is specified
description: The string that I want to check if it's representing a positive integer (like "10")
default_value: "'1'" # optional, available in Snowflake and Postgres
returns: # required
data_type: integer # required
```
Expand Down Expand Up @@ -159,9 +160,10 @@ You can define SQL and Python UDFs in dbt. Note: Python UDFs are currently suppo
arguments: # optional
- name: a_string # required if arguments is specified
data_type: string # required if arguments is specified
description: The string that I want to check if it's representing a positive integer (like "10")
returns: # required
data_type: integer # required
description: The string that I want to check if it's representing a positive integer (like "10")
default_value: "'1'" # optional, available in Snowflake and Postgres
returns: # required
data_type: integer # required
```
</File>
</TabItem>
Expand Down Expand Up @@ -197,7 +199,7 @@ You can define SQL and Python UDFs in dbt. Note: Python UDFs are currently suppo
<TabItem value="Snowflake">

```sql
CREATE OR REPLACE FUNCTION udf_db.udf_schema.is_positive_int(a_string STRING)
CREATE OR REPLACE FUNCTION udf_db.udf_schema.is_positive_int(a_string STRING DEFAULT '1')
RETURNS INTEGER
LANGUAGE SQL
IMMUTABLE
Expand Down Expand Up @@ -242,7 +244,7 @@ You can define SQL and Python UDFs in dbt. Note: Python UDFs are currently suppo
<TabItem value="Postgres">

```sql
CREATE OR REPLACE FUNCTION udf_schema.is_positive_int(a_string text)
CREATE OR REPLACE FUNCTION udf_schema.is_positive_int(a_string text DEFAULT '1')
RETURNS int
LANGUAGE sql
IMMUTABLE
Expand All @@ -260,7 +262,7 @@ You can define SQL and Python UDFs in dbt. Note: Python UDFs are currently suppo

<TabItem value="Snowflake">
```sql
CREATE OR REPLACE FUNCTION udf_db.udf_schema.is_positive_int(a_string STRING)
CREATE OR REPLACE FUNCTION udf_db.udf_schema.is_positive_int(a_string STRING DEFAULT '1')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated the CREATE statement for Python

RETURNS INTEGER
LANGUAGE PYTHON
RUNTIME_VERSION = '3.11'
Expand Down
1 change: 1 addition & 0 deletions website/docs/reference/function-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ functions:
- name: <string> # required if arguments is specified
data_type: <string> # required if arguments is specified, warehouse-specific
description: <markdown_string> # optional
default_value: <string | boolean | integer> # optional, available in Snowflake and Postgres
- name: ... # declare additional arguments
[returns](/reference/resource-properties/returns): # required
data_type: <string> # required, warehouse-specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import ArgumentsShared from '/snippets/_arguments-shared.md';

```yml


functions:
- name: <function name>
arguments:
- name: <arg name>
data_type: <string> # warehouse-specific
description: <markdown_string>
default_value: <string | boolean | integer> # optional, available in Snowflake and Postgres

```

Expand Down Expand Up @@ -55,6 +55,49 @@ Refer to your warehouse documentation for the complete list of supported data ty

An optional markdown string describing the argument. This is helpful for documentation purposes.

### default_value

Use the `default_value` property to make a function argument optional.
- When an argument isn't defined with a `default_value`, it becomes a required argument, and you must pass a value for them when you use the function. If a required argument isn’t passed, the function call fails.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised lines 61 and 62

- Arguments with a `default_value` are optional &mdash; if you don't pass a value for the argument, the warehouse uses the value you set in `default_value`.

This property is supported in [Snowflake](https://docs.snowflake.com/en/developer-guide/udf-stored-procedure-arguments#designating-an-argument-as-optional) and [Postgres](https://www.postgresql.org/docs/current/sql-createfunction.html).

When you use `default_value`, the order of your arguments matter. Any required arguments (those without default values) have to come before optional ones. Here's an example with the correct order:

<File name='functions/schema.yml'>

```yml
functions:
- name: sum_2_values
description: Add two values together
arguments:
- name: val1 # this argument comes first because it has no default value
data_type: integer
description: The first value
- name: val2
data_type: integer
description: The second value
default_value: 0
returns:
data_type: integer
```
</File>

In this example:
- `val1` has no `default_value`, so it’s required.
- `val2` has a `default_value` of `0`, so it’s optional. If you don’t provide a value for `val2`, the function uses `0` instead.

See the following examples of calling the `sum_2_values` function:

```text
sum_2_values(5) # val1 = 5, val2 = 0 (default value used since user did not specify val2)
sum_2_values(5, 10) # val1 = 5, val2 = 10
sum_2_values() # ❌ error: val1 is required and must be passed
```



Copy link
Contributor

@mirnawong1 mirnawong1 Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we should include an example of what 'calling a function' looks like for sql/python:
e.g for sql it looks like:

select sum_2_values(5);        -- val1 = 5, val2 = 0 (default used since user didn't specify 2nd value in the sql call)
select sum_2_values(5, 10);    -- val1 = 5, val2 = 10
select sum_2_values();         -- ❌ error: val1 is required and must be passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calling of a function should look the same whether the function is using Python or SQL 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, @QMalcolm ! I added a generic example here, could you please review and let me know if it needs changes? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🙂

## Examples

### Simple function arguments
Expand Down
2 changes: 1 addition & 1 deletion website/snippets/_arguments-shared.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
The `arguments` property is used to define the parameters that a resource can accept. Each argument can have a `name`, a type field, and an optional `description`.
The `arguments` property is used to define the parameters that a resource can accept. Each argument can have a `name`, a type field, and optional properties such as `description` and `default_value`.

Loading