# SqlEngine.registerFunction

Register a function to be accessible to this SqlEngine.

### For an overview see page Python SqlEngine Class

### Prototype

        SqlEngine.registerFunction(return_type, function_name, function, n_arguments)

### Arguments

return_type | The return type; one of the following built-in Python types:
        bool
        int
        long
        float
        string
        unicode
function_name | The function name
function | The Python function as defined by the application and registered with the runtime by calling `exdb.register_function()`
n_arguments | The number of arguments for this function; if -1 is specified it means that the function accepts a variable number of arguments

### Description

When a function is registered using this method, it will be accessible to this SqlEngine.

NB: This method is reentrant. In the current Python API a SqlEngine is implicitly created by a cursor, so this method is rarely needed. Also please note the following:

- The return type should be one of the following built-in Python types: `bool, int, long, float, string, unicode`
- The parameter types are not specified - it is the application's responsibility to check the parameters types.
- Polymorphic functions are allowed.
- The `n_arguments` argument can be -1: in this case the function can accept a varying number of parameters.
- If the `n_arguments` argument is `2` and `function` is called with just one parameter, then it is considered as an aggregate (For an example of this see the EMA function in the SDK sample “samples/python/sql/sqlbasic” - a snippet of which is shown below).

### Returns

Exception | An exception is thrown with the appropriate error message

### Example

        def ema(agg,val):
            a = 2.0 / (14 + 1)
            return a*val + (1-a)*agg

        ...
        dict = exdb.load_dictionary(schema, persistent=is_disk, debug=is_debug)
        db = exdb.open_database(dbname='opendb', dictionary=dict, is_disk=is_disk, db_segment_size=128*1024*1024);
        exdb.register_function(float, "ema", ema, 2)
        ...
        conn = db.connect()
        conn.engine.registerFunction(float, "ema", ema, 2)