CREATE ANALYTIC FUNCTION
Associates a User Defined Analytic Function (UDAnF) stored in a shared Linux library with a SQL function name. You must have already loaded the library containing the UDAnF using the CREATE LIBRARY statement. When you call the SQL function, Vertica passes the arguments to the analytic function in the library to process.
Syntax
CREATE [ OR REPLACE ] ANALYTIC FUNCTION function-name
... AS [ LANGUAGE 'language' ] NAME 'factory'
... LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
function‑name
|
The name to assign to the UDAnF. This is the name you use in your SQL statements to call the function. |
LANGUAGE 'language'
|
The language used to develop this function, one of the following:
|
NAME 'factory'
|
The name of the C++ factory class in the shared library that generates the object to handle the function's processing. |
LIBRARY library‑name
|
The name of the shared library that contains the C++ object to perform the processing for this function. This library must have been previously loaded using the CREATE LIBRARY statement. |
FENCED | NOT FENCED
|
Enables or disables Fenced Mode for this function. Default Value: |
Privileges
- To create a function, the user must have CREATE privilege on the schema to contain the function and USAGE privilege on the library containing the function.
- To use a function, the user must have USAGE privilege on the schema that contains the function and EXECUTE privileges on the function.
- To drop a function, the user must either be a superuser, the owner of the function, or the owner of the schema which contains the function.
Usage Considerations
- The parameters and return value for the function are automatically determined by the CREATE ANALYTIC FUNCTION statement, based on data supplied by the factory class.
- You can assign multiple functions the same name if they accept different sets of arguments. See Overloading Your UDx in Extending Vertica for more information.
- You can return a list of all UDFs by querying the system table V_CATALOG.USER_FUNCTIONS. Users see only the functions on which they have
EXECUTE
privileges.
Examples
This example shows how to create an analytic function named an_rank based on the factory class named RankFactory in the AnalyticFunctions library..
=> CREATE ANALYTIC FUNCTION an_rank AS LANGUAGE 'C++' NAME 'RankFactory' LIBRARY AnalyticFunctions;