![]() The receive function can be declared as taking one argument of type internal, or as taking three arguments of types internal, oid, integer. (For example, the standard integer data types use network byte order as the external binary representation, while the internal representation is in the machine's native byte order.) The receive function should perform adequate checking to ensure that the value is valid. The binary representation should be chosen to be cheap to convert to internal form, while being reasonably portable. If this function is not supplied, the type cannot participate in binary input. The optional receive_function converts the type's external binary representation to the internal representation. Output functions are not invoked for NULL values. The output function must return type cstring. (This case is mainly meant to support domain input functions, which might need to reject NULL inputs.) The output function must be declared as taking one argument of the new data type. The function must still return NULL in this case, unless it raises an error. Usually, an input function should be declared STRICT if it is not, it will be called with a NULL first parameter when reading a NULL input value. The input function must return a value of the data type itself. The first argument is the input text as a C string, the second argument is the type's own OID (except for array types, which instead receive their element type's OID), and the third is the typmod of the destination column, if known (-1 will be passed if not). The input function can be declared as taking one argument of type cstring, or as taking three arguments of types cstring, oid, integer. output_function performs the reverse transformation. The input_function converts the type's external textual representation to the internal representation used by the operators and functions defined for the type. ![]() Generally these functions have to be coded in C or another low-level language. The support functions input_function and output_function are required, while the functions receive_function, send_function, type_modifier_input_function, type_modifier_output_function, analyze_function, and subscript_function are optional. You must register two or more functions (using CREATE FUNCTION) before defining the type. The parameters can appear in any order, not only that illustrated above, and most are optional. (This restriction is made because an erroneous type definition could confuse or even crash the server.) To create a new base type, you must be a superuser. The fourth form of CREATE TYPE creates a new base type (scalar type). Otherwise, the multirange type name is formed by appending a _multirange suffix to the range type name. If the range type name contains the substring range, then the multirange type name is formed by replacement of the range substring with multirange in the range type name. If not specified, this name is chosen automatically as follows. The optional multirange_type_name parameter specifies the name of the corresponding multirange type. ![]() While this is optional, providing it allows much greater efficiency of GiST indexes on columns of the range type. The optional subtype_diff function must take two values of the subtype type as argument, and return a double precision value representing the difference between the two given values. This automatically replaces the shell type entry with a valid range type. Then the function can be declared using the shell type as argument and result, and finally the range type can be declared using the same name. This is done by issuing the command CREATE TYPE name, with no additional parameters. To do this, you must first create a shell type, which is a placeholder type that has no properties except a name and an owner. Creating a canonical function is a bit tricky, since it must be defined before the range type can be declared. This is used to convert range values to a canonical form, when applicable. The optional canonical function must take one argument of the range type being defined, and return a value of the same type. If the subtype is collatable, and you want to use a non-default collation in the range's ordering, specify the desired collation with the collation option. Normally the subtype's default b-tree operator class is used to determine ordering to use a non-default operator class, specify its name with subtype_opclass. The range type's subtype can be any type with an associated b-tree operator class (to determine the ordering of values for the range type). The third form of CREATE TYPE creates a new range type, as described in Section 8.17.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |