↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / 数据类型

bit varying

variable-length bit string

当前阅读 PG 18·选择有来源记录的版本

此版本暂无所选语言的定义,以下显示原始英文内容。

Catalog name
pg_catalog.varbit
Type OID
1562
Type kind
Base type
Declared length
Variable length (varlena)
Storage strategy
extended
Input function
varbit_in
Output function
varbit_out
aliases
varbit, varbit [ ( n ) ]
casts
map[castcontext:i castfunc:0 castmethod:b castsource:bit casttarget:varbit], map[castcontext:i castfunc:0 castmethod:b castsource:varbit casttarget:bit], map[castcontext:i castfunc:varbit castmethod:f castsource:varbit casttarget:varbit]
coverage
source inventory; exact declared input types for operator classes
manual documentation
dedicated family chapter
manual path
datatype-bit.html
ranges
未知
signature
bit varying [ ( n ) ]

版本定义 PG 18

8.10. 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(n) and bit varying(n), where n is a positive integer.

bit type data must match the length n exactly; it is an error to attempt to store shorter or longer bit strings. bit varying data is of variable length up to the maximum length n; longer strings will be rejected. Writing bit without a length is equivalent to bit(1), while bit varying without a length specification means unlimited length.

Note

If one explicitly casts a bit-string value to bit(n), it will be truncated or zero-padded on the right to be exactly n bits, without raising an error. Similarly, if one explicitly casts a bit-string value to bit varying(n), it will be truncated on the right if it is more than n bits.

Refer to Section 4.1.2.5 for information about the syntax of bit string constants. Bit-logical operators and string manipulation functions are available; see Section 9.6.

Example 8.3. 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 2 does not match type bit(3)

INSERT INTO test VALUES (B'10'::bit(3), B'101');
SELECT * FROM test;

  a  |  b
-----+-----
 101 | 00
 100 | 101


A bit string value requires 1 byte for each group of 8 bits, plus 5 or 8 bytes overhead depending on the length of the string (but long values may be compressed or moved out-of-line, as explained in Section 8.3 for character strings).

比较版本

完整来源事实

catalog

{"array_type_name":"_varbit","array_type_oid":"1563","descr":"variable-length bit string","oid":"1562","typacl":"_null_","typalign":"i","typanalyze":"-","typarray":"0","typbasetype":"0","typbyval":"f","typcategory":"V","typcollation":"0","typdefault":"_null_","typdefaultbin":"_null_","typdelim":"','","typelem":"0","typinput":"varbit_in","typisdefined":"t","typispreferred":"t","typlen":"-1","typmodin":"varbittypmodin","typmodout":"varbittypmodout","typname":"varbit","typnamespace":"pg_catalog","typndims":"0","typnotnull":"f","typoutput":"varbit_out","typowner":"POSTGRES","typreceive":"varbit_recv","typrelid":"0","typsend":"varbit_send","typstorage":"x","typsubscript":"-","typtype":"b","typtypmod":"-1"}

operator classes

map[opcdefault:t opcfamily:btree/varbit_ops opcintype:varbit opckeytype:0 opcmethod:btree opcname:varbit_ops opcnamespace:pg_catalog opcowner:POSTGRES], map[opcdefault:t opcfamily:brin/varbit_minmax_ops opcintype:varbit opckeytype:varbit opcmethod:brin opcname:varbit_minmax_ops opcnamespace:pg_catalog opcowner:POSTGRES]

operators

map[descr:concatenate oid:1797 oprcanhash:f oprcanmerge:f oprcode:bitcat oprcom:0 oprjoin:- oprkind:b oprleft:varbit oprname:|| oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:varbit oprright:varbit], map[descr:equal oid:1804 oprcanhash:f oprcanmerge:t oprcode:varbiteq oprcom:=(varbit,varbit) oprjoin:eqjoinsel oprkind:b oprleft:varbit oprname:= oprnamespace:pg_catalog oprnegate:<>(varbit,varbit) oprowner:POSTGRES oprrest:eqsel oprresult:bool oprright:varbit], map[descr:not equal oid:1805 oprcanhash:f oprcanmerge:f oprcode:varbitne oprcom:<>(varbit,varbit) oprjoin:neqjoinsel oprkind:b oprleft:varbit oprname:<> oprnamespace:pg_catalog oprnegate:=(varbit,varbit) oprowner:POSTGRES oprrest:neqsel oprresult:bool oprright:varbit], map[descr:less than oid:1806 oprcanhash:f oprcanmerge:f oprcode:varbitlt oprcom:>(varbit,varbit) oprjoin:scalarltjoinsel oprkind:b oprleft:varbit oprname:< oprnamespace:pg_catalog oprnegate:>=(varbit,varbit) oprowner:POSTGRES oprrest:scalarltsel oprresult:bool oprright:varbit], map[descr:greater than oid:1807 oprcanhash:f oprcanmerge:f oprcode:varbitgt oprcom:<(varbit,varbit) oprjoin:scalargtjoinsel oprkind:b oprleft:varbit oprname:> oprnamespace:pg_catalog oprnegate:<=(varbit,varbit) oprowner:POSTGRES oprrest:scalargtsel oprresult:bool oprright:varbit], map[descr:less than or equal oid:1808 oprcanhash:f oprcanmerge:f oprcode:varbitle oprcom:>=(varbit,varbit) oprjoin:scalarlejoinsel oprkind:b oprleft:varbit oprname:<= oprnamespace:pg_catalog oprnegate:>(varbit,varbit) oprowner:POSTGRES oprrest:scalarlesel oprresult:bool oprright:varbit], map[descr:greater than or equal oid:1809 oprcanhash:f oprcanmerge:f oprcode:varbitge oprcom:<=(varbit,varbit) oprjoin:scalargejoinsel oprkind:b oprleft:varbit oprname:>= oprnamespace:pg_catalog oprnegate:<(varbit,varbit) oprowner:POSTGRES oprrest:scalargesel oprresult:bool oprright:varbit]

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

正文语言: en · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f