401 Star 1.4K Fork 1.5K

GVPopenGauss / openGauss-server

 / 详情

创建三个同名函数,调用函数返回结果不对

已取消
缺陷
创建于  
2022-12-01 12:29

【标题描述】:
【测试类型:SQL功能/存储功能/接口功能/工具功能/性能/并发/压力长稳/故障注入/安全/资料/编码规范】【测试版本:2.0.0】 问题描述

【操作系统和硬件信息】(查询命令: cat /etc/system-release, uname -a):
单机
【测试环境】(单机/1主x备x级联备):
dan j
【被测功能】:
函数重载
【测试类型】:
功能
【数据库版本】(查询命令: gaussdb –V):
输入图片说明
【预置条件】:

【操作步骤】(请填写详细的操作步骤):
1、创建函数,入参为with time zone
create or replace function timefunc(i time(2) with time zone) returns time(2) with time zone as $$
begin return i; end;$$ language plpgsql;

2、创建函数,入参为with time zone
create or replace function timefunc(i time(2) without time zone) returns time(2) without time zone as $$
begin return i; end;$$ language plpgsql;

3、调用函数
select timefunc('21:21:21');--这一步应该返回21:21:21,实际返回的是默认给加了时区:
输入图片说明

4、再次创建一个同名函数,入参为tinyint类型
create or replace function timefunc(i tinyint) returns tinyint as $$
begin return i; end;$$ language plpgsql;
5、再次调用函数
select timefunc('21:21:21');--调用直接报错,见下图:
输入图片说明

【预期输出】:

【实际输出】:

【原因分析】:

  1. 这个问题的根因
  2. 问题推断过程
  3. 还有哪些原因可能造成类似现象
  4. 该问题是否有临时规避措施
  5. 问题解决方案
  6. 预计修复问题时间

【日志信息】(请附上日志文件、截图、coredump信息):

【测试代码】:

评论 (3)

caicurry 创建了缺陷

Hey @caicurry, Welcome to openGauss Community.
All of the projects in openGauss Community are maintained by @opengauss-bot.
That means the developers can comment below every pull request or issue to trigger Bot Commands.
Please follow instructions at Here to find the details.

Hi @caicurry, please use the command /sig xxx to add a SIG label to this issue.
For example: /sig sqlengine or /sig storageengine or /sig om or /sig ai and so on.
You can find more SIG labels from Here.
If you have no idea about that, please contact with @xiangxinyong , @zhangxubo .

yansong_lee 负责人设置为pengjiong
yansong_lee 优先级设置为次要
pengjiong 添加协作者pengjiong
pengjiong 负责人pengjiong 修改为Cross-罗
胡正超 负责人Cross-罗 修改为未设置
胡正超 取消协作者pengjiong
胡正超 负责人设置为Carl
胡正超 负责人Carl 修改为胡正超
胡正超 添加协作者胡正超
胡正超 负责人胡正超 修改为Carl
胡正超 取消协作者胡正超
胡正超 添加协作者胡正超

两个问题均为非问题 ,函数匹配时如果出现多个可选项,需要匹配入参的优先级,并选择优先级高的那个函数进行调用。
第一个问题,在openGauss中,time类型和timetz类型同属Datetime,因此需要对比同类中的优先级,代码中明确规定timetz的优先级比time高,所以匹配了timetz类型,这个是正常现象
输入图片说明

第二个问题,openGauss中,tinyint属于Numeric类别数据类型,time属于Datetime类别数据类型,在类型转换时,Numeric类别总是高于Datetime类别。
输入图片说明
如果入参是一个字符串,那它就有两种调用选择,一种是调用入参为tinyint的timefunc,另一种是调用入参为time的timefunc。此时就需要有一个类型转换优先级,看这个字符串入参应该匹配哪一个类型,由于上述说过Numeric的优先级高于Datetime,所以就匹配了tinyint。又因为字符串的输入格式对于tinyint来说是非法的,因此报错。
如果想要让这两个语句成功,可以利用'::type_name'这种形式对字符串进行强制转换,如下所示:
输入图片说明
输入图片说明

胡正超 负责人Carl 修改为Cross-罗
胡正超 取消协作者胡正超
yansong_lee 任务状态待办的 修改为已取消

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(3)
5622128 opengauss bot 1581905080
C++
1
https://gitee.com/opengauss/openGauss-server.git
git@gitee.com:opengauss/openGauss-server.git
opengauss
openGauss-server
openGauss-server

搜索帮助