Skip to content

Conversation

@luna-bianca
Copy link
Contributor

@luna-bianca luna-bianca commented Nov 21, 2025

What are you changing in this pull request and why?

Closes #8195

Previews:

Checklist

@luna-bianca luna-bianca requested a review from a team as a code owner November 21, 2025 06:25
@vercel
Copy link

vercel bot commented Nov 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
docs-getdbt-com Ready Ready Preview Nov 27, 2025 1:33pm

@luna-bianca luna-bianca requested review from QMalcolm and graciegoheen and removed request for a team and QMalcolm November 21, 2025 06:25
@github-actions github-actions bot added the content Improvements or additions to content label Nov 21, 2025
@luna-bianca luna-bianca requested a review from QMalcolm November 21, 2025 06:26
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

Small change request, otherwise this looks good!

<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

@luna-bianca luna-bianca requested a review from QMalcolm November 24, 2025 14:09
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@graciegoheen
Copy link
Collaborator

@QMalcolm are we good to merge this in? did this make it in time for the code freeze?

@QMalcolm
Copy link
Contributor

QMalcolm commented Nov 24, 2025

@QMalcolm are we good to merge this in? did this make it in time for the code freeze?

Good question @graciegoheen. The core side got in. However, I don't believe the adapters side made it. We merged the adapters support on Nov 19th (PR), and our last cloud image didn't include it. So the parsing functionality is out (you are able to specify defaults in your project without issue), but the actual support (the defaults being part of the create statement) provided by the adapter is not 😞 So the adapters side won't make it into cloud until after the code freeze


### default_value

The `default_value` is an optional property that you can use to define a default value for a function argument. If no value is provided for that argument, the warehouse uses the specified default. Setting a `default_value` makes the argument optional. 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).
Copy link
Contributor

Choose a reason for hiding this comment

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

confirming this is for python and sql too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Default arguments are supported for both Python and SQL for Snowflake. Postgres only supports default arguments for SQL (but that's because Postgres has no support for Python functions at all) 🙂

- `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.

</File>

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

### 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

- `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 in SQL and Python:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content Improvements or additions to content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] default values for arguments - dbt-core Issue #12044

5 participants