smallint
有符号两字节整数
当前查看 PostgreSQL 18。
中文定义与说明
有符号两字节整数
同版本中文手册节选
数字类型包括 2、4、8 字节的整数,4、8 字节的浮点数,以及可选精度的小数。表 8.2 列出了所有可用类型。
数字类型常量的语法在第 4.1.2 节里描述。数字类型有一整套对应的算术操作符和函数。相关信息请参考第 9 章。下面的几节详细描述这些类型。
PG10–20 核心源码清单。类型转换与操作符类列出源码显式声明的关系;缺少记录不能排除通过其他机制进行转换或使用索引。
定义
SQL 名称与别名: int2
有符号两字节整数
smallint
- 目录名称
- pg_catalog.int2
- 类型 OID
- 21
- 类型种类
- 基础类型
- 声明长度
- 2 字节
- 存储策略
- plain
- 输入函数
- int2in
- 输出函数
- int2out
- 手册中的声明
- smallint
- 存储大小
- 2 字节
- 手册说明
- 小范围整数
- 范围
- -32768 到 +32767
系统目录属性
此构建的源码初始化值。字段含义参见 pg_type 。包含头文件默认值;依赖构建的常量保留符号形式,不作为服务器运行时实测。
oid21descr-32 thousand to 32 thousand, 2-byte storagetypacl_null_typlen2typelem0typnameint2typsendint2sendtyptypebtypalignstyparray0typbyvalttypdelim','typinputint2intypmodin-typndims0typownerPOSTGREStyprelid0typmodout-typoutputint2outtyptypmod-1typanalyze-typdefault_null_typnotnullftypreceiveint2recvtypstorageptypbasetype0typcategoryNtypcollation0typisdefinedttypnamespacepg_catalogtypsubscript-typdefaultbin_null_array_type_oid1005typispreferredfarray_type_name_int2
类型转换 25
与此类型相关的显式 pg_cast 记录。PostgreSQL 还支持 pg_cast 之外的类型转换,缺少记录不能证明转换不可能。
| 源类型 | 目标类型 | 转换上下文 | 转换方式 | 函数 |
|---|---|---|---|---|
int8 | int2 | 赋值 | 函数 | int2(int8) |
int2 | int8 | 隐式 | 函数 | int8(int2) |
int2 | int4 | 隐式 | 函数 | int4(int2) |
int2 | float4 | 隐式 | 函数 | float4(int2) |
int2 | float8 | 隐式 | 函数 | float8(int2) |
int2 | numeric | 隐式 | 函数 | numeric(int2) |
int4 | int2 | 赋值 | 函数 | int2(int4) |
float4 | int2 | 赋值 | 函数 | int2(float4) |
float8 | int2 | 赋值 | 函数 | int2(float8) |
numeric | int2 | 赋值 | 函数 | int2(numeric) |
int2 | oid | 隐式 | 函数 | int4(int2) |
int2 | regproc | 隐式 | 函数 | int4(int2) |
int2 | regprocedure | 隐式 | 函数 | int4(int2) |
int2 | regoper | 隐式 | 函数 | int4(int2) |
int2 | regoperator | 隐式 | 函数 | int4(int2) |
int2 | regclass | 隐式 | 函数 | int4(int2) |
int2 | regcollation | 隐式 | 函数 | int4(int2) |
int2 | regtype | 隐式 | 函数 | int4(int2) |
int2 | regconfig | 隐式 | 函数 | int4(int2) |
int2 | regdictionary | 隐式 | 函数 | int4(int2) |
int2 | regrole | 隐式 | 函数 | int4(int2) |
int2 | regnamespace | 隐式 | 函数 | int4(int2) |
int2 | bytea | 显式 | 函数 | bytea(int2) |
bytea | int2 | 显式 | 函数 | int2(bytea) |
jsonb | int2 | 显式 | 函数 | int2(jsonb) |
运算符重载 63
每种操作数签名均为独立重载。实现函数和返回类型来自同一源码构建。
操作符类 5
声明输入类型与此类型相符的操作符类。多态操作符类、类型转换和表达式索引还可能提供其他索引路径;不能仅凭此表判断是否支持索引。
版本比较
PostgreSQL 17 → 18。属性比较不包含构建标识和说明正文;原始目录字段与源描述保留原文。
类型转换
PostgreSQL 17
[{"castcontext": "a", "castfunc": "int2(float4)", "castmethod": "f", "castsource": "float4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(float8)", "castmethod": "f", "castsource": "float8", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(int8)", "castmethod": "f", "castsource": "int8", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(numeric)", "castmethod": "f", "castsource": "numeric", "casttarget": "int2"}, {"castcontext": "e", "castfunc": "int2(jsonb)", "castmethod": "f", "castsource": "jsonb", "casttarget": "int2"}, {"castcontext": "i", "castfunc": "float4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "float4"}, {"castcontext": "i", "castfunc": "float8(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "float8"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "oid"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regclass"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regcollation"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regconfig"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regdictionary"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regnamespace"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regoper"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regoperator"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regproc"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regprocedure"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regrole"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regtype"}, {"castcontext": "i", "castfunc": "int8(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int8"}, {"castcontext": "i", "castfunc": "numeric(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "numeric"}]PostgreSQL 18
[{"castcontext": "a", "castfunc": "int2(float4)", "castmethod": "f", "castsource": "float4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(float8)", "castmethod": "f", "castsource": "float8", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(int4)", "castmethod": "f", "castsource": "int4", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(int8)", "castmethod": "f", "castsource": "int8", "casttarget": "int2"}, {"castcontext": "a", "castfunc": "int2(numeric)", "castmethod": "f", "castsource": "numeric", "casttarget": "int2"}, {"castcontext": "e", "castfunc": "bytea(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "bytea"}, {"castcontext": "e", "castfunc": "int2(bytea)", "castmethod": "f", "castsource": "bytea", "casttarget": "int2"}, {"castcontext": "e", "castfunc": "int2(jsonb)", "castmethod": "f", "castsource": "jsonb", "casttarget": "int2"}, {"castcontext": "i", "castfunc": "float4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "float4"}, {"castcontext": "i", "castfunc": "float8(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "float8"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int4"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "oid"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regclass"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regcollation"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regconfig"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regdictionary"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regnamespace"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regoper"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regoperator"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regproc"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regprocedure"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regrole"}, {"castcontext": "i", "castfunc": "int4(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "regtype"}, {"castcontext": "i", "castfunc": "int8(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "int8"}, {"castcontext": "i", "castfunc": "numeric(int2)", "castmethod": "f", "castsource": "int2", "casttarget": "numeric"}]文档与源码
- 构建
- 18.6 · https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- 指纹
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f
相关条目
全部数据类型 · 下载此版本 JSON · 最早收录的样本不代表该类型的实际引入版本。