新执行器函数支持情况
1. 类型转换函数
1.1 anything to text
| Function Name | Input Type | Output Type | OID | Status | Description |
|---|
charout | char | cstring | 33 | Implemented but unsupported | 将单个字符转换为 C 风格的字符串。 |
byteaout | bool | cstring | 31 | Implemented but unsupported | 应该是将布尔值转换为字符串,但这里的输入类型与输出类型不匹配。 |
int2out | int2 | cstring | 39 | Implemented but unsupported | 将 16 位整数转换为字符串。 |
int4out | int4 | cstring | 43 | Implemented but unsupported | 将 32 位整数转换为字符串。 |
int8out | int8 | cstring | 461 | Implemented but unsupported | 将 64 位整数转换为字符串。 |
float4out | float4 | cstring | 201 | Implemented but unsupported | 将 32 位浮点数转换为字符串。 |
float8out | float8 | cstring | 215 | Implemented but unsupported | 将 64 位浮点数转换为字符串。 |
numeric_out | numeric | cstring | 1702 | Implemented but unsupported | 将任意精度数值转换为字符串。 |
date_out | date | cstring | 1085 | Implemented but unsupported | 将日期转换为字符串。 |
boolout | bool | cstring | 1243 | Implemented but unsupported | 将布尔值转换为字符串。 |
timeout | time | cstring | 1144 | Implemented but unsupported | 将时间值转换为字符串。 |
timestamp_out | timestamp | cstring | 1313 | Implemented but unsupported | 将时间戳转换为字符串。 |
interval_out | interval | cstring | 1161 | Implemented but unsupported | 将间隔值转换为字符串。 |
Timestamptz | timestamptz | cstring | N/A | Implemented but implementation function error | 将带时区的时间戳转换为字符串,但实现函数存在问题。 |
有实现但是不支持的原因是:在6.x版本,这种转换的类型是CoerceViaIO 类型,用来表示两种类型之间的类型强制转换。CoerceViaIO 是一种类型转换机制,它利用了类型输出(typoutput)和类型输入(typinput)函数来从一种数据类型转换到另一种数据类型。这种转换是基于文本格式的,也就是说,它首先将源数据类型转换为文本形式,然后再将该文本解析为目标数据类型。
例如,当你尝试将一个整数转换为日期,或者将一个日期转换为时间戳时,PostgreSQL 可能会使用 CoerceViaIO 路径。在这个过程中,整数首先被转换为文本,然后文本再被解析为日期或时间戳。
相关测试用例见下:
set new_executor = auto;
CREATE TABLE data_types (
char_column char(1),
smallint_column smallint,
int_column int,
bigint_column bigint,
float_column float4,
double_column float8,
decimal_column decimal(10,2),
date_column date,
time_column time,
timestamptz_column timestamptz,
timestamp_column timestamp,
interval_column interval,
boolean_column boolean
);
INSERT INTO data_types (
char_column,
smallint_column,
int_column,
bigint_column,
float_column,
double_column,
decimal_column,
date_column,
time_column,
timestamptz_column,
timestamp_column,
interval_column,
boolean_column
)
SELECT
substring('abcdefghijklmnopqrstuvwxyz' FROM (floor(random() * 26) + 1)::integer FOR 1),
floor(random()*32767)::smallint,
floor(random()*2147483647)::integer,
floor(random()*9223372036854775807)::bigint,
random()::real,
random(),
floor(random()*10000)::numeric(10,2),
'2024-01-01'::date + floor(random()*365)::bigint * interval '1 day',
'00:00:00'::time + floor(random()*86400)::bigint * interval '1 second',
('2024-01-01 00:00:00'::timestamp + floor(random()*31536000)::bigint * interval '1 second') AT TIME ZONE 'UTC',
'2024-01-01 00:00:00'::timestamp + floor(random()*31536000)::bigint * interval '1 second',
interval '1 day' * floor(random()*30)::bigint +
interval '1 hour' * floor(random()*24)::bigint +
interval '1 minute' * floor(random()*60)::bigint +
interval '1 second' * floor(random()*60)::bigint,
true
FROM generate_series(1,1000);
explain analyze select text(char_column) from data_types;
explain analyze select text(smallint_column) from data_types;
explain analyze select text(int_column) from data_types;
explain analyze select text(bigint_column) from data_types;
explain analyze select text(float_column) from data_types;
explain analyze select text(double_column)from data_types;
explain analyze select text(decimal_column) from data_types;
explain analyze select text(date_column) from data_types;
explain analyze select text(boolean_column) from data_types;
explain analyze select text(time_column) from data_types;
explain analyze select text(timestamptz_column) from data_types;
explain analyze select text(interval_column) from data_types;
explain analyze select text(timestamp_column) from data_types;
1.2 to timestamptz
| Function Name | Input Type(s) | Output Type | OID | Status | Description |
|---|
to_timestamp | float8 | timestamptz | 1158 | Not supported, no oid [1158] corresponds | 将浮点数转换为带时区的时间戳,但该函数未被支持。 |
to_timestamp | text, text | timestamptz | 1778 | Not supported, text_to_timestamp()has incorrect parameters | 将文本字符串和格式字符串转换为带时区的时间戳,但函数参数不正确导致不支持。 |
1.3 to date
date date(timestamptz) 不支持
| Function Name | Input Type | Output Type | OID | Status | Description |
|---|
date | timestamp | date | 2029 | Supported | 从时间戳中提取日期部分。 |
explain analyze select cast(timestamp_column as date) from data_types;
explain analyze select timestamp_column::date from data_types;
1.4 to timestamp
timestamp (date time), timestamp(timestamptz), timestamp(timestamp,int4)没有实现
| Function Name | Input Type | Output Type | OID | Status | Description |
|---|
timestamp | date | timestamp | 2024 | Supported | 从日期中构建时间戳,默认时间为午夜(00:00:00)。 |
explain analyze select cast(date_column as timestamp) from data_types;
explain analyze select date_column::timestamp from data_types;
1.5 in-out函数
| Oid | Function Name | Input Type | Output Type | Status | Description |
|---|
| 38 | int2in | cstring | int2 | Implemented but unsupported | 将 C 风格的字符串转换为 16 位整数。 |
| 42 | int4in | cstring | int4 | Implemented but unsupported | 将 C 风格的字符串转换为 32 位整数。 |
| 460 | int8in | cstring | int8 | Implemented but unsupported | 将 C 风格的字符串转换为 64 位整数。 |
| 200 | float4in | cstring | float4 | Implemented but unsupported | 将 C 风格的字符串转换为 32 位浮点数。 |
| 214 | float8in | cstring | float8 | Implemented but unsupported | 将 C 风格的字符串转换为 64 位浮点数。 |
| 1777 | to_number | text | numeric | Not specified | 将文本字符串转换为任意精度数值。 |
2. 处理函数
2.1 时间处理函数
| Function Name | Input Type(s) | Output Type | Status | Description | |
|---|
| 1389 | isfinite | timestamptz | bool | Supported | 检查时间戳是否有限(适用于日期、间隔和时间戳)。 |
| 2021 | date_part | text, timestamp | float | Supported | 从时间戳中提取指定的部分(适用于时间戳、带时区的时间戳、间隔、带时区的时间和日期)。 |
| 2020 | date_trunc | text, timestamp | timestamp | Supported | 从时间戳中截取指定的部分(适用于时间戳、带时区的时间戳、间隔)。 |
| 1690 | time_mi_time | time, time | interval | Not supported | 两个时间相减得到间隔(不支持,因为没有注册 TIMEOID,但现在已支持)。 |
| 1141 | date_pli | date, int4 | date | Supported | 日期加上整数天。 |
| 1142 | date_mii | date, int4 | date | Supported | 日期减去整数天。 |
| 1188 | timestamptz_mi | timestamptz, timestamptz | interval | Supported | 两个带时区的时间戳相减得到间隔。 |
| timestamp_mi | timestamp, timestamp | interval | Supported | 两个时间戳相减得到间隔。 |
| 2071 | date_pl_interval | date, interval | timestamp | Partially supported | 日期加上间隔(部分支持,原因未知)。 |
| 2072 | date_mi_interval | date, interval | timestamp | Partially supported | 日期减去间隔(部分支持,原因disable INTERVAL type in scan)。 |
| 1747 | time_pl_interval | time, interval | time | Not supported | 时间加上间隔(不支持,原因disable INTERVAL type in scan)。 |
| 1748 | time_mi_interval | time, interval | time | Not supported | 时间减去间隔(不支持,原因disable INTERVAL type in scan)。 |
| 2032 | timestamp_pl_interval | timestamp, interval | timestamp | Partially supported | 时间戳加上间隔(部分支持,原因未知disable INTERVAL type in scan)。 |
| 2033 | timestamp_mi_interval | timestamp, interval | timestamp | Partially supported | 时间戳减去间隔(部分支持,原因未知disable INTERVAL type in scan)。 |
| 1168 | interval_um | interval | interval | Partially supported | 间隔的负值(部分支持,原因disable INTERVAL type in scan)。 |
| 1598 | random | None | float8 | Not supported | 生成随机数(不支持,原因case T_FuncExpr 明确拦截)。 |
| 1599 | setseed | float8 | void | Not supported | 设置随机数种子(不支持,原因case T_FuncExpr 明确拦截)。 |
explain analyze select isfinite(date_column) from data_types;
explain analyze select isfinite(interval_column) from data_types;
explain analyze select isfinite(timestamp_column) from data_types;
explain analyze select isfinite(timestamptz_column) from data_types;
explain analyze select date_part('day', timestamp_column) from data_types;
explain analyze select date_part('day', timestamptz_column) from data_types;
explain analyze select date_part('day', interval_column) from data_types;
explain analyze select date_part('day', date_column) from data_types;
explain analyze select date_part('second', time_column) from data_types;
explain analyze select date_part('second', timetz_column) from data_types;
explain analyze select date_trunc('day', timestamp_column) from data_types;
explain analyze select date_trunc('day', timestamptz_column) from data_types;
explain analyze select date_trunc('day', timestamptz_column, 'America/New_York') from data_types;
explain analyze select date_trunc('day', interval_column) from data_types;
explain analyze select time_mi_time(time_column, time_column) from data_types;
explain analyze select date_pli(date_column, int_column) from data_types;
explain analyze select date_mii(date_column, int_column) from data_types;
explain analyze select timestamptz_mi(timestamptz_column, timestamptz_column) from data_types;
explain analyze select timestamp_mi(timestamp_column, timestamp_column) from data_types;
explain analyze select date_pl_interval(date_column, interval_column) from data_types;
explain analyze select date_column + interval_column from data_types;
explain analyze select date_column + '1 day'::interval from data_types
explain analyze select time_pl_interval(time_column, interval_column) from data_types;
explain analyze select time_column + interval_column from data_types;
explain analyze select time_column + '1 second'::interval from data_types
explain analyze select timestamp_pl_interval(timestamp_column, interval_column) from data_types;
explain analyze select timestamp_column + interval_column from data_types;
explain analyze select timestamp_column + '1 second'::interval from data_types;
explain analyze select interval_um(interval_column) from data_types;
2.2 字符串处理函数
| Function Name | Input Type(s) | Output Type | OID | Status | Description |
|---|
octet_length | text | Int4 | 1374 | Supported | 计算文本的字节长度。 |
octet_length | bpchar | Int4 | 1375 | Supported | 计算定长字符的字节长度。 |
length | bytea | Int4 | 2010 | Supported | 计算字节数组的长度。 |
textlen | text | Int4 | 1257 | Supported | 计算文本的长度。 |
length | bpchar | Int4 | 1318 | Supported | 计算定长字符的长度。 |
textlike | text, text | bool | 850 | Supported | 检查文本是否符合模式。 |
bpcharlike | bpchar, text | bool | 1631 | Supported | 检查定长字符是否符合模式。 |
textnlike | text, text | bool | 851 | Supported | 检查文本是否不符合模式。 |
bpcharnlike | bpchar, text | bool | 1632 | Supported | 检查定长字符是否不符合模式。 |
substr | text, int4, int4 | text | 877 | Supported | 提取文本的子串。 |
substr | text, int4 | text | 883 | Supported | 提取文本的子串。 |
substring | text, int4, int4 | text | 936 | Supported | 提取文本的子串。 |
substring | text, int4 | text | 937 | Supported | 提取文本的子串。 |
lower | text | text | 870 | Supported | 将文本转换为小写。 |
upper | text | text | 871 | Supported | 将文本转换为大写。 |
textcat | text, text | text | 1258 | Supported | 连接两个文本字符串。 |
position | text, text | int4 | 849 | Supported | 查找一个文本在另一个文本中的位置。 |
strpos | text, text | int4 | 868 | Supported | 查找一个文本在另一个文本中的位置。 |
initcap | text | text | 872 | Supported | 将每个单词首字母大写。 |
ascii | text | int4 | 1620 | Supported | 获取文本第一个字符的 ASCII 值。 |
varchar | varchar, int4, bool | varchar | 669 | Supported | 转换并调整文本的长度。 |
ltrim | text | text | 881 | Supported | 删除文本开头的空白字符。 |
ltrim | text, text | text | 875 | Supported | 删除文本开头特定字符。 |
rtrim | text | text | 882 | Supported | 删除文本末尾的空白字符。 |
rtrim | text, text | text | 876 | Supported | 删除文本末尾特定字符。 |
btrim | text | text | 885 | Supported | 删除文本两端的空白字符。 |
btrim | text, text | text | 884 | Supported | 删除文本两端特定字符。 |
repeat | text, int4 | text | 1622 | Not supported | 重复文本指定次数。 |
chr | int4 | text | 1621 | Supported | 返回给定 ASCII 值的字符。 |
bpchar | bpchar, int4, bool | bpchar | 668 | Supported | 调整定长字符的长度。 |
lpad | text, int4, text | text | 873 | Supported | 左侧填充文本。 |
rpad | text, int4, text | text | 874 | Supported | 右侧填充文本。 |
lpad | text, int4 | text | 879 | Supported | 左侧填充文本至指定长度。 |
rpad | text, int4 | text | 880 | Supported | 右侧填充文本至指定长度。 |
bpchareq | bpchar, bpchar | bool | 1053 | Supported | 比较两个定长字符是否相等。 |
bpcharle | bpchar, bpchar | bool | 1048 | Supported | 检查一个定长字符是否小于等于另一个。 |
bpcharlt | bpchar, bpchar | bool | 1049 | Supported | 检查一个定长字符是否小于另一个。 |
bpcharle | bpchar, bpchar | bool | 1050 | Supported | 检查一个定长字符是否小于等于另一个。 |
bpchargt | bpchar, bpchar | bool | 1051 | Supported | 检查一个定长字符是否大于另一个。 |
bpcharge | bpchar, bpchar | bool | 1052 | Supported | 检查一个定长字符是否大于等于另一个。 |
translate | text, text, text | text | 878 | Supported | 替换文本中的字符。 |
split_part | text, text, int4 | text | 2088 | Supported | 分割文本并返回指定部分。 |
text_pattern_lt | text, text | bool | 2160 | Supported | 检查文本是否小于模式。 |
text_pattern_le | text, text | bool | 2161 | Supported | 检查文本是否小于等于模式。 |
text_pattern_ge | text, text | bool | 2163 | Supported | 检查文本是否大于等于模式。 |
text_pattern_gt | text, text | bool | 2164 | Supported | 检查文本是否大于模式。 |
textregexeq | text, text | bool | 1254 | Supported | 使用正则表达式比较文本。 |
texticregexeq | text, text | bool | 1238 | Supported | 使用正则表达式比较文本(忽略大小写)。 |
textregexne | text, text | bool | 1256 | Supported | 使用正则表达式比较文本是否不匹配。 |
texticregexne | text, text | bool | 1239 | Supported | 使用正则表达式比较文本是否不匹配(忽略大小写)。 |
bpcharregexeq | bpchar, text | bool | 1658 | Supported | 使用正则表达式比较定长字符。 |
bpcharicregexeq | bpchar, text | bool | 1656 | Supported | 使用正则表达式比较定长字符(忽略大小写)。 |
bpcharregexne | bpchar, text | bool | 1659 | Supported | 使用正则表达式比较定长字符是否不匹配。 |
bpcharicregexne | bpchar, text | bool | 1657 | Supported | 使用正则表达式比较定长字符是否不匹配(忽略大小写)。 |
regexp_replace | text, text, text | text | 2284 | Supported | 使用正则表达式替换文本中的模式 |
CREATE TABLE char_types (
char_column char(1),
varchar_column varchar(100),
text_column text,
bpchar bpchar(255)
);
INSERT INTO char_types (char_column, varchar_column, text_column)
SELECT
chr(floor(random() * 26 + 65)::int),
md5(random()::text),
(
SELECT string_agg(chr(floor(random() * 26 + 65)::int), '')
FROM generate_series(1, (ceiling(random() * 10) + 1)::int)
)
FROM generate_series(1, 1000);
CREATE TABLE my_table1 (
id serial PRIMARY KEY,
my_column bpchar(255)
);
INSERT INTO my_table1 (my_column) VALUES ('Hello, World!');
INSERT INTO my_table1 (my_column) VALUES ('你好,世界!');
explain analyze select octet_length(text_column) from char_types;
explain analyze SELECT octet_length(my_column) AS byte_length FROM my_table;
explain analyze select octet_length(text_column) from char_types;
explain analyze SELECT length(my_column) AS byte_length FROM my_table;
explain select textlike(text_column, 'N%A') AS is_match from char_types limit 1;
explain select text_column like 'N%A' from char_types;
explain analyze select * from char_types where text_column like 'N%A';
explain analyze SELECT bpcharlike(my_column, 'H%d%') AS byte_length FROM my_table;
explain select my_column like 'H%d%' from my_table;
explain analyze select * from my_table where my_column like'H%d%';
explain select textnlike(text_column, 'N%A') AS is_match from char_types limit 1;
explain select text_column not like 'N%A' from char_types;
explain analyze select * from char_types where text_column not like 'N%A';
explain analyze SELECT bpcharnlike(my_column, 'H%d%') AS byte_length FROM my_table;
explain select my_column not like 'H%d%' from my_table;
explain analyze select * from my_table where my_column not like'H%d%';
explain select substr(text_column, 1, 3) AS is_match from char_types limit 1;
explain select substr(text_column, 3) AS is_match from char_types limit 1;
explain select lower(text_column) AS is_match from char_types limit 1;
explain select upper(text_column) AS is_match from char_types limit 1;
explain select textcat(text_column, text_column) AS is_match from char_types limit 1;
explain select position(text_column in text_column) from char_types;
explain select strpos(text_column , text_column) from char_types;
explain select initcap(text_column) from char_types;
explain select ascii(text_column) from char_types;
explain select "varchar"(varchar_column, 10::int4, false) from char_types;
explain select ltrim(text_column) from char_types;
explain select ltrim(text_column, text_column) from char_types;
explain select rtrim(text_column) from char_types;
explain select rtrim(text_column, text_column) from char_types;
explain select btrim(text_column) from char_types;
explain select btrim(text_column, text_column) from char_types;
explain select repeat(text_column, 12) from char_types;
explain select chr(int_column) from data_types;
explain select "bpchar"(my_column, 12, false) from my_table;
explain select lpad(text_column, 12, text_column) from char_types;
explain select rpad(text_column, 12, text_column) from char_types;
explain select lpad(text_column, 12) from char_types;
explain select rpad(text_column, 12) from char_types;
explain select bpchareq(my_column, my_column) from my_table;
explain select bpcharlt(my_column, my_column) from my_table;
explain select bpcharle(my_column, my_column) from my_table;
explain select bpchargt(my_column, my_column) from my_table;
explain select bpcharge(my_column, my_column) from my_table;
explain select bpcharne(my_column, my_column) from my_table;
explain select translate(text_column, 'A', 'AAAA') from char_types;
explain select split_part(text_column, 'A', '1') from char_types;
explain select text_pattern_lt(text_column, text_column) from char_types;
explain select text_pattern_le(text_column, text_column) from char_types;
explain select text_pattern_ge(text_column, text_column) from char_types;
explain select text_pattern_gt(text_column, text_column) from char_types;
explain analyze select regexp_replace(text_column, 'a', '12') from char_types;
explain analyze select textregexeq(text_column, '[a-zA-Z]') from char_types;
explain analyze select texticregexeq(text_column, '[a-zA-Z]') from char_types;
explain analyze select textregexne(text_column, '[a-zA-Z]') from char_types;
explain analyze select texticregexne(text_column, '[a-zA-Z]') from char_types;
explain analyze select regexp_replace(my_column, 'a', '12') from my_table1;
explain analyze select textregexeq(my_column, '[a-zA-Z]') from my_table1;
explain analyze select texticregexeq(my_column, '[a-zA-Z]') from my_table1;
explain analyze select textregexne(my_column, '[a-zA-Z]') from my_table1;
explain analyze select texticregexne(my_column, '[a-zA-Z]') from my_table1;
2.3 数组处理函数
| Function Name | Input Type(s) | Output Type | OID | Status | Description |
|---|
arrayoverlap | anyarray, anyarray | bool | 2747 | Not supported | 检查两个数组是否有重叠元素(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID)。 |
arraycontains | anyarray, anyarray | bool | 2748 | Not supported | 检查一个数组是否包含另一个数组的所有元素(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID)。 |
arraycontained | anyarray, anyarray | bool | 2749 | Not supported | 检查一个数组是否被另一个数组完全包含(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID) |
2.4 数值处理函数
| Function Name | Input Type | Output Type | OID | Status | Description |
|---|
float8abs | float8 | float8 | 221 | Supported | 计算浮点数的绝对值。 |
float4abs | float4 | float4 | 207 | Supported | 计算浮点数的绝对值。 |
int8abs | int8 | int8 | 1230 | Supported | 计算整数的绝对值。 |
int4abs | int4 | int4 | 1251 | Supported | 计算整数的绝对值。 |
int2abs | int2 | int2 | 1253 | Supported | 计算整数的绝对值。 |
float8um | float8 | float8 | 220 | Supported | 计算浮点数的负值。 |
float4um | float4 | float4 | 206 | Supported | 计算浮点数的负值。 |
int8um | int8 | int8 | 462 | Supported | 计算整数的负值。 |
int4um | int4 | int4 | 212 | Supported | 计算整数的负值。 |
int2um | int2 | int2 | 213 | Supported | 计算整数的负值。 |
2.5 tid处理函数
| Function Name | Input Type(s) | Output Type | OID | Status | Description |
|---|
tide | tid, tid | bool | 1292 | Not supported | 比较两个事务 ID 是否相等(函数声明不一致)。 |
tidne | tid, tid | bool | 1265 | Not supported | 比较两个事务 ID 是否不相等(函数声明不一致)。 |
tidlt | tid, tid | bool | 2791 | Not supported | 检查一个事务 ID 是否小于另一个(函数声明不一致)。 |
tidle | tid, tid | bool | 2793 | Not supported | 检查一个事务 ID 是否小于等于另一个(函数声明不一致)。 |
tidgt | tid, tid | bool | 2790 | Not supported | 检查一个事务 ID 是否大于另一个(函数声明不一致)。 |
tidge | tid, tid | bool | 2792 | Not supported | 检查一个事务 ID 是否大于等于另一个(函数声明不一致)。 |
explain select tide(bigint_column, bigint_column) from data_types;
explain select tidne(bigint_column, bigint_column) from data_types;
explain select tidlt(bigint_column, bigint_column) from data_types;
explain select tidle(bigint_column, bigint_column) from data_types;
explain select tidgt(bigint_column, bigint_column) from data_types;
explain select tidge(bigint_column, bigint_column) from data_types;
explain select float4abs(float_column) from data_types;
explain select float8abs(double_column) from data_types;
explain select int8abs(bigint_column) from data_types;
explain select int4abs(int_column) from data_types;
explain select int2abs(smallint_column) from data_types;
explain select float8um(double_column) from data_types;
explain select float4um(float_column) from data_types;
explain select int8um(bigint_column) from data_types;
explain select int4um(int_column) from data_types;
explain select int2um(smallint_column) from data_types;
explain select int2not(smallint_column) from data_types;
explain select int4not(int_column) from data_types;
explain select int8not(bigint_column) from data_types;
explain select int2shl(smallint_column, 1) from data_types;
explain select int4shl(int_column, 1) from data_types;
explain select int8shl(bigint_column, 1) from data_types;
explain select int2shr(smallint_column, 1) from data_types;
explain select int4shr(int_column, 1) from data_types;
explain select int8shr(bigint_column, 1) from data_types;
explain select int2and(smallint_column, smallint_column) from data_types;
explain select int4and(int_column, int_column) from data_types;
explain select int8and(bigint_column, bigint_column) from data_types;
explain select int2or(smallint_column, smallint_column) from data_types;
explain select int4or(int_column, int_column) from data_types;
explain select int8or(bigint_column, bigint_column) from data_types;
explain select int2xor(smallint_column, smallint_column) from data_types;
explain select int4xor(int_column, int_column) from data_types;
explain select int8xor(bigint_column, bigint_column) from data_types;
explain select int2mod(smallint_column, smallint_column) from data_types;
explain select int4mod(int_column, int_column) from data_types;
explain select int8mod(bigint_column, bigint_column) from data_types;
2.6 send函数
| oid | 函数声明 | 支持情况 | 备注 |
|---|
| 2435 | bytea charsend(char) | function charsend(character) does not exist | |
| 2405 | bytea int2send(int2) | 支持 | |
| 2407 | bytea int4send(int4) | 支持 | |
| 2409 | bytea int8send(int8) | 支持 | |
| 2425 | bytea float4send(float4) | 支持 | |
| 2427 | bytea float8send(float8) | 支持 | |
| 2437 | bytea boolsend(bool) | 支持 | |
| 2415 | bytea textsend(text) | 支持 | |
| 2469 | bytea date_send(date) | 支持 | |
| 2471 | bytea time_send(time) | 不支持 | |
| 2475 | bytea timestamp_send(timestamp) | 支持 | |
| 2477 | bytea timestamptz_send(timestamptz) | 支持 | |
| 2479 | bytea interval_send(interval) | 不支持 | |
| 2461 | bytea numeric_send(numeric) | 支持 | |
explain analyze select int2send(smallint_column) from data_types;
explain analyze select int4send(int_column) from data_types;
explain analyze select int8send(bigint_column) from data_types;
explain analyze select float4send(float_column) from data_types;
explain analyze select float8send(double_column) from data_types;
explain analyze select boolsend(boolean_column) from data_types;
explain analyze select textsend(text_column) from char_types;
explain analyze select date_send(date_column) from data_types;
explain analyze select time_send(time_column) from data_types;
explain analyze select timestamp_send(timestamp_column) from data_types;
explain analyze select timestamptz_send(timestamptz_column) from data_types;
explain analyze select interval_send(interval_column) from data_types;
explain analyze select numeric_send(decimal_column) from data_types;
2.7 数学运算
| Function Name | Input Type(s) | Output Type | OID | Status | Description |
|---|
dcbrt | float8 | float8 | 231 | Supported | 计算立方根。 |
dsqrt | float8 | float8 | 230 | Supported | 计算平方根。 |
int2not | int2 | int2 | 1895 | Supported | 计算按位非。 |
int4not | int4 | int4 | 1901 | Supported | 计算按位非。 |
int8not | int8 | int8 | 1907 | Supported | 计算按位非。 |
int2shl | int2, int4 | int2 | 1896 | Supported | 计算左移。 |
int4shl | int2, int4 | int4 | 1902 | Supported | 计算左移。 |
int8shl | int2, int4 | int8 | 1908 | Supported | 计算左移。 |
int2shr | int2, int4 | int2 | 1897 | Supported | 计算右移。 |
int4shr | int2, int4 | int4 | 1903 | Supported | 计算右移。 |
int8shr | int2, int4 | int8 | 1909 | Supported | 计算右移。 |
int2and | int2, int2 | int2 | 1892 | Supported | 计算按位与。 |
int4and | int4, int4 | int4 | 1898 | Supported | 计算按位与。 |
int8and | int8, int8 | int8 | 1904 | Supported | 计算按位与。 |
int2or | int2, int2 | int2 | 1893 | Supported | 计算按位或。 |
int4or | int4, int4 | int4 | 1899 | Supported | 计算按位或。 |
int8or | int8, int8 | int8 | 1905 | Supported | 计算按位或。 |
int2xor | int2, int2 | int2 | 1894 | Supported | 计算按位异或。 |
int4xor | int4, int4 | int4 | 1900 | Supported | 计算按位异或。 |
int8xor | int8, int8 | int8 | 1906 | Supported | 计算按位异或。 |
int2mod | int2, int2 | int2 | 155 | Supported | 计算模数。 |
int4mod | int4, int4 | int4 | 156 | Supported | 计算模数。 |
int8mod | int8, int8 | int8 | 945 | Supported | 计算模数。 |
dpow | float8, float8 | float8 | 232 | Supported | 计算幂。 |
ceil | float8 | float8 | 2308 | Supported | 向上取整。 |
floor | float8 | float8 | 2309 | Supported | 向下取整。 |
dround | float8 | float8 | 228 | Supported | 四舍五入。 |
dtrunc | float8 | float8 | 229 | Supported | 截断到整数。 |
sign | float8 | float8 | 2310 | Supported | 计算符号。 |
dexp | float8 | float8 | 233 | Supported | 计算指数。 |
dlog1 | float8 | float8 | 234 | Supported | 计算自然对数。 |
log10 | float8 | float8 | 1194 | Supported | 计算以10为底的对数。 |
log | float8 | float8 | 1340 | Core, 参数不匹配,这个机制有问题,params size不匹配竟然都会匹配到 | 计算对数。 |
asin | float8 | float8 | 1600 | Supported | 计算反正弦。 |
acos | float8 | float8 | 1601 | Supported | 计算反余弦。 |
atan | float8 | float8 | 1602 | Supported | 计算反正切。 |
atan2 | float8, float8 | float8 | 1603 | Supported | 计算两数的反正切。 |
sin | float8 | float8 | 1604 | Supported | 计算正弦。 |
cos | float8 | float8 | 1605 | Supported | 计算余弦。 |
tan | float8 | float8 | 1606 | Supported | 计算正切。 |
cot | float8 | float8 | 1607 | Supported | 计算余切。 |
degrees | float8 | float8 | 1608 | Supported | 弧度转角度。 |
radians | float8 | float8 | 1609 | Supported | 角度转弧度。 |
numeric_uminus | numeric | numeric | 1771 | Supported | 计算负值。 |
numeric_abs | numeric | numeric | 1704 | Supported | 计算绝对值。 |
round | numeric | numeric | 1708 | Supported | 四舍五入。 |
trunc | numeric, int4 | numeric | 1709 | Supported | 截断到小数点后指定位数。 |
trunc | numeric | numeric | 1710 | Supported | 截断到整数。 |
numeric | numeric, int4 | numeric | 1703 | Not supported | 构建数字类型。 |
mod | numeric, numeric | numeric | 1728 | Supported | 计算模数。 |
sqrt | numeric | numeric | 1730 | Supported | 计算平方根。 |
exp | numeric | numeric | 1732 | Supported | 计算指数。 |
ln | numeric | numeric | 1734 | Supported | 计算自然对数。 |
log | numeric, numeric | numeric | 1736 | Supported | 计算对数。 |
numeric_fac | int8 | numeric | 111 | Supported | 计算阶乘。 |
pow | numeric, numeric | numeric | 1738 | Supported | 计算幂。 |
stddev_samp | int2 | numeric | 2714 | Supported | 样本标准差。 |
stddev_samp | int4 | numeric | 2713 | Supported | 样本标准差。 |
stddev_samp | int8 | numeric | 2712 | Supported | 样本标准差。 |
stddev_samp | float4 | float8 | 2715 | Supported | 样本标准差。 |
stddev_samp | float8 | float8 | 2716 | Supported | 样本标准差。 |
stddev_samp | numeric | numeric | 2717 | Supported | 样本标准差。 |
stddev_pop | int2 | numeric | 2726 | Supported | 总体标准差。 |
stddev_pop | int4 | numeric | 2725 | Supported | 总体标准差。 |
stddev_pop | int8 | numeric | 2724 | Supported | 总体标准差。 |
stddev_pop | float4 | float8 | 2727 | Supported | 总体标准差。 |
stddev_pop | float8 | float8 | 2728 | Supported | 总体标准差。 |
stddev_pop | numeric | numeric | 2729 | Supported | 总体标准差。 |
stddev | int2 | numeric | 2156 | Supported | 标准差。 |
stddev | int4 | numeric | 2155 | Supported | 标准差。 |
stddev | int8 | numeric | 2154 | Supported | 标准差。 |
stddev | float4 | float8 | 2157 | Supported | 标准差。 |
stddev | float8 | float8 | 2158 | Supported | 标准差。 |
stddev | numeric | numeric | 2159 | Supported | 标准差。 |
explain analyze select dcbrt(double_column) from data_types;
explain analyze select dsqrt(double_column) from data_types;
explain analyze select dpow(double_column, double_column) from data_types;
explain analyze select ceil(double_column) from data_types;
explain analyze select floor(double_column) from data_types;
explain analyze select dround(double_column) from data_types;
explain analyze select dtrunc(double_column) from data_types;
explain analyze select sign(double_column) from data_types;
explain analyze select dlog1(double_column) from data_types;
explain analyze select log10(double_column) from data_types;
explain analyze select log(double_column) from data_types;
explain analyze select asin(double_column) from data_types;
explain analyze select acos(double_column) from data_types;
explain analyze select atan(double_column) from data_types;
explain analyze select atan2(double_column, 1.1) from data_types;
explain analyze select sin(double_column) from data_types;
explain analyze select cos(double_column) from data_types;
explain analyze select tan(double_column) from data_types;
explain analyze select cot(double_column) from data_types;
explain analyze select degrees(double_column) from data_types;
explain analyze select radians(double_column) from data_types;
explain analyze select numeric_uminus(decimal_column) from data_types;
explain analyze select numeric_abs(decimal_column) from data_types;
explain analyze select round(decimal_column) from data_types;
explain analyze select trunc(decimal_column, 4) from data_types;
explain analyze select trunc(decimal_column) from data_types;
explain analyze select "numeric"(decimal_column , 4) from data_types;
explain analyze select mod(decimal_column , decimal_column) from data_types;
explain analyze select sqrt(decimal_column) from data_types;
explain analyze select exp(decimal_column) from data_types;
explain analyze select ln(decimal_column) from data_types;
explain analyze select log(decimal_column, decimal_column) from data_types where bigint_column < 100;;
explain analyze select pow(decimal_column, decimal_column) from data_types where bigint_column < 100;;
explain analyze select numeric_fac(bigint_column) from data_types where bigint_column < 100;
explain analyze select stddev_samp(smallint_column) from data_types;
explain analyze select stddev_samp(int_column) from data_types;
explain analyze select stddev_samp(bigint_column) from data_types where bigint_column < 1000;
explain analyze select stddev_samp(float_column) from data_types;
explain analyze select stddev_samp(double_column) from data_types;
explain analyze select stddev_samp(decimal_column) from data_types;
explain analyze select stddev_pop(smallint_column) from data_types;
explain analyze select stddev_pop(int_column) from data_types;
explain analyze select stddev_pop(bigint_column) from data_types where bigint_column < 1000;
explain analyze select stddev_pop(float_column) from data_types;
explain analyze select stddev_pop(double_column) from data_types;
explain analyze select stddev_pop(decimal_column) from data_types;
explain analyze select stddev(smallint_column) from data_types;
explain analyze select stddev(int_column) from data_types;
explain analyze select stddev(bigint_column) from data_types where bigint_column < 1000;
explain analyze select stddev(float_column) from data_types;
explain analyze select stddev(double_column) from data_types;
explain analyze select stddev(decimal_column) from data_types;
2.8 oid运算符
| 716 | Oid oddlt(oid oid) | 不支持,oid类型没有注册 | |
|---|
| 717 | Oid oidle(oid oid) | 不支持,oid类型没有注册 | |
| 184 | Oid oideq(oid oid) | 不支持,oid类型没有注册 | |
| 185 | Oid oidne(oid oid) | 不支持,oid类型没有注册 | |
| 1638 | Oid oidgt(oid oid) | 不支持,oid类型没有注册 | |
| 1639 | Oid oidge(oid oid) | 不支持,oid类型没有注册 | |
| 1965 | Oid oidlarger(oid oid) | 不支持,oid类型没有注册 | |
| 1966 | oid oidsmaller(oid oid) | 不支持,oid类型没有注册 | |
| 677 | bool oidvectorlt(oidvector oidvector) | 类型错误 | |
| 678 | bool oidvectorle(oidvector oidvector) | 类型错误 | |
| 679 | bool oidvectoreq(oidvector oidvector) | 类型错误 | |
| 619 | bool oidvectorne(oidvector oidvector) | 类型错误 | |
| 681 | bool oidvectorgt(oidvector oidvector) | 类型错误 | |
| 680 | bool oidvectorge(oidvector oidvector) | 类型错误 | |
2.9 name运算符
| oid | 函数声明 | 支持情况 | 备注 |
|---|
| 655 | bool namelt(name name) | 不支持 | |
| 656 | bool namele(name name) | 不支持 | |
| 62 | bool nameeq(name name) | 不支持 | |
| 659 | bool namene(name name) | 不支持 | |
| 657 | bool namegt(name name) | 不支持 | |
| 658 | bool namege(name name) | 不支持 | |
| 241 | bool namelttext(name text) | 不支持 | |
| 242 | bool nameletext(name text) | 不支持 | |
| 240 | bool nameeqtext(name text) | 不支持 | |
| 245 | bool namenetext(name text) | 不支持 | |
| 244 | bool namegttext(name text) | 不支持 | |
| 243 | bool namegetext(name text) | 不支持 | |
| 248 | bool textltname(text anme) | 不支持 | |
| 249 | bool textlename(text name) | 不支持 | |
| 247 | bool texteqname(text name) | 不支持 | |
| 252 | bool textnename(text name) | 不支持 | |
| 251 | bool textgtname(text name) | 不支持 | |
| 250 | Bool textgename(text name) | 不支持 | |
CREATE TABLE names (
id serial PRIMARY KEY,
name1 name,
name2 name
);
INSERT INTO names (name1, name2) VALUES ('table_a', 'table_b');
INSERT INTO names (name1, name2) VALUES ('table_z', 'table_a');
INSERT INTO names (name1, name2) VALUES ('table_x', 'table_y');
INSERT INTO names (name1, name2) VALUES ('table_y', 'table_y');
explain analyze select namelt(name1, name2) from names;
explain analyze select namele(name1, name2) from names;
explain analyze select nameeq(name1, name2) from names;
explain analyze select namene(name1, name2) from names;
explain analyze select namegt(name1, name2) from names;
explain analyze select namege(name1, name2) from names;
explain analyze select namelttext(name2, '12'::text) from names;
explain analyze select nameletext(name2, '12'::text) from names;
explain analyze select nameeqtext(name2, '12'::text) from names;
explain analyze select namenetext(name2, '12'::text) from names;
explain analyze select namegttext(name2, '12'::text) from names;
explain analyze select namegetext( name2, '12'::text) from names;
explain analyze select textltname('12'::text, name1) from names;
explain analyze select textlename('12'::text, name1) from names;
explain analyze select texteqname('12'::text, name1) from names;
explain analyze select textnename('12'::text, name1) from names;
explain analyze select textgtname('12'::text, name1) from names;
explain analyze select textgename('12'::text, name1) from names;
2.10 窗口函数
| oid | 函数声明 | 支持情况 | 备注 |
|---|
| 3100 | int8 row_number() | 不支持 | |
| 3101 | int8 rank() | 不支持 | |
| 3102 | int8 dense_rank() | 不支持 | |
CREATE TABLE orders (
order_id serial PRIMARY KEY,
customer_name text,
order_date date,
amount numeric
);
INSERT INTO orders (customer_name, order_date, amount)
VALUES ('Alice', '2023-01-01', 100.00),
('Bob', '2023-01-01', 200.00),
('Alice', '2023-01-02', 150.00),
('Charlie', '2023-01-02', 300.00),
('Bob', '2023-01-03', 250.00),
('Alice', '2023-01-03', 175.00);
SELECT
customer_name,
order_date,
amount,
row_number() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;
SELECT
customer_name,
order_date,
amount,
rank() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;
SELECT
customer_name,
order_date,
amount,
dense_rank() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;
DROP TABLE orders;