You are viewing the documentation for a prerelease version.

View Latest

EXECUTE FUNCTION

  • Developer Preview
The EXECUTE FUNCTION statement enables you to execute a user-defined function.

This is a Developer Preview feature, intended for development purposes only. Do not use this feature in production. No Enterprise Support is provided for Developer Preview features.

Refer to Developer Preview Mode for more information.

Purpose

The EXECUTE FUNCTION statement enables you to execute a user-defined function. It is useful for testing user-defined functions outside the context of a query.

You cannot use the EXECUTE FUNCTION statement to execute a built-in N1QL function. If you do this, error 10101: Function not found is generated.

Syntax

execute-function ::= EXECUTE FUNCTION name '(' [ expression ( ',' expression )* ] ')'
'EXECUTE' 'FUNCTION' name '(' (expression (',' expression)* )? ')'
name

The name of the function. This may be an unqualified identifier, such as func1 or `func-1`, or a qualified identifier with a namespace, such as default:func1.

The name of a user-defined function is case-sensitive, unlike that of a built-in function. You must execute the user-defined function using the same case that was used when it was created.
expression

[Optional] A N1QL expression required by the function as an argument. If the function was created with named parameters, you must supply all the arguments that were specified when the function was created. If the function was created without named parameters, it is variadic, and you can supply as many arguments as needed.

Return Value

The function returns one value, of any valid N1QL type. The result (and the data type of the result) depend on the expression or code that were used to define the function.

If you supply the wrong number of arguments, or arguments with the wrong data type, the possible results differ, depending on whether the function was defined with or without any named parameters.

If the function was defined with named parameters:

  • If you do not supply enough arguments, the function generates error 10104: Incorrect number of arguments.

  • If you supply too many arguments, the function generates error 10104: Incorrect number of arguments.

  • If any of the arguments have the wrong data type, the function may return unexpected results, depending on the function expression or code.

If the function was defined without named parameters:

  • If you do not supply enough arguments, the function may return unexpected results, depending on the function expression or code.

  • If you supply too many arguments, the extra parameters are ignored.

  • If any of the arguments have the wrong data type, the function may return unexpected results, depending on the function expression or code.

Examples

For examples, refer to CREATE FUNCTION.