database_doc: SQL data types

Next: Arbitrary Octave types, Previous: Concept, Up: Top [Index]

## 3 Representation in Octave of types defined by SQL

For types specific to database implementations, see Postgresql data types.

The last column indicates whether the SQL type is automatically deduced by this packages functions from the representation of the data in Octave. If not, the correct SQL type must be specified by the user if the data is sent from Octave to the database.

The listed names of SQL data types are those which are used by the functions of this package. They are sometimes different from the original SQL typenames, e.g. `int2`, `int4`, and `int8` instead of `smallint`, `integer`, and `bigint`, respectively. If not obvious, the original SQL typename is given in parantheses.

SQL | Octave | auto
--- | --- | ---
bool | logical scalar | yes
bytea (variable length binary string) | array of uint8, one-dimensional if converted from SQL data | yes
float8 | double scalar | yes
float4 | single scalar | yes
varchar | string | no
bpchar (char) | string | no
int2 | int16 scalar | yes
int4 | int32 scalar | yes
int8 | int64 scalar | yes
timestamp | 8-byte-time-value (see below), positive or negative difference to 2000-01-01 00:00 | no
timestamptz | as timestamp | no
time | 8-byte-time-value (see below) | no
timetz | 2-element cell array with 8-byte-time-value (see below, time of day) and int32 scalar (time zone in seconds, negative east of UTC) | no
date | int32 scalar, positive or negative difference to 2000-01-01 | no
interval | 3-element cell array with 8-byte-time-value (see below), int32 (days), and int32 (months) | no
bit | structure with fields `bitlen` (int32, number of valid bits) and `bits` (uint8 array, 8 bits per entry, first entry contains the leftmost bits, last entry may contain less than 8 bits) | no
varbit | as bit | yes
xml | string | no
any array | Structure with fields `data` (holding a cell-array with entries of a type corresponding to the SQL element type), `ndims` (holding the number of dimensions of the corresponding SQL array, since this can not be deduced from the dimensions of the Octave cell-array in all cases), and optionally (but always present in returned values) `lbounds` (a row vector of enumeration bases for all dimensions, default is `ones (1, ndims)`; enumeration bases different from `1` are supported e.g. by Postgresql). Array elements may not correspond to arrays in SQL (use additional dimensions for this), but may correspond to composite types, which is allowed to lead to arbitrarily deep nesting. | no
any composite type (row type) | One-dimensional cell-array with entries of types corresponding to the respective SQL types. Entries may also correspond to an array-type or composite type; this is allowed to lead to arbitrarily deep nesting. | no

8-byte-time-value: int64 scalar, representing microseconds, if server is configured for integer date/time; double scalar, representing seconds, if server is configured for float date/time. If the type (integer or float) of an input Octave variable for an 8-byte-time-value does not match the server configuration, there is no automatic conversion but an error is thrown.

Octaves `NA` corresponds to an SQL NULL value (not `NaN`, which is interpreted as a value of a float type!).

Next: Arbitrary Octave types, Previous: Concept, Up: Top [Index]