[MDEV-6980] OUT parameters in PREPARE Created: 2014-10-29  Updated: 2017-08-14  Resolved: 2014-12-04

Status: Closed
Project: MariaDB Server
Component/s: Prepared Statements
Fix Version/s: 10.1.2

Type: Task Priority: Blocker
Reporter: Sergei Golubchik Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None


 Description   

Current — 10.1.1 — implementation of OUT parameters in PREPARE is as follows:

PREPARE .... "SELECT ... INTO ?, ?, ...";
EXECUTE .... USING @var1, @var2, ...

It is non-standard. And it's not strictly necessary, as there are easy workarounds.

Standard syntax is

PREPARE .... "SELECT ... ";
EXECUTE ... INTO @var1, @var2, ...

The workaround is:

PREPARE .... "SELECT ... INTO @var1, @var2, ...";
EXECUTE ....

We should consider changing the syntax to be standard or removing this feature completely.



 Comments   
Comment by Sergei Golubchik [ 2014-12-04 ]

removed completely

Comment by Richard Bensley [ 2017-08-11 ]

@serg, are we going to see a return of this? Or something similar?

Parameterised stored procedure SQL would be very VERY useful for dynamic table names, infile/outfile names, etc.

Comment by Sergei Golubchik [ 2017-08-12 ]

it's not about parameterised stored procedure SQL, it's output parameters in PREPARE, dynamic SQL.

Comment by Richard Bensley [ 2017-08-14 ]

Hi @serg, yes I understand.I see there were some great changes made in MDEV-10866.

This is roughly what I mean, instead of create extremely large concat statements for analytics work loads to generate new tables and outfiles.

e.g:

SET @source_table=source_table_name;
SET @new_table_name=CONCAT("source_table_name", CURDATE());
 
PREPARE stmt FROM "CREATE TABLE @new_table AS SELECT ... FROM @source_table";

Also for outfiles!

PREPARE out_stmt FROM "SELECT * FROM @table INTO OUTFILE '@outfile_name' @TERMINATION_PARMATERS;"

Does that make sense? Our analytics sql is hundreds of lines long, I generally wrap SQL with something like python to generate data instead of using stored procedures.

Comment by Sergei Golubchik [ 2017-08-14 ]

It makes sense. But the problem is that a parameter ­— OUT or IN, in PREPARE or in the protocol level prepared statements, even in stored procedures — it's an expression and can be used anywhere where an expression is allowed. In particular, table names cannot be parameters.

Generated at Thu Feb 08 07:16:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.