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 。包含头文件默认值;依赖构建的常量保留符号形式,不作为服务器运行时实测。
oid23descr-2 billion to 2 billion integer, 4-byte storagetypacl_null_typlen4typelem0typnameint4typsendint4sendtyptypebtypalignityparray0typbyvalttypdelim','typinputint4intypmodin-typndims0typownerPOSTGREStyprelid0typmodout-typoutputint4outtyptypmod-1typanalyze-typdefault_null_typnotnullftypreceiveint4recvtypstorageptypbasetype0typcategoryNtypcollation0typisdefinedttypnamespacepg_catalogtypsubscript-typdefaultbin_null_array_type_oid1007typispreferredfarray_type_name_int4
类型转换 44
与此类型相关的显式 pg_cast 记录。PostgreSQL 还支持 pg_cast 之外的类型转换,缺少记录不能证明转换不可能。
| 源类型 | 目标类型 | 转换上下文 | 转换方式 | 函数 |
|---|---|---|---|---|
int8 | int4 | 赋值 | 函数 | int4(int8) |
int2 | int4 | 隐式 | 函数 | int4(int2) |
int4 | int8 | 隐式 | 函数 | int8(int4) |
int4 | int2 | 赋值 | 函数 | int2(int4) |
int4 | float4 | 隐式 | 函数 | float4(int4) |
int4 | float8 | 隐式 | 函数 | float8(int4) |
int4 | numeric | 隐式 | 函数 | numeric(int4) |
float4 | int4 | 赋值 | 函数 | int4(float4) |
float8 | int4 | 赋值 | 函数 | int4(float8) |
numeric | int4 | 赋值 | 函数 | int4(numeric) |
int4 | money | 赋值 | 函数 | money(int4) |
int4 | bool | 显式 | 函数 | bool(int4) |
bool | int4 | 显式 | 函数 | int4(bool) |
int4 | oid | 隐式 | 二进制兼容 | 0 |
oid | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regproc | 隐式 | 二进制兼容 | 0 |
regproc | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regprocedure | 隐式 | 二进制兼容 | 0 |
regprocedure | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regoper | 隐式 | 二进制兼容 | 0 |
regoper | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regoperator | 隐式 | 二进制兼容 | 0 |
regoperator | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regclass | 隐式 | 二进制兼容 | 0 |
regclass | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regcollation | 隐式 | 二进制兼容 | 0 |
regcollation | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regtype | 隐式 | 二进制兼容 | 0 |
regtype | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regconfig | 隐式 | 二进制兼容 | 0 |
regconfig | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regdictionary | 隐式 | 二进制兼容 | 0 |
regdictionary | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regrole | 隐式 | 二进制兼容 | 0 |
regrole | int4 | 赋值 | 二进制兼容 | 0 |
int4 | regnamespace | 隐式 | 二进制兼容 | 0 |
regnamespace | int4 | 赋值 | 二进制兼容 | 0 |
int4 | bytea | 显式 | 函数 | bytea(int4) |
bytea | int4 | 显式 | 函数 | int4(bytea) |
char | int4 | 显式 | 函数 | int4(char) |
int4 | char | 显式 | 函数 | char(int4) |
int4 | bit | 显式 | 函数 | bit(int4,int4) |
bit | int4 | 显式 | 函数 | int4(bit) |
jsonb | int4 | 显式 | 函数 | int4(jsonb) |
运算符重载 79
每种操作数签名均为独立重载。实现函数和返回类型来自同一源码构建。
| 运算符 | 左操作数 | 右操作数 | 返回类型 | 含义 | 实现函数 |
|---|---|---|---|---|---|
= | int4 | int8 | bool | 等于。 | int48eq |
<> | int4 | int8 | bool | 不等于。 | int48ne |
< | int4 | int8 | bool | 小于。 | int48lt |
> | int4 | int8 | bool | 大于。 | int48gt |
<= | int4 | int8 | bool | 小于或等于。 | int48le |
>= | int4 | int8 | bool | 大于或等于。 | int48ge |
= | int4 | int4 | bool | 等于。 | int4eq |
< | int4 | int4 | bool | 小于。 | int4lt |
= | xid | int4 | bool | 等于。 | xideqint4 |
<> | xid | int4 | bool | 不等于。 | xidneqint4 |
= | int8 | int4 | bool | 等于。 | int84eq |
<> | int8 | int4 | bool | 不等于。 | int84ne |
< | int8 | int4 | bool | 小于。 | int84lt |
> | int8 | int4 | bool | 大于。 | int84gt |
<= | int8 | int4 | bool | 小于或等于。 | int84le |
>= | int8 | int4 | bool | 大于或等于。 | int84ge |
* | int4 | int4 | int4 | 相乘。 | int4mul |
<> | int4 | int4 | bool | 不等于。 | int4ne |
> | int4 | int4 | bool | 大于。 | int4gt |
<= | int4 | int4 | bool | 小于或等于。 | int4le |
>= | int4 | int4 | bool | 大于或等于。 | int4ge |
/ | int4 | int4 | int4 | 相除。 | int4div |
% | int4 | int4 | int4 | 取余。 | int4mod |
= | int2 | int4 | bool | 等于。 | int24eq |
= | int4 | int2 | bool | 等于。 | int42eq |
< | int2 | int4 | bool | 小于。 | int24lt |
< | int4 | int2 | bool | 小于。 | int42lt |
> | int2 | int4 | bool | 大于。 | int24gt |
> | int4 | int2 | bool | 大于。 | int42gt |
<> | int2 | int4 | bool | 不等于。 | int24ne |
<> | int4 | int2 | bool | 不等于。 | int42ne |
<= | int2 | int4 | bool | 小于或等于。 | int24le |
<= | int4 | int2 | bool | 小于或等于。 | int42le |
>= | int2 | int4 | bool | 大于或等于。 | int24ge |
>= | int4 | int2 | bool | 大于或等于。 | int42ge |
* | int2 | int4 | int4 | 相乘。 | int24mul |
* | int4 | int2 | int4 | 相乘。 | int42mul |
/ | int2 | int4 | int4 | 相除。 | int24div |
/ | int4 | int2 | int4 | 相除。 | int42div |
+ | int4 | int4 | int4 | 相加。 | int4pl |
+ | int2 | int4 | int4 | 相加。 | int24pl |
+ | int4 | int2 | int4 | 相加。 | int42pl |
- | int4 | int4 | int4 | 相减。 | int4mi |
- | int2 | int4 | int4 | 相减。 | int24mi |
- | int4 | int2 | int4 | 相减。 | int42mi |
- | 无(一元) | int4 | int4 | 取负。 | int4um |
+ | int8 | int4 | int8 | 相加。 | int84pl |
- | int8 | int4 | int8 | 相减。 | int84mi |
* | int8 | int4 | int8 | 相乘。 | int84mul |
/ | int8 | int4 | int8 | 相除。 | int84div |
+ | int4 | int8 | int8 | 相加。 | int48pl |
- | int4 | int8 | int8 | 相减。 | int48mi |
* | int4 | int8 | int8 | 相乘。 | int48mul |
/ | int4 | int8 | int8 | 相除。 | int48div |
@ | 无(一元) | int4 | int4 | 绝对值。 | int4abs |
* | money | int4 | money | 相乘。 | cash_mul_int4 |
/ | money | int4 | money | 相除。 | cash_div_int4 |
* | int4 | money | money | 相乘。 | int4_mul_cash |
+ | date | int4 | date | 相加。 | date_pli |
- | date | int4 | date | 相减。 | date_mii |
<< | bit | int4 | bit | 按位左移。 | bitshiftleft |
>> | bit | int4 | bit | 按位右移。 | bitshiftright |
<< | int2 | int4 | int2 | 按位左移。 | int2shl |
>> | int2 | int4 | int2 | 按位右移。 | int2shr |
& | int4 | int4 | int4 | 按位与。 | int4and |
| | int4 | int4 | int4 | 按位或。 | int4or |
# | int4 | int4 | int4 | 按位异或。 | int4xor |
~ | 无(一元) | int4 | int4 | 按位取反。 | int4not |
<< | int4 | int4 | int4 | 按位左移。 | int4shl |
>> | int4 | int4 | int4 | 按位右移。 | int4shr |
<< | int8 | int4 | int8 | 按位左移。 | int8shl |
>> | int8 | int4 | int8 | 按位右移。 | int8shr |
+ | 无(一元) | int4 | int4 | 一元正号。 | int4up |
+ | int4 | date | date | 相加。 | integer_pl_date |
-> | json | int4 | json | 获取 JSON 数组元素。 | json_array_element |
->> | json | int4 | text | 获取 JSON 数组元素并返回文本。 | json_array_element_text |
-> | jsonb | int4 | jsonb | 获取 jsonb 数组元素。 | jsonb_array_element |
->> | jsonb | int4 | text | 获取 jsonb 数组元素并返回文本。 | jsonb_array_element_text |
- | jsonb | int4 | jsonb | 删除数组元素。 | jsonb_delete(jsonb,int4) |
操作符类 5
声明输入类型与此类型相符的操作符类。多态操作符类、类型转换和表达式索引还可能提供其他索引路径;不能仅凭此表判断是否支持索引。
版本比较
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 · 最早收录的样本不代表该类型的实际引入版本。