Home | Previous Page | Next Page   System Catalog Tables > SYSCOLUMNS >

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, 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
SERIAL

4
4
4

BIGINT, INT8
SERIAL8

8 (XPS)
8 (XPS)

INT8
SERIAL8

10 (IDS)
10 (IDS)

Varying-Length Character Data Types

For Dynamic Server 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:

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.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]