Next: , Up: Types Conversion


11.1 Consulting Existing Type Converters

To see what type converters are already defined, use the dbcoltypes procedure. To get a type-converter object that encapsulates the stringifier, the objectifier and the default, use the procedure dbcoltype-lookup. The components of the returned object can be read using the dbcoltype:FOO procedures.

— Procedure: dbcoltypes

Return names of all registered type converters.

— Procedure: dbcoltype-lookup type-name

Return a type-converter object given its type-name, a symbol. Return #f if no such t-c object by that name exists.

— Procedure: dbcoltype:stringifier tc

Extract stringifier from the type-converter object tc.

— Procedure: dbcoltype:objectifier tc

Extract objectifier from the type-converter object tc.

— Procedure: dbcoltype:default tc

Extract default string from the type-converter object tc.

Here is a simple example that uses dbcoltype-lookup and dbcoltype:objectifier to convert a text[][] value into a nested list:

     (let ((raw (pg-getvalue result 0 0))
           (conv (dbcoltype:objectifier (dbcoltype-lookup 'text[][]))))
       (format #t "~A\n~A\n" raw (conv raw)))
     
     -| {{a,b},{c,d}}
     -| (("a" "b") ("c" "d"))

Note that even though the type is an "array", as implied by the square brackets, the result is a list. This is mostly due to a limitation in PostgreSQL: dimensionality is not stored for array types, so the conversion cannot be done in a random-access manner. Perhaps this will change in the future.

Builtin Converters

Here is the set of builtin converters and their default values.

     smallint     "0"                    serial8      "0"
     integer      "0"                    varchar      #f
     bigint       "0"                    character    #f
     int          "0"                    char         "?"
     int2         "0"                    text         ""
     int4         "0"                    name         "???"
     int8         "0"                    bytea        #f
     numeric      "0"                    timestamp    "1970-01-01 00:00:00"
     decimal      "0"                    boolean      "f"
     real         "0.0"                  bool         "f"
     double       "0.0"                  inet         "0.0.0.0"
     float4       "0.0"                  cidr         "0.0.0.0"
     float8       "0.0"                  inet-host    "127.0.0.1"
     serial       "0"                    macaddr      "00:00:00:00:00:00"
     bigserial    "0"                    oid          "-1"
     serial4      "0"                    aclitem      "?"

Here are the array variants:

     text[]
     text[][]
     int4[]
     aclitem[]