SQL - CREATE FUNCTION

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

Syntax

CREATE FUNCTION <name> <code>
                [PARAMETERS [<comma-separated list of parameters' name>]]
                [IDEMPOTENT true|false]
                [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:

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

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

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

For more information, see