-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add default_value under arguments #8209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: current
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
QMalcolm
left a comment
There was a problem hiding this 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!
website/docs/reference/resource-properties/function-arguments.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Grace Goheen <[email protected]>
Co-authored-by: Grace Goheen <[email protected]>
| <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') |
There was a problem hiding this comment.
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
QMalcolm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
|
@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 |
website/docs/reference/resource-properties/function-arguments.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Mirna Wong <[email protected]>
website/docs/reference/resource-properties/function-arguments.md
Outdated
Show resolved
Hide resolved
|
|
||
| ### 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). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> | ||
|
|
There was a problem hiding this comment.
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
Co-authored-by: Mirna Wong <[email protected]>
website/docs/reference/resource-properties/function-arguments.md
Outdated
Show resolved
Hide resolved
website/docs/reference/resource-properties/function-arguments.md
Outdated
Show resolved
Hide resolved
| ### 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. |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this part
What are you changing in this pull request and why?
Closes #8195
Previews:
Checklist