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=# 
相关推荐
@爱学习的小趴菜16 小时前
Redis服务器配置
服务器·数据库·redis
寒秋丶17 小时前
Milvus:向量字段-二进制向量、稀疏向量与密集向量(六)
数据库·人工智能·python·ai·ai编程·milvus·向量数据库
寒秋丶17 小时前
Milvus:通过Docker安装Milvus向量数据库(一)
数据库·人工智能·docker·ai·ai编程·milvus·rag
Maỿbe18 小时前
Redis的持久化
数据库·redis·缓存
努力学习的小廉19 小时前
初识MYSQL —— 基本查询
数据库·mysql·1024程序员节
许泽宇的技术分享19 小时前
让数据库“听懂“人话:Text2Sql.Net 深度技术解析
数据库·.net
珊珊而川20 小时前
MAC-SQL 算法一
数据库·sql·oracle
听风吟丶21 小时前
深入解析 Spring Boot 自动配置:原理、实践与进阶
java·数据库·sql
风语者日志21 小时前
[LitCTF 2023]这是什么?SQL !注一下 !
android·数据库·sql
lang2015092821 小时前
Spring Boot 核心技巧与实战指南
java·数据库·spring boot