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=# 
相关推荐
傻啦嘿哟42 分钟前
Python 数据分析与可视化实战:从数据清洗到图表呈现
大数据·数据库·人工智能
cookqq1 小时前
mongodb源码分析session异步接受asyncSourceMessage()客户端流变Message对象
数据库·sql·mongodb·nosql
呼拉拉呼拉1 小时前
Redis故障转移
数据库·redis·缓存·高可用架构
什么都想学的阿超1 小时前
【Redis系列 04】Redis高可用架构实战:主从复制与哨兵模式从零到生产
数据库·redis·架构
pp-周子晗(努力赶上课程进度版)2 小时前
【MySQL】视图、用户管理、MySQL使用C\C++连接
数据库·mysql
斯特凡今天也很帅2 小时前
clickhouse常用语句汇总——持续更新中
数据库·sql·clickhouse
超级小忍3 小时前
如何配置 MySQL 允许远程连接
数据库·mysql·adb
吹牛不交税3 小时前
sqlsugar WhereIF条件的大于等于和等于查出来的坑
数据库·mysql
hshpy4 小时前
setting up Activiti BPMN Workflow Engine with Spring Boot
数据库·spring boot·后端
文牧之5 小时前
Oracle 审计参数:AUDIT_TRAIL 和 AUDIT_SYS_OPERATIONS
运维·数据库·oracle