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=# 
相关推荐
钝挫力PROGRAMER24 分钟前
实战经验:如何修复 MariaDB 因 InnoDB 损坏导致的启动失败 (status=6/ABRT)
数据库·mariadb
我是一颗柠檬25 分钟前
【MySQL全面教学】MySQL基础与环境搭建Day1(2026年)
数据库·后端·sql·mysql·database
我是一颗柠檬25 分钟前
【MySQL全面教学】MySQL数据类型详解Day2(2026年)
数据库·后端·sql·mysql·database
一只fish28 分钟前
Oracle官方文档翻译《Database Concepts 26ai》第10章-SQL
数据库·oracle
jnrjian34 分钟前
export partition 的par file
数据库·oracle
空中海39 分钟前
Redis知识图谱和回顾
数据库·redis·知识图谱
不甘先生1 小时前
PostgreSQL 数据库基础一览表
数据库·postgresql
DBdoctor官方1 小时前
2026 DBA实测推荐:5款数据库管理工具 监控、SQL审核、AI能力横评
数据库·sql·dba
qq_196976171 小时前
硬核项目管理:Gemini境像站驱动的WBS自动分解、关键路径识别与风险登记册生成(国内免费镜像实测)
数据库
迷枫7121 小时前
DM8 读写分离集群学习总结:从部署规划到扩容排查
数据库·学习