cloud-fan commented on code in PR #51281: URL: https://github.com/apache/spark/pull/51281#discussion_r2167992173
########## docs/sql-ref-syntax-ddl-create-sql-function.md: ########## @@ -0,0 +1,305 @@ +--- +layout: global +title: CREATE FUNCTION (SQL) +displayTitle: CREATE FUNCTION (SQL) +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description +The `CREATE FUNCTION` statement creates a SQL function that can be used in SQL statements. The function can be temporary or permanent, and can return either a scalar value or a table result. The function body can be defined either a SQL expression or a query. + +When `TEMPORARY` is specified, the function is only available for the current session. Otherwise, it is persisted in the catalog and available across sessions. The `OR REPLACE` option allows updating an existing function definition, while `IF NOT EXISTS` prevents errors when creating a function that already exists. + +The function parameters must be specified with their data types. The return type can be either a scalar data type or a table with an optional schema definition. + + +### Syntax + +```sql +CREATE [OR REPLACE] [TEMPORARY] FUNCTION [IF NOT EXISTS] + function_name ( [ function_parameter [, ...] ] ) + { [ RETURNS data_type ] | + RETURNS TABLE [ ( column_spec [, ...]) ] } + [ characteristic [...] ] + RETURN { expression | query } + +function_parameter + parameter_name data_type [DEFAULT default_expression] [COMMENT parameter_comment] + +column_spec + column_name data_type [COMMENT column_comment] + +characteristic + { LANGUAGE SQL | + [NOT] DETERMINISTIC | + COMMENT function_comment | + [CONTAINS SQL | READS SQL DATA] } +``` + +### Parameters + +- **OR REPLACE** + + If specified, the function with the same name and signature (number of parameters and parameter types) is replaced. You cannot replace an existing function with a different signature or a procedure. This is mainly useful to update the function body and the return type of the function. You cannot specify this parameter with `IF NOT EXISTS`. + +- **TEMPORARY** + + The scope of the function being created. When you specify `TEMPORARY`, the created function is valid and visible in the current session. No persistent entry is made in the catalog. + +- **IF NOT EXISTS** + + If specified, creates the function only when it does not exist. The creation of the function succeeds (no error is thrown) if the specified function already exists in the system. You cannot specify this parameter with `OR REPLACE`. + +- **function_name** + + A name for the function. For a permanent function, you can optionally qualify the function name with a schema name. Review Comment: ```suggestion A name for the function. For a permanent function, you can optionally qualify the function name, or it will be created under the current catalog and namespace. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
