更新时间:2024-05-14 GMT+08:00

系统函数

GaussDB数据库兼容绝大多数MySQL的系统函数,但存在部分差异。只能使用M-Compatibility兼容模式下的系统函数,不能使用原GaussDB的系统函数,避免产生非预期的结果。当前存在原GaussDB的系统函数和MySQL系统函数同名,但是M-Compatibility兼容模式下尚未支持这些函数的情况;一部分未支持的同名函数会提示用户在M-Compatibility兼容模式下不支持,另外一部分同名函数仍然保持原GaussDB系统函数的行为。用户禁止使用这些同名函数,避免产生非预期的结果。具体同名函数列表如下:

表1 M-Compatibility兼容模式下提示不支持的同名函数

cot

isEmpty

json_append

json_array

json_array_append

json_array_insert

json_contains

json_contains_path

json_depth

json_extract

json_insert

json_keys

json_length

json_merge

json_merge_patch

json_merge_preserve

json_object

json_quote

json_remove

json_valid

json_replace

json_search

json_set

json_type

json_unquote

last_insert_id

md5

mod

octet_length

overlaps

point

radians

stddev_pop

stddev_samp

var_pop

var_samp

variance

lag

lead

-

表2 M-Compatibility兼容模式下保持原GaussDB系统函数行为的同名函数

ceil

decode

encode

format

instr

position

round

stddev

regexp_instr

regexp_like

regexp_replace

regexp_substr

row_num

-

-

M-Compatibility兼容模式下,系统函数存在以下公共差异:

  1. 系统函数的返回值类型仅考虑入参node类型为Var(表中数据)和Const(常量输入)类型时的情况与MySQL保持一致,其他情况(如入参为运算表达式、函数表达式等)可能返回值的类型与MySQL有差异。
  2. 当聚合函数以其他函数、操作符或SELECT子句等表达式作为入参时(如SELECT sum(abs(n)) FROM t;),聚合函数将获取不到入参表达式传递的精度信息,导致函数的结果精度与MySQL有差异。