↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 数据类型 / 数值

integer

有符号四字节整数

当前查看 PostgreSQL 18。

中文定义与说明

有符号四字节整数

同版本中文手册节选

数字类型包括 2、4、8 字节的整数,4、8 字节的浮点数,以及可选精度的小数。表 8.2 列出了所有可用类型。

数字类型常量的语法在第 4.1.2 节里描述。数字类型有一整套对应的算术操作符和函数。相关信息请参考第 9 章。下面的几节详细描述这些类型。

查看完整中文手册与上下文。

PG10–20 核心源码清单。类型转换与操作符类列出源码显式声明的关系;缺少记录不能排除通过其他机制进行转换或使用索引。

定义

SQL 名称与别名: int4, int

有符号四字节整数

integer
目录名称
pg_catalog.int4
类型 OID
23
类型种类
基础类型
声明长度
4 字节
存储策略
plain
输入函数
int4in
输出函数
int4out
手册中的声明
integer
存储大小
4 字节
手册说明
整数的常用选择
范围
-2147483648 到 +2147483647

系统目录属性

此构建的源码初始化值。字段含义参见 pg_type 。包含头文件默认值;依赖构建的常量保留符号形式,不作为服务器运行时实测。

oid
23
descr
-2 billion to 2 billion integer, 4-byte storage
typacl
_null_
typlen
4
typelem
0
typname
int4
typsend
int4send
typtype
b
typalign
i
typarray
0
typbyval
t
typdelim
','
typinput
int4in
typmodin
-
typndims
0
typowner
POSTGRES
typrelid
0
typmodout
-
typoutput
int4out
typtypmod
-1
typanalyze
-
typdefault
_null_
typnotnull
f
typreceive
int4recv
typstorage
p
typbasetype
0
typcategory
N
typcollation
0
typisdefined
t
typnamespace
pg_catalog
typsubscript
-
typdefaultbin
_null_
array_type_oid
1007
typispreferred
f
array_type_name
_int4

类型转换 44

与此类型相关的显式 pg_cast 记录。PostgreSQL 还支持 pg_cast 之外的类型转换,缺少记录不能证明转换不可能。

源类型目标类型转换上下文转换方式函数
int8int4赋值函数int4(int8)
int2int4隐式函数int4(int2)
int4int8隐式函数int8(int4)
int4int2赋值函数int2(int4)
int4float4隐式函数float4(int4)
int4float8隐式函数float8(int4)
int4numeric隐式函数numeric(int4)
float4int4赋值函数int4(float4)
float8int4赋值函数int4(float8)
numericint4赋值函数int4(numeric)
int4money赋值函数money(int4)
int4bool显式函数bool(int4)
boolint4显式函数int4(bool)
int4oid隐式二进制兼容0
oidint4赋值二进制兼容0
int4regproc隐式二进制兼容0
regprocint4赋值二进制兼容0
int4regprocedure隐式二进制兼容0
regprocedureint4赋值二进制兼容0
int4regoper隐式二进制兼容0
regoperint4赋值二进制兼容0
int4regoperator隐式二进制兼容0
regoperatorint4赋值二进制兼容0
int4regclass隐式二进制兼容0
regclassint4赋值二进制兼容0
int4regcollation隐式二进制兼容0
regcollationint4赋值二进制兼容0
int4regtype隐式二进制兼容0
regtypeint4赋值二进制兼容0
int4regconfig隐式二进制兼容0
regconfigint4赋值二进制兼容0
int4regdictionary隐式二进制兼容0
regdictionaryint4赋值二进制兼容0
int4regrole隐式二进制兼容0
regroleint4赋值二进制兼容0
int4regnamespace隐式二进制兼容0
regnamespaceint4赋值二进制兼容0
int4bytea显式函数bytea(int4)
byteaint4显式函数int4(bytea)
charint4显式函数int4(char)
int4char显式函数char(int4)
int4bit显式函数bit(int4,int4)
bitint4显式函数int4(bit)
jsonbint4显式函数int4(jsonb)

运算符重载 79

每种操作数签名均为独立重载。实现函数和返回类型来自同一源码构建。

运算符左操作数右操作数返回类型含义实现函数
=int4int8bool等于。int48eq
<>int4int8bool不等于。int48ne
<int4int8bool小于。int48lt
>int4int8bool大于。int48gt
<=int4int8bool小于或等于。int48le
>=int4int8bool大于或等于。int48ge
=int4int4bool等于。int4eq
<int4int4bool小于。int4lt
=xidint4bool等于。xideqint4
<>xidint4bool不等于。xidneqint4
=int8int4bool等于。int84eq
<>int8int4bool不等于。int84ne
<int8int4bool小于。int84lt
>int8int4bool大于。int84gt
<=int8int4bool小于或等于。int84le
>=int8int4bool大于或等于。int84ge
*int4int4int4相乘。int4mul
<>int4int4bool不等于。int4ne
>int4int4bool大于。int4gt
<=int4int4bool小于或等于。int4le
>=int4int4bool大于或等于。int4ge
/int4int4int4相除。int4div
%int4int4int4取余。int4mod
=int2int4bool等于。int24eq
=int4int2bool等于。int42eq
<int2int4bool小于。int24lt
<int4int2bool小于。int42lt
>int2int4bool大于。int24gt
>int4int2bool大于。int42gt
<>int2int4bool不等于。int24ne
<>int4int2bool不等于。int42ne
<=int2int4bool小于或等于。int24le
<=int4int2bool小于或等于。int42le
>=int2int4bool大于或等于。int24ge
>=int4int2bool大于或等于。int42ge
*int2int4int4相乘。int24mul
*int4int2int4相乘。int42mul
/int2int4int4相除。int24div
/int4int2int4相除。int42div
+int4int4int4相加。int4pl
+int2int4int4相加。int24pl
+int4int2int4相加。int42pl
-int4int4int4相减。int4mi
-int2int4int4相减。int24mi
-int4int2int4相减。int42mi
-无(一元)int4int4取负。int4um
+int8int4int8相加。int84pl
-int8int4int8相减。int84mi
*int8int4int8相乘。int84mul
/int8int4int8相除。int84div
+int4int8int8相加。int48pl
-int4int8int8相减。int48mi
*int4int8int8相乘。int48mul
/int4int8int8相除。int48div
@无(一元)int4int4绝对值。int4abs
*moneyint4money相乘。cash_mul_int4
/moneyint4money相除。cash_div_int4
*int4moneymoney相乘。int4_mul_cash
+dateint4date相加。date_pli
-dateint4date相减。date_mii
<<bitint4bit按位左移。bitshiftleft
>>bitint4bit按位右移。bitshiftright
<<int2int4int2按位左移。int2shl
>>int2int4int2按位右移。int2shr
&int4int4int4按位与。int4and
|int4int4int4按位或。int4or
#int4int4int4按位异或。int4xor
~无(一元)int4int4按位取反。int4not
<<int4int4int4按位左移。int4shl
>>int4int4int4按位右移。int4shr
<<int8int4int8按位左移。int8shl
>>int8int4int8按位右移。int8shr
+无(一元)int4int4一元正号。int4up
+int4datedate相加。integer_pl_date
->jsonint4json获取 JSON 数组元素。json_array_element
->>jsonint4text获取 JSON 数组元素并返回文本。json_array_element_text
->jsonbint4jsonb获取 jsonb 数组元素。jsonb_array_element
->>jsonbint4text获取 jsonb 数组元素并返回文本。jsonb_array_element_text
-jsonbint4jsonb删除数组元素。jsonb_delete(jsonb,int4)

操作符类 5

声明输入类型与此类型相符的操作符类。多态操作符类、类型转换和表达式索引还可能提供其他索引路径;不能仅凭此表判断是否支持索引。

操作符类索引方法输入类型操作符族默认存储类型
int4_opsbtreeint4btree/integer_ops是与输入类型相同
int4_opshashint4hash/integer_ops是与输入类型相同
int4_minmax_opsbrinint4brin/integer_minmax_ops是int4
int4_minmax_multi_opsbrinint4brin/integer_minmax_multi_ops否int4
int4_bloom_opsbrinint4brin/integer_bloom_ops否int4

版本比较

PostgreSQL 17 → 18。属性比较不包含构建标识和说明正文;原始目录字段与源描述保留原文。

类型转换

PostgreSQL 17

[{"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "oid", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regclass", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regcollation", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regconfig", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regdictionary", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regnamespace", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regoper", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regoperator", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regproc", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regprocedure", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regrole", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regtype", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int2(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int4(float4)", "castmethod": "f", "castsource": "float4", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(float8)", "castmethod": "f", "castsource": "float8", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(int8)", "castmethod": "f", "castsource": "int8", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(numeric)", "castmethod": "f", "castsource": "numeric", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "money(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "money"}, {"castcontext": "e", "castfunc": "bit(int4,int4)", "castmethod": "f", "castsource": "int4", "casttarget": "bit"}, {"castcontext": "e", "castfunc": "bool(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "bool"}, {"castcontext": "e", "castfunc": "char(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "char"}, {"castcontext": "e", "castfunc": "int4(bit)", "castmethod": "f", "castsource": "bit", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(bool)", "castmethod": "f", "castsource": "bool", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(char)", "castmethod": "f", "castsource": "char", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(jsonb)", "castmethod": "f", "castsource": "jsonb", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "oid"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regclass"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regcollation"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regconfig"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regdictionary"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regnamespace"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regoper"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regoperator"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regproc"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regprocedure"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regrole"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regtype"}, {"castcontext": "i", "castfunc": "float4(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "float4"}, {"castcontext": "i", "castfunc": "float8(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "float8"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "int8(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int8"}, {"castcontext": "i", "castfunc": "numeric(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "numeric"}]

PostgreSQL 18

[{"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "oid", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regclass", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regcollation", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regconfig", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regdictionary", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regnamespace", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regoper", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regoperator", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regproc", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regprocedure", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regrole", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "0", "castmethod": "b", "castsource": "regtype", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int2(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int4(float4)", "castmethod": "f", "castsource": "float4", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(float8)", "castmethod": "f", "castsource": "float8", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(int8)", "castmethod": "f", "castsource": "int8", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "int4(numeric)", "castmethod": "f", "castsource": "numeric", "casttarget": "int4"}, {"castcontext": "a", "castfunc": "money(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "money"}, {"castcontext": "e", "castfunc": "bit(int4,int4)", "castmethod": "f", "castsource": "int4", "casttarget": "bit"}, {"castcontext": "e", "castfunc": "bool(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "bool"}, {"castcontext": "e", "castfunc": "bytea(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "bytea"}, {"castcontext": "e", "castfunc": "char(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "char"}, {"castcontext": "e", "castfunc": "int4(bit)", "castmethod": "f", "castsource": "bit", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(bool)", "castmethod": "f", "castsource": "bool", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(bytea)", "castmethod": "f", "castsource": "bytea", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(char)", "castmethod": "f", "castsource": "char", "casttarget": "int4"}, {"castcontext": "e", "castfunc": "int4(jsonb)", "castmethod": "f", "castsource": "jsonb", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "oid"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regclass"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regcollation"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regconfig"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regdictionary"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regnamespace"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regoper"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regoperator"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regproc"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regprocedure"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regrole"}, {"castcontext": "i", "castfunc": "0", "castmethod": "b", "castsource": "int4", "casttarget": "regtype"}, {"castcontext": "i", "castfunc": "float4(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "float4"}, {"castcontext": "i", "castfunc": "float8(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "float8"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "int8(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int8"}, {"castcontext": "i", "castfunc": "numeric(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "numeric"}]

文档与源码

构建
18.6 · https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
指纹
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

相关条目

全部数据类型 · 下载此版本 JSON · 最早收录的样本不代表该类型的实际引入版本。