Updated on 2024-06-03 GMT+08:00

Binary Types

Table 1 lists the binary types supported by GaussDB.

Table 1 Binary types

Name

Description

Storage Space

BLOB

Binary large object (BLOB).

Currently, BLOB only supports the following external access APIs:

  • DBE_LOB.GET_LENGTH
  • DBE_LOB.READ
  • DBE_LOB.WRITE
  • DBE_LOB.WRITE_APPEND
  • DBE_LOB.COPY
  • DBE_LOB.ERASE

For details about the APIs, see DBE_LOB.

For Ustore, the maximum size is 1 GB minus 1 byte. However, the size of the column description header and the size of the tuple (less than 1 GB minus 1 byte) where the column is located must also be considered. Therefore, the maximum size of the BLOB type may be less than 1 GB minus 1 byte.

When sql_compatibility is set to 'B', if b_format_version is set to '5.7' and b_format_dev_version is set to 's1', the BLOB type is mapped to the BYTEA type, and the alias is BYTEA.

For details about the storage specifications, see the BYTEA type.

TINYBLOB

MEDIUMBLOB

LONGBLOB

Binary large object (BLOB).

For details about the storage specifications, see the BYTEA type.

This type can be used only when sql_compatibility is set to 'B', b_format_version is set to '5.7', and b_format_dev_version is set to 's1'. The type is mapped to the BYTEA type, and the alias is BYTEA.

RAW

Variable-length hexadecimal string.

4 bytes plus the actual binary string. The maximum size is 1 GB minus 1 byte. However, the size of the column description header and the size of the tuple (less than 1 GB minus 1 byte) where the column is located must also be considered. Therefore, the maximum size of this type may be less than 1 GB minus 1 byte.

BYTEA

Variable-length binary string.

4 bytes plus the actual binary string. The maximum size is 1 GB minus 1 byte. However, the size of the column description header and the size of the tuple (less than 1 GB minus 1 byte) where the column is located must also be considered. Therefore, the maximum size of this type may be less than 1 GB minus 1 byte.

BYTEAWITHOUTORDERWITHEQUALCOL

Variable-length binary character string (new type for the encryption feature. If the encryption type of an encrypted column is specified as deterministic encryption, the column type is BYTEAWITHOUTORDERWITHEQUALCOL). The original data type is displayed when an encrypted table is printed by running the meta command.

4 bytes plus the actual binary string. The maximum value is 1,073,741,771 bytes (1 GB minus 53 bytes).

BYTEAWITHOUTORDERCOL

Variable-length binary character string (new type for the encryption feature. If the encryption type of an encrypted column is specified as random encryption, the column type is BYTEAWITHOUTORDERCOL). The original data type is displayed when an encrypted table is printed by running the meta command.

4 bytes plus the actual binary string. The maximum value is 1,073,741,771 bytes (1 GB minus 53 bytes).

_BYTEAWITHOUTORDERWITHEQUALCOL

Variable-length binary string, which is a new type for the encryption feature.

4 bytes plus the actual binary string. The maximum value is 1,073,741,771 bytes (1 GB minus 53 bytes).

_BYTEAWITHOUTORDERCOL

Variable-length binary string, which is a new type for the encryption feature.

4 bytes plus the actual binary string. The maximum value is 1,073,741,771 bytes (1 GB minus 53 bytes).

  • In addition to the size limit of each column, the total size of each tuple cannot exceed 1 GB minus 1 byte.
  • BYTEAWITHOUTORDERWITHEQUALCOL, BYTEAWITHOUTORDERCOL, _BYTEAWITHOUTORDERWITHEQUALCOL, and _BYTEAWITHOUTORDERCOL cannot be directly used to create a table.
  • RAW(n), where n indicates the recommended byte length and is not used to verify the byte length of the input raw type.
  • When sql_compatibility is set to 'B', if b_format_version is set to '5.7' and b_format_dev_version is set to 's1', the TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB types are displayed as BYTEA. For example, when the table structure is queried, the TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB types are displayed as BYTEA.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- Create a table.
gaussdb=# CREATE TABLE blob_type_t1 
(
    BT_COL1 INTEGER,
    BT_COL2 BLOB,
    BT_COL3 RAW,
    BT_COL4 BYTEA
) ;

-- Insert data.
gaussdb=# INSERT INTO blob_type_t1 VALUES(10,empty_blob(),
HEXTORAW('DEADBEEF'),E'\\xDEADBEEF');

-- Query data in the table.
gaussdb=# SELECT * FROM blob_type_t1;
 bt_col1 | bt_col2 | bt_col3  |  bt_col4   
---------+---------+----------+------------
      10 |         | DEADBEEF | \xdeadbeef
(1 row)

-- Drop the table.
gaussdb=# DROP TABLE blob_type_t1;

-- Example: TINYBLOB, MEDIUMBLOB, and LONGBLOB types
gaussdb=# CREATE DATABASE gaussdb_m WITH dbcompatibility  'B';
gaussdb=# \c gaussdb_m
-- Set compatible version control parameters.
gaussdb_m=# SET b_format_version='5.7';
gaussdb_m=# SET b_format_dev_version='s1';
-- Create a table.
gaussdb_m=# CREATE TABLE t1(a tinyblob, b blob, m mediumblob, l longblob);
-- Insert data.
gaussdb_m=# INSERT INTO t1 VALUES ('tinyblobtest', 'blobtest', 'mediumblobtest', 'longblobtest');
-- Query data in the table.
gaussdb_m=# SELECT * FROM t1;
      a       |    b     |       m        |      l
--------------+----------+----------------+--------------
 tinyblobtest | blobtest | mediumblobtest | longblobtest
(1 row)

-- Drop the table and database.
gaussdb_m=# DROP TABLE t1;
gaussdb_m=# \c postgres;
gaussdb=# DROP DATABASE gaussdb_m;
-- Reset parameters.
gaussdb=# \c RESET ALL;