From efcecd9eca884776137b156a3f1f93c23b98a648 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 22 May 2001 16:37:17 +0000 Subject: Make bit and bit varying types reject too long input. (They already tried to do that, but inconsistently.) Make bit type reject too short input, too, per SQL. Since it no longer zero pads, 'zpbit*' has been renamed to 'bit*' in the source, hence initdb. --- doc/src/sgml/datatype.sgml | 50 +++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index bbbc85197bb..e86614f2ef7 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -2276,30 +2276,52 @@ SELECT * FROM test1 WHERE a; 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 x); where + x is a positive integer. + + + + BIT type data must match the length + x exactly; it is an error to attempt to + store shorter or longer bit strings. BIT VARYING is + of variable length up to the maximum length + x; longer strings will be rejected. + BIT without length is equivalent to + BIT(1), BIT VARYING without length + specification means unlimited length. + + + + + Prior to PostgreSQL 7.2, BIT type data was + zero-padded on the right. This was changed to comply with the + SQL standard. To implement zero-padded bit strings, a + combination of the concatenation operator and the + substring function can be used. + + + + + Refer to for information about the syntax of bit string constants. Bit-logical operators and string manipulation functions are available; see . - - - Some examples: + + Using the bit string types + CREATE TABLE test (a BIT(3), b BIT VARYING(5)); INSERT INTO test VALUES (B'101', B'00'); +INSERT INTO test VALUES (B'10', B'101'); + +ERROR: bit string length does not match type bit(3) + SELECT SUBSTRING(b FROM 1 FOR 2) FROM test; - - + -- cgit v1.2.3