.create function.create function

创建存储函数,该函数是具有给定名称的可重用 let 语句函数。Creates a stored function, which is a reusable let statement function with the given name. 函数定义与数据库元数据一起保留。The function definition is persisted with the database metadata.

函数可以调用其他函数(不支持递归性),并且允许 let 语句作为函数正文的一部分。Functions can call other functions (recursiveness is not supported), and let statements are allowed as part of the Function Body. 请参阅 let 语句See let statements.

参数类型和 CSL 语句的规则与 let 语句的规则相同。Rules for parameter types and CSL statements are the same as for let statements.


.create function [ifnotexists]with ([docstring = Documentation][, folder = foldername] )] [, skipvalidation = 'true'] )] FunctionName ( ParamName : ParamType [, ...] ) { FunctionBody }.create function [ifnotexists]with ([docstring = Documentation][, folder = foldername] )] [, skipvalidation = 'true'] )] FunctionName ( ParamName : ParamType [, ...] ) { FunctionBody }


输出参数Output parameter 类型Type 说明Description
名称Name StringString 函数的名称。The name of the function.
parametersParameters StringString 函数所需的参数。The parameters required by the function.
正文Body StringString (零个或多个)let 语句,后跟有效的 CSL 表达式,该表达式在函数调用时求值。(Zero or more) let statements followed by a valid CSL expression that is evaluated upon function invocation.
文件夹Folder StringString 用于 UI 函数分类的文件夹。A folder used for UI functions categorization. 此参数不会更改调用函数的方式。This parameter doesn't change the way function is invoked.
DocStringDocString StringString 用于 UI 目的的函数说明。A description of the function for UI purposes.


  • 如果函数已存在:If function already exists:
    • 如果指定了 ifnotexists 标志,则该命令将被忽略(不应用更改)。If ifnotexists flag is specified, the command is ignored (no change applied).
    • 如果未指定 ifnotexists 标志,则将返回错误。If ifnotexists flag is NOT specified, an error is returned.
    • 若要更改现有函数,请参阅 .alter 函数For altering an existing function, see .alter function
  • 需要数据库用户权限Requires database user permission.
  • let 语句并非支持所有数据类型。Not all data types are supported in let statements. 支持的类型为:布尔值、字符串、长整型、日期/时间、时间跨度、双精度型和动态型。Supported types are: boolean, string, long, datetime, timespan, double, and dynamic.
  • 使用“skipvalidation”跳过函数的语义验证。Use 'skipvalidation' to skip semantic validation of the function. 如果以不正确的顺序创建函数,并且之前创建了使用 F2 的 F1,这会很有用。This is useful when functions are created in an incorrect order and F1 that uses F2 is created earlier.


.create function
with (docstring = 'Simple demo function', folder='Demo')
MyFunction1()  {StormEvents | limit 100}
名称Name parametersParameters 正文Body 文件夹Folder DocStringDocString
MyFunction1MyFunction1 ()() {StormEvents | limit 100}{StormEvents | limit 100} 演示Demo 简单演示函数Simple demo function
.create function
with (docstring = 'Demo function with parameter', folder='Demo')
 MyFunction2(myLimit: long)  {StormEvents | limit myLimit}
名称Name parametersParameters 正文Body 文件夹Folder DocStringDocString
MyFunction2MyFunction2 (myLimit:long)(myLimit:long) {StormEvents | limit myLimit}{StormEvents | limit myLimit} 演示Demo 带参数的演示函数Demo function with parameter