Creating a Scalar or Aggregate UDF

Learn how to create and configure external C or C++ scalar and aggregate user-defined functions.

  1. Declare the UDF to the server by using the CREATE FUNCTION or CREATE AGGREGATE FUNCTION statements. Write and execute these statements as commands, or use Sybase Control Center.

    The external C/C++ form of the CREATE FUNCTION statement requires the CREATE EXTERNAL REFERENCE system privilege. Therefore, standard users do not have the authority to declare any UDFs of this type.

  2. Write the UDF library identification function.
  3. Define the UDF as a set of C or C++ functions. See Defining a scalar UDF or Defining an aggregate UDF.
  4. Implement the function entry points in C/C++.
  5. Compile the UDF functions and the library identification functions.
  6. Link the compiled file into a dynamically linkable library.

Any reference to a UDF in a SQL statement first, if necessary, links the dynamically linkable library. The calling patterns are then called.

Because these high-performance external C/C++ user-defined functions involve the loading of non-server library code into the process space of the server, there are potential risks to data integrity, data security, and server robustness from poorly or maliciously written functions. To manage these risks, each SAP Sybase IQ server can explicitly enable or disable this functionality.