Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

Bit String Data Types

Syntax

bit_string_data_type ::

BIT

| BINARY [(length)]

| VARBINARY [(length)]

| LVARBINARY

Arguments

  • BIT

    Type BIT corresponds to a single bit value of 0 or 1.

    c-treeSQL statements can assign and compare values in BIT columns to and from columns of types BINARY, VARBINARY, TINYINT, SMALLINT, INTEGER, and Character types. However, in assignments from BINARY, VARBINARY, and LVARBINARY, the value of the first four bits must be 0001 or 0000.

    No arithmetic operations are allowed on BIT columns.

  • BINARY [(length)]

    Type BINARY corresponds to a bit field of the specified length of bytes. The default length is 1 byte. The maximum length is 65,500 bytes (8192 bytes prior to V12).

    In interactive SQL, INSERT statements must use a special format to store values in BINARY columns. They can specify the binary values as a bit string, hexadecimal string, or character string. INSERT statements must enclose binary values in single-quote marks, preceded by b for a bit string and x for a hexadecimal string:



    Prefix


    Suffix

    Example
    (for same 2 byte data)

    bit string

    b'

    '

    b'1010110100010000'

    hex string

    x'

    '

    x'ad10'

    char string

     

    '

    'ad10'

    FairCom DB SQL interprets a character string as the character representation of a hexadecimal string.

    If the data inserted into a BINARY column is less than the length specified, FairCom DB SQL pads it with zeroes.

    BINARY data can be assigned and compared to and from columns of type BIT, VARBINARY, and Character types. No arithmetic operations are allowed.

  • VARBINARY [(length)]

    Type VARBINARY corresponds to a variable-length bit field with the maximum length specified. The default length is one and the maximum length is 65,500 (8192 prior to V12). Otherwise, VARBINARY columns have the same characteristics as BINARY.

  • LVARBINARY

    The LVARBINARY data type corresponds to an arbitrarily long bit field with the maximum length of less than two gigabytes. The LVARBINARY data type is recommended for BLOB support.

    The arbitrary size and unstructured nature of long data types restrict where they can be used.

    • Long columns are allowed in select lists of query expressions and in INSERT statements.
    • INSERT statements can store data from columns of any type except LVARCHAR into a LVARBINARY column, but LVARBINARY data cannot be stored in any other type.
    • CONTAINS predicates are the only predicates that allow long columns.
    • Conditional expressions, arithmetic expressions, and functions cannot specify long columns.
    • UPDATE statements cannot specify long columns.

TOCIndex