LightDB 函数/存储过程支持在任意位置使用默认值【24.1】【oracle 兼容】

LightDB 函数/存储过程支持在任意位置使用默认值

在之前的版本中,在 LightDB 中创建的函数或存储过程,每个有默认值的参数后面的参数都需要有默认值(同c++中函数, 默认值从右向左赋值)。

在 24.1 版本中支持oracle 中的默认值用法,有默认值的参数后面的参数可以没有默认值。

示例

在有默认值的参数后面的参数没有默认值情况下,在pg_proc 对于没有默认值的参数,会有 null 的默认值, 实际不会使用,对于这种参数,仍需传入参数函数才能使用 。可以结合lt_proc_ext 的procconfig字段,默认值对应的参数id 为-1,则表示为伪默认值,不会实际使用。

lightdb@postgres=# create database test_o with lightdb_syntax_compatible_type oracle;
NOTICE:  role "test_o" already exists
CREATE DATABASE
lightdb@postgres=# \c test_o 
You are now connected to database "test_o" as user "lightdb".
compatible type: oracle

create function testfd
(
    a1 int,
    a2 varchar default '2',
    a3 varchar,
    a4 int default 14
)
return varchar as
begin
    return a1 || ' @ ' || a2 ||  ' @ ' || a3 || ' @ ' || a4;
end;
/

lightdb@test_o=# select proname, proaccess, procconfig from lt_proc_ext where proname = 'testfd' order by oid;
 proname | proaccess |                         procconfig                         
---------+-----------+------------------------------------------------------------
 testfd  | n         | {PROCCONFIG :argDefaultCount 3 :argDefaultIndexes  1 -1 3}
(1 row)

lightdb@test_o=# select pg_get_expr(proargdefaults,0) from pg_proc where proname ='testfd';
                     pg_get_expr                     
-----------------------------------------------------
 '2'::character varying, NULL::character varying, 14
(1 row)

lightdb@test_o=# 
lightdb@test_o=# select testfd(a1=>1, a3=>'q');
     testfd     
----------------
 1 @ 2 @ q @ 14
(1 row)

lightdb@test_o=# select testfd(1, '2', '3');
     testfd     
----------------
 1 @ 2 @ 3 @ 14
(1 row)

lightdb@test_o=# select testfd(1);
ERROR:  function testfd(integer) does not exist
LINE 1: select testfd(1);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_o=# 
相关推荐
阿华的代码王国几秒前
MySQL ------- 索引(B树B+树)
数据库·mysql
Hello.Reader28 分钟前
StarRocks实时分析数据库的基础与应用
大数据·数据库
执键行天涯30 分钟前
【经验帖】JAVA中同方法,两次调用Mybatis,一次更新,一次查询,同一事务,第一次修改对第二次的可见性如何
java·数据库·mybatis
yanglamei196240 分钟前
基于GIKT深度知识追踪模型的习题推荐系统源代码+数据库+使用说明,后端采用flask,前端采用vue
前端·数据库·flask
工作中的程序员1 小时前
ES 索引或索引模板
大数据·数据库·elasticsearch
严格格1 小时前
三范式,面试重点
数据库·面试·职场和发展
微刻时光1 小时前
Redis集群知识及实战
数据库·redis·笔记·学习·程序人生·缓存
单字叶2 小时前
MySQL数据库
数据库·mysql
mqiqe2 小时前
PostgreSQL 基础操作
数据库·postgresql·oracle
just-julie2 小时前
MySQL面试题——第一篇
数据库·mysql