CREATE SOURCE
Adds a user-defined load source function to the catalog. The library containing the function must have been previously added using CREATE LIBRARY.
CREATE SOURCE automatically determines the function parameters and return value from data supplied by the factory class. Vertica supports overloading load source functions. When you call the SQL function, Vertica passes the input table to the function in the library to process.
Installing an untrusted UDL function can compromise the security of the server. UDxs can contain arbitrary code. In particular, user-defined source functions can read data from any arbitrary location. It is up to the developer of the function to enforce proper security limitations. Superusers must not grant access to UDxs to untrusted users.
Syntax
CREATE [ OR REPLACE ] SOURCE [ IF NOT EXISTS ] [[database.]schema.]function AS [ LANGUAGE 'language' ] NAME 'factory' LIBRARY library [ FENCED | NOT FENCED ]
Arguments
OR REPLACE
|
If a function with the same name and arguments exists, replace it. You can use this to change between fenced and unfenced modes, for example. If you do not use this directive and the function already exists, the CREATE statement returns with a rollback error. OR REPLACE and IF NOT EXISTS are mutually exclusive. |
IF NOT EXISTS
|
If a function with the same name and arguments exists, return without creating the function. OR REPLACE and IF NOT EXISTS are mutually exclusive. |
[database.]schema
|
Database and schema. The default schema is |
function
|
Name of the function to create. This is the name used in SQL invocations of the function. It does not need to match the name of the factory, but it is less confusing if they are the same or similar. The function name must conform to the restrictions on Identifiers. |
LANGUAGE 'language'
|
Language used to develop this function, one of the following:
|
NAME 'factory'
|
Name of the factory class that generates the function instance. This is the same name used by the RegisterFactory class. |
LIBRARY library
|
Name of the C++ library shared object file or Java Jar file. This library must already have been loaded by CREATE LIBRARY. |
FENCED | NOT FENCED
|
Enables or disables fenced mode for this function. Default: |
Privileges
Superuser
Example
The following example demonstrates loading a library named curllib
, then defining a source function named curl
that is mapped to the CurlSourceFactory
factory class in the library:
=> CREATE LIBRARY curllib as '/opt/vertica/sdk/examples/build/cURLLib.so'; CREATE LIBRARY => CREATE SOURCE curl AS LANGUAGE 'C++' NAME 'CurlSourceFactory' LIBRARY curllib; CREATE SOURCE => \x Expanded display is on. => SELECT * FROM user_functions; -[ RECORD 1 ]----------+-------------------- schema_name | public function_name | curl procedure_type | User Defined Source function_return_type | function_argument_type | function_definition | volatility | is_strict | f is_fenced | f comment |