Storing column length

The collength column value depends on the data type of the column.

Integer-based data types

A collength value for a BIGINT, BIGSERIAL, DATE, INTEGER, INT8, SERIAL, SERIAL8, or SMALLINT column is machine-independent. The database server uses the following lengths for these integer-based data types of the SQL language.
Integer-based data types Length (in bytes)
SMALLINT 2
DATE, INTEGER, and SERIAL 4
INT8 and SERIAL8 10
BIGINT and BIGSERIAL 8

Varying-length character data types

For HCL OneDB™ columns of the LVARCHAR type, collength has the value of max from the data type declaration, or 2048 if no maximum was specified.

For VARCHAR or NVARCHAR columns, the max_size and min_space values are encoded in the collength column using one of these formulas:
  • If the collength value is positive:
    collength = (min_space * 256) + max_size
  • If the collength value is negative:
    collength + 65536 = (min_space * 256) + max_size

Time data types

As noted previously, DATE columns have a value of 4 in the collength column.

For columns of type DATETIME or INTERVAL, collength is determined using the following formula:
(length * 256) + (first_qualifier * 16) + last_qualifier
The length is the physical length of the DATETIME or INTERVAL field, and first_qualifier and last_qualifier have values that the following table shows.
Field qualifier Value Field qualifier Value
YEAR 0 FRACTION(1) 11
MONTH 2 FRACTION(2) 12
DAY 4 FRACTION(3) 13
HOUR 6 FRACTION(4) 14
MINUTE 8 FRACTION(5) 15
SECOND 10

For example, if a DATETIME YEAR TO MINUTE column has a length of 12 (such as YYYY:DD:MO:HH:MI), a first_qualifier value of 0 (for YEAR), and a last_qualifier value of 8 (for MINUTE), then the collength value is 3080 (from (256 * 12) + (0 * 16) + 8).

Fixed-point data types

The collength value for a MONEY or DECIMAL (p, s) column can be calculated using the following formula:
(precision * 256) + scale

Simple-large-object data types

If the data type of the column is BYTE or TEXT, collength holds the length of the descriptor.