Creating a user-defined function

Learn how to create and configure external C/C++ user-defined functions (UDFs).

For instructions on creating UDFs using Interactive SQL, see System Administration Guide: Volume 2 > Using Procedures and Batches.

  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 the appropriate CREATE statement using the Sybase Central New Function wizard.

    The external C/C++ form of the CREATE FUNCTION statement requires DBA or RESOURCE authority, so 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 IQ server can explicitly enable or disable this functionality.

Related concepts
User-defined function restrictions
Maintenance of user-defined functions
Compiling and linking source code to build dynamically linkable libraries
SQL data types
Related tasks
Calling user-defined functions
Setting the dynamic library interface
Dropping user-defined functions
Granting and revoking permissions
Using Microsoft Visual Studio debugger for user-defined functions