Using Bit data type : Bit « Data Type « PostgreSQL






Using Bit data type

postgres=#
postgres=# CREATE TABLE test (a BIT(3), b BIT VARYING(5));
CREATE TABLE
postgres=#
postgres=# INSERT INTO test VALUES (B'101', B'00');
INSERT 0 1
postgres=# INSERT INTO test VALUES (B'10', B'101');
ERROR:  bit string length 2 does not match type bit(3)
postgres=# INSERT INTO test VALUES (B'10'::bit(3), B'101');
INSERT 0 1
postgres=# SELECT * FROM test;
  a  |  b
-----+-----
 101 | 00
 100 | 101
(2 rows)

postgres=#
postgres=#
postgres=# drop table test;
DROP TABLE
postgres=#

           
       








Related examples in the same category