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=# 
相关推荐
猫咪-952714 分钟前
【金仓数据库征文】——选择金仓,选择胜利
数据库·金仓数据库 2025 征文·数据库平替用金仓
努力进修1 小时前
【金仓数据库征文】-金仓数据库性能调优 “快准稳” 攻略:实战优化,让数据处理飞起来
数据库·人工智能·金仓数据库 2025 征文·数据库平替用金仓
User_芊芊君子2 小时前
【金仓数据库征文】金仓数据库KingbaseES:千行百业国产化征程中的璀璨之星
数据库·数据库平替用金仓·金仓数据库2025征文
User_芊芊君子3 小时前
【金仓数据库征文】金仓数据库KingbaseES:在技术与人文交织中开拓信创未来
数据库·数据库平替用金仓·金仓数据库2025征文
傻啦嘿哟4 小时前
Python正则表达式:用“模式密码“解锁复杂字符串
linux·数据库·mysql
辰哥单片机设计6 小时前
JW01三合一传感器详解(STM32)
数据库·mongodb
小刘同学++6 小时前
Qt使用 SQLite 数据库的基本方法
数据库·qt·sqlite
施嘉伟9 小时前
Oracle 11g RAC ASM磁盘组剔盘、加盘实施过程
数据库·oracle
橘猫云计算机设计10 小时前
springboot基于hadoop的酷狗音乐爬虫大数据分析可视化系统(源码+lw+部署文档+讲解),源码可白嫖!
数据库·hadoop·spring boot·爬虫·python·数据分析·毕业设计
卓怡学长10 小时前
w304基于HTML5的民谣网站的设计与实现
java·前端·数据库·spring boot·spring·html5