Fix user var bug in plsql.
This commit is contained in:
@ -1266,6 +1266,11 @@ static List* pg_rewrite_query(Query* query)
|
||||
PrepareStmt *stmt = (PrepareStmt *)query->utilityStmt;
|
||||
if (IsA(stmt->query, UserVar)) {
|
||||
querytree_list = QueryRewritePrepareStmt(query);
|
||||
} else if (IsA(stmt->query, Const)) {
|
||||
if (((Const *)stmt->query)->constisnull) {
|
||||
ereport(ERROR, (errcode(ERRCODE_UNRECOGNIZED_NODE_TYPE),
|
||||
errmsg("userdefined variable in prepare statement must be text type.")));
|
||||
}
|
||||
} else {
|
||||
querytree_list = list_make1(query);
|
||||
}
|
||||
|
||||
@ -1096,6 +1096,7 @@ static Datum ExecEvalConst(ExprState* exprstate, ExprContext* econtext, bool* is
|
||||
if (found) {
|
||||
if (entry->isParse) {
|
||||
con = (Const *)uservar->value;
|
||||
entry->isParse = false;
|
||||
} else {
|
||||
Node *node = coerce_type(NULL, (Node *)entry->value, entry->value->consttype, ((Const *)uservar->value)->consttype,
|
||||
-1, COERCION_IMPLICIT, COERCE_IMPLICIT_CAST, -1);
|
||||
|
||||
@ -1648,6 +1648,33 @@ select @a_1131028:=cast(2 as number);
|
||||
2
|
||||
(1 row)
|
||||
|
||||
DROP PROCEDURE IF EXISTS load_tbtest_WITH_REPLACE;
|
||||
NOTICE: function load_tbtest_with_replace() does not exist, skipping
|
||||
CREATE PROCEDURE load_tbtest_WITH_REPLACE(id_count IN INT) AS
|
||||
BEGIN
|
||||
SET @id = 1;
|
||||
WHILE @id <= id_count LOOP
|
||||
raise info 'id is %',@id;
|
||||
IF @id % 10 = 0 THEN
|
||||
SET @lsql = '';
|
||||
END IF;
|
||||
SET @id = @id + 1;
|
||||
raise info 'id+ is %',@id;
|
||||
END LOOP;
|
||||
END;
|
||||
/
|
||||
call load_tbtest_WITH_REPLACE(3);
|
||||
INFO: id is 1
|
||||
INFO: id+ is 2
|
||||
INFO: id is 2
|
||||
INFO: id+ is 3
|
||||
INFO: id is 3
|
||||
INFO: id+ is 4
|
||||
load_tbtest_with_replace
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
set enable_set_variable_b_format = 0;
|
||||
select @var_t_1 := 2;
|
||||
ERROR: syntax error at or near ":="
|
||||
|
||||
@ -539,7 +539,21 @@ select @a_1131028:=cast('x' as text);
|
||||
select @a_1131028:=cast(2 as int);
|
||||
select @a_1131028:=cast(2 as number);
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS load_tbtest_WITH_REPLACE;
|
||||
CREATE PROCEDURE load_tbtest_WITH_REPLACE(id_count IN INT) AS
|
||||
BEGIN
|
||||
SET @id = 1;
|
||||
WHILE @id <= id_count LOOP
|
||||
raise info 'id is %',@id;
|
||||
IF @id % 10 = 0 THEN
|
||||
SET @lsql = '';
|
||||
END IF;
|
||||
SET @id = @id + 1;
|
||||
raise info 'id+ is %',@id;
|
||||
END LOOP;
|
||||
END;
|
||||
/
|
||||
call load_tbtest_WITH_REPLACE(3);
|
||||
|
||||
set enable_set_variable_b_format = 0;
|
||||
select @var_t_1 := 2;
|
||||
|
||||
Reference in New Issue
Block a user