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.