B库下insert、upsert的用户变量与列名相同时,取用户变量优先级最高,与MySQL保持一致

This commit is contained in:
laishenghao
2022-12-01 16:19:18 +08:00
parent f4f3dd08ac
commit c0ab0b37c1
4 changed files with 51 additions and 5 deletions

View File

@ -966,10 +966,15 @@ Node* transformColumnRef(ParseState* pstate, ColumnRef* cref)
if (node == NULL) {
node = hookresult;
} else if (hookresult != NULL) {
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
errmsg("column reference \"%s\" is ambiguous", NameListToString(cref->fields)),
parser_errposition(pstate, cref->location)));
if (IS_SUPPORT_RIGHT_REF(pstate->rightRefState)) {
node = hookresult;
} else {
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
errmsg("column reference \"%s\" is ambiguous", NameListToString(cref->fields)),
parser_errposition(pstate, cref->location)));
}
}
}

View File

@ -1621,7 +1621,7 @@ static Node* plpgsql_post_column_ref(ParseState* pstate, ColumnRef* cref, Node*
*/
Node* myvar = resolve_column_ref(pstate, expr, cref, (var == NULL));
if (myvar != NULL && var != NULL) {
if (myvar != NULL && var != NULL && !IS_SUPPORT_RIGHT_REF(pstate->rightRefState)) {
/*
* We could leave it to the core parser to throw this error, but we
* can add a more useful detail message than the core could.

View File

@ -148,5 +148,29 @@ select * from upser order by c1;
(15 rows)
drop table upser;
-- test var
create table with_var(a int default 999);
create function with_var_func() return int as
declare
a int := 666;
begin
insert into with_var values(a);
return a;
end;
/
call with_var_func();
with_var_func
---------------
666
(1 row)
select * from with_var;
a
-----
666
(1 row)
drop function with_var_func;
drop table with_var;
\c postgres
drop database rightref;

View File

@ -65,6 +65,23 @@ select * from upser order by c1;
drop table upser;
-- test var
create table with_var(a int default 999);
create function with_var_func() return int as
declare
a int := 666;
begin
insert into with_var values(a);
return a;
end;
/
call with_var_func();
select * from with_var;
drop function with_var_func;
drop table with_var;
\c postgres
drop database rightref;