This topic describes the binary data types in PolarDB for PostgreSQL(Compatible with Oracle) that can be stored by binary strings.

Table 1. Binary large objects
Data typeLengthDescription
BINARYThe same as the length of the binary string.The fixed-length binary string. The string must be 1 to 8,300 bytes in length.
BLOBThe actual binary string plus 1 byte if the binary string is less than 127 bytes in length. If the binary string is greater than or equal to 127 bytes in length, the length equals the actual binary string plus 4 bytes.The variable-length binary string.
VARBINARYThe same as the length of the binary string. The variable-length binary string. The string must be from 1 to 8,300 bytes in length.
BYTEA1 or 4 bytes plus the actual length of the binary string. The variable-length binary string.
A binary string is a sequence of octets or bytes. Binary strings are distinguished from character strings in the following two aspects:
  • Binary strings can store octets of zero values and other non-displayable octets whose length is out of the range from 32 to 126 bytes.
  • Operations on binary strings process the actual bytes, whereas the encoding and processing of character strings depend on local settings.

BYTEA type

The BYTEA type supports two external input and output formats: hex format and PostgreSQL escape format.
  • The hex format encodes binary data in a way where each byte contains 2 hexadecimal digits. The most significant four bits are at the beginning. A binary string starts with a \x (as distinguished from the escape format).
  • The escape format is a traditional PostgreSQL format. It uses ASCII character sequences to represent binary strings, and converts binary strings that cannot be represented as ASCII characters into special escape sequences. Theoretically, this format is convenient if the characters are meaningful. In practice, however, this format blurs the distinction between binary strings and character strings. The escape mechanism is complicated. We recommend that you avoid this format for new applications.