Next: Result Transforms, Previous: Types Conversion, Up: Top
A column definition, or def for short, associates a column name, its type and any additional options. It has the form:
(NAME TYPE [OPTIONS...])
name and type are symbols specifying the name and type of the
column, respectively (see Types Conversion). options are strings
passed directly to PostgreSQL as part of a CREATE TABLE
command. For
example, the status output of the rsync(1) program can be specified by the
form:
(define rsync-defs '((time timestamp) (error_condition text) (files text[]) (wrote int4) ; bytes (read text[][]) (rate float4) (total int4) ; bytes (speedup float4) (etc int4[])))
Likewise, here is an example that might be useful in keeping a table of
expenses (although probably using float4
is not a good idea for
monetary values):
(define expense-ledger-defs '((i serial) (date timestamp) (amount float4) (details text[])))
Note that there are no options in these examples. The components of a def can
be extracted with procedures in the postgres-col-defs
module, which can
be loaded like so:
(use-modules ((database postgres-col-defs) #:renamer (symbol-prefix-proc 'def:)))
In this example, we use the #:renamer
clause to systematically prefix
"def:" to the names that the client module would see (resulting in
def:column-name
and so on).
[NOTE: docs missing for column-name]
[NOTE: docs missing for type-name]
[NOTE: docs missing for type-options]
[NOTE: docs missing for validate-def]
There are two more convenience procedures, the first one useful in transforming the results of a query into Scheme objects (see Result Transforms):
[NOTE: docs missing for objectifiers]
[NOTE: docs missing for stringifiers]