Bitstring
| Name | Aliases | Description |
|---|---|---|
BITSTRING | BIT | Variable-length strings of 1s and 0s |
Bitstrings are strings of 1s and 0s. The bit type data is of variable length. A bitstring value requires 1 byte for each group of 8 bits, plus a fixed amount to store some metadata.
By default bitstrings will not be padded with zeroes.
Bitstrings can be very large, having the same size restrictions as BLOBs.
Creating a Bitstring
A string encoding a bitstring can be cast to a BITSTRING:
Query
SELECT '101010'::BITSTRING AS b;Result
b-------- 101010Creating a BITSTRING with a predefined length is possible with the bitstring function. The resulting bitstring will be left-padded with zeroes.
Query
SELECT bitstring('0101011', 12) AS b;Result
b-------------- 000000101011Numeric values (integer and float values) can also be converted to a BITSTRING via casting. For example:
Query
SELECT 123::BITSTRING AS b;Result
b---------------------------------- 00000000000000000000000001111011Functions
See Bitstring Functions.