This page in other versions: 8.4 / 9.0 / 9.1 / 9.2 / 9.3  |  Development versions: devel / 9.4  |  Unsupported versions: 7.1 / 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3

3.8. Bit String Types

Bit strings are strings of 1's and 0's. They can be used to store or visualize bit masks. There are two SQL bit types: BIT(x) and BIT VARYING(x); the x specifies the maximum length. BIT type data is automatically padded with 0's on the right to the maximum length, BIT VARYING is of variable length. BIT without length is equivalent to BIT(1), BIT VARYING means unlimited length. Input data that is longer than the allowed length will be truncated. Refer to Section 1.1.2.2 for information about the syntax of bit string constants. Bit-logical operators and string manipulation functions are available; see Chapter 4.

Some examples:

CREATE TABLE test (a BIT(3), b BIT VARYING(5));
INSERT INTO test VALUES (B'101', B'00');
SELECT SUBSTRING(b FROM 1 FOR 2) FROM test;
Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group