MDEV-38329 Named parameters in stored procedure CALL#4902
Open
MooSayed1 wants to merge 1 commit intoMariaDB:mainfrom
Open
MDEV-38329 Named parameters in stored procedure CALL#4902MooSayed1 wants to merge 1 commit intoMariaDB:mainfrom
MooSayed1 wants to merge 1 commit intoMariaDB:mainfrom
Conversation
Add support for named parameter syntax using => in CALL statements: CALL proc(a => 1, b => 2); CALL proc(1, b => 2, c => 3); CALL proc(a => 1, c => 3); Parser: added sp_cparam rule in sql_yacc.yy to accept ident ARROW_SYM expr. Named args set IS_EXPLICIT_NAME and store the name in Item::name, reusing the UDF named argument mechanism. Positional args after named args are rejected at parse time. Reordering: in sp_head::execute_procedure(), named args are matched against sp_pcontext formal parameters and reordered to declared positions. Omitted params with defaults are filled from sp_variable::default_value. Unknown names, duplicates, and missing required params are detected at execution time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Jira issue number for this PR is: MDEV-38329
Description
Stored procedures currently require all arguments to be passed positionally.
When a routine has many parameters with defaults, there is no way to skip
middle parameters — only trailing ones can be omitted.
This patch adds named parameter invocation using the
=>syntax:This brings MariaDB in line with Oracle, PostgreSQL, SQL Server, and Firebird,
all of which already support named parameter invocation.
Parser changes (
sql/sql_yacc.yy):Added
sp_cparamrule to acceptident ARROW_SYM expralongside plainexprin CALL argument lists. Named arguments set
IS_EXPLICIT_NAMEon the Item andstore the parameter name in
Item::name, reusing the same mechanism that UDFnamed arguments already use. Positional arguments after a named argument are
rejected at parse time.
Reordering (
sql/sp_head.cc):In
sp_head::execute_procedure(), before the binding loop, named arguments arematched against
sp_pcontext's formal parameter list by name and reordered totheir declared positions. Omitted parameters with defaults are filled from
sp_variable::default_value. The following errors are detected:ER_SP_UNDECLARED_VAR)ER_SP_UNDECLARED_VAR)ER_SP_WRONG_NO_OF_ARGS)Current status
Done:
CALL proc(a => 1, b => 2)syntax acceptedCALL proc(1, b => 2)execute_procedure()Still working on:
SELECT func(a => 1))PREPARE stmt FROM 'CALL p(a => ?)')This PR is a work in progress. Reviews and feedback on the current approach are welcome.
Release Notes
Stored procedures now support named parameter invocation using the
=>syntax.Arguments can be passed by name in any order, and parameters with default values
can be skipped:
CALL proc(a => 1, c => 3).How can this PR be tested?
The test covers:
Basing the PR against the correct MariaDB version
This is a new feature. The PR targets
main.PR quality check