SQL - CREATE FUNCTION

Creates a new Server-side function. You can execute Functions from SQL, HTTP and Java.

Syntax

  1. CREATE FUNCTION <name> <code>
  2. [PARAMETERS [<comma-separated list of parameters' name>]]
  3. [IDEMPOTENT true|false]
  4. [LANGUAGE <language>]
  • <name> Defines the function name.
  • <code> Defines the function code.
  • PARAMETERS Defines a comma-separated list of parameters bound to the execution heap. You must wrap your parameters list in square brackets [].
  • IDEMPOTENT Defines whether the function can change the database status. This is useful given that HTTP GET can call IDEMPOTENT functions, while others are called by HTTP POST. By default, it is set to FALSE.
  • LANGUAGE Defines the language to use. By default, it is set to JavaScript.

Examples

  • Create a function test() in JavaScript, which takes no parameters:

    1. orientdb> CREATE FUNCTION test "print('\nTest!')"
  • Create a function test(a,b) in JavaScript, which takes 2 parameters:

    1. orientdb> CREATE FUNCTION test "return a + b;" PARAMETERS [a,b]
  • Create a function allUsersButAdmin in SQL, which takes with no parameters:

    1. orientdb> CREATE FUNCTION allUsersButAdmin "SELECT FROM ouser WHERE name <>
    2. 'admin'" LANGUAGE SQL

For more information, see