SQL Reference

CREATE TRANSFORM

The CREATE TRANSFORM statement defines transformation functions, identified by a group name, that are used to exchange structured type values with host language programs and with external functions and methods.

Invocation

This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared. However, if the bind option DYNAMICRULES BIND applies, the statement cannot be dynamically prepared (SQLSTATE 42509).

Authorization

The privileges held by the authorization ID of the statement must include at least one of the following:

Syntax

>>-CREATE--+-TRANSFORM--+---FOR--type-name---------------------->
           '-TRANSFORMS-'
 
      .------------------------------------------------------------------------------------.
      |                 .-,--------------------------------------------------------.       |
      V                 V                                                   (1)    |       |
>--------group-name--(------+-TO SQL---+---WITH--| function-specification |--------+---)---+>
                            '-FROM SQL-'
 
>--------------------------------------------------------------><
 
function-specification
 
|---+-FUNCTION--function-name--+-------------------------------+-+->
    |                          '-(--+-------------------+---)--' |
    |                               |  .-,-----------.  |        |
    |                               |  V             |  |        |
    |                               '----data-type---+--'        |
    '-SPECIFIC FUNCTION--specific-name---------------------------'
 
>---------------------------------------------------------------|
 

Notes:

  1. The same clause must not be specified more than once.

Description

TRANSFORM  or  TRANSFORMS
Indicates that one or more transform groups is being defined. Either version of the keyword can be specified.

FOR type-name
Specifies a name for the user-defined structured type for which the transform group is being defined.

In dynamic SQL statements, the CURRENT SCHEMA special register is used as a qualifier for an unqualified type-name. In static SQL statements the QUALIFIER precompile/bind option implicitly specifies the qualifier for an unqualified type-name. The type-name must be the name of an existing user-defined type (SQLSTATE 42704), and it must be a structured type (SQLSTATE 42809). The structured type or any other structured type in the same type hierarchy must not have transforms already defined with the given group-name (SQLSTATE 42739).

group-name
Specifies the name of the transform group containing the TO SQL and FROM SQL functions. The name does not need to be unique; but a transform group of this name (with the same TO SQL and/or FROM SQL direction defined) must not be previously defined for the specified type-name (SQLSTATE 42739). A group-name must be an SQL identifier, with a maximum of 18 characters in length (SQLSTATE 42622), and it may not include any qualifier prefix (SQLSTATE 42601). The group-name cannot begin with the prefix 'SYS', since this is reserved for database use (SQLSTATE 42939).

At most, one of each of the FROM SQL and TO SQL function designations may be specified for any given group (SQLSTATE 42628).

TO SQL
Defines the specific function used to transform a value to the SQL user-defined structured type format. The function must have all its parameters as built-in data types and the returned type is type-name.

FROM SQL
Defines the specific function used to transform a value to a built in data type value representing the SQL user-defined structured type. The function must have one parameter of data type type-name, and return a built-in data type (or set of built-in data types).

WITH function-specification
There are several ways available to specify the function instance.

If FROM SQL is specified, function-specification must identify a function that meets the following requirements:

If TO SQL is specified, function-specification must identify a function that meets the following requirements:

Methods (even if specified with FUNCTION ACCESS) cannot be specified as transforms through function-specification. Instead, only functions that are defined by the CREATE FUNCTION statement can act as transforms (SQLSTATE 42704 or 42883).

Additionally, although not enforced, the one or more built-in types which are returned from the FROM SQL function should directly correspond to the one or more built-in types which are parameters of the TO SQL function. This is a logical consequence of the inverse relationship between these two functions.

FUNCTION function-name
Identifies the particular function by name, and is valid only if there is exactly one function with the function-name. The function identified may have any number of parameters defined for it.

In dynamic SQL statements, the CURRENT SCHEMA special register is used as a qualifier for an unqualified object name. In static SQL statements the QUALIFIER precompile/bind option implicitly specifies the qualifier for unqualified object names.

If no function by this name exists in the named or implied schema, an error is raised (SQLSTATE 42704). If there is more than one specific instance of the function in the named or implied schema, an error is raised (SQLSTATE 42725). The standard function selection algorithm is not used.

FUNCTION function-name (data-tape,...)
Provides the function signature, which uniquely identifies the function to be used. The standard function selection algorithm is not used.

function-name
Specifies the name of the function. In dynamic SQL statements, the CURRENT SCHEMA special register is used as a qualifier for an unqualified object name. In static SQL statements the QUALIFIER precompile/bind option implicitly specifies the qualifier for unqualified object names.

(data-type,...)
The data-types specified here must match the data types specified in the CREATE FUNCTION statement in the corresponding position. Both the number of data types and the logical concatenation of the data types are used to identify the specific function.

If the data-type is unqualified, the type name is resolved by searching the schemas on the SQL path. This also applies to data type names specified for a REFERENCE type.

It is not necessary to specify the length, precision or scale for the parameterized data types. Instead an empty set of parentheses can be coded to indicate that these attributes should be ignored when looking for a data type match.

FLOAT() cannot be used (SQLSTATE 42601), since the parameter value indicates different data types (REAL or DOUBLE). However, if length, precision, or scale is coded, the value must exactly match that specified in the CREATE FUNCTION statement.

A type of FLOAT(n) does not need to match the defined value for n since 0<n<25 means REAL and 24<n<54 means DOUBLE. Matching occurs based on whether the type is REAL or DOUBLE. Note that the FOR BIT DATA attribute is not considered part of the signature for matching purposes. For example, a CHAR FOR BIT DATA specified in the signature would match a function defined with CHAR only.

If no function with the specified signature exists in the named or implied schema, an error is raised (SQLSTATE 42883).

SPECIFIC FUNCTION specific-name
Identifies the particular user-defined function, using a specific name either specified or defaulted to at function creation time.

In dynamic SQL statements, the CURRENT SCHEMA special register is used as a qualifier for an unqualified object name. In static SQL statements, the QUALIFIER precompile/bind option implicitly specifies the qualifier for unqualified object names. The specific-name must identify a specific function instance in the named or implied schema; otherwise, an error is raised (SQLSTATE 42704).

Notes

Examples

Example 1: Create two transform groups that associate the user-defined structured type polygon with a transform function customized for C and one specialized for Java.

   CREATE TRANSFORM FOR POLYGON
      mystruct1 (FROM SQL WITH FUNCTION myxform_sqlstruct,
                 TO SQL WITH FUNCTION myxform_structsql)
      myjava1   (FROM SQL WITH FUNCTION myxform_sqljava,
                 TO SQL WITH FUNCTION myxform_javasql )


[ Top of Page | Previous Page | Next Page ]