SetUpsertAttrnoState bug

This commit is contained in:
nnuanyang
2023-11-15 01:29:26 -08:00
parent 3172134f4c
commit da0106aebb
3 changed files with 29 additions and 9 deletions

View File

@ -1626,19 +1626,21 @@ static void SetUpsertAttrnoState(ParseState* pstate, List *targetList)
for (int ni = 0; ni < len; ++ni) {
ResTarget* res = (ResTarget*)lfirst(target);
char* name = nullptr;
if (list_length(res->indirection) > 0) {
name = ((Value*)llast(res->indirection))->val.str;
if (list_length(res->indirection) > 0 && IsA(linitial(res->indirection), String)) {
name = strVal(linitial(res->indirection));
} else {
name = res->name;
}
for (int ci = 0; ci < colNum; ++ci) {
if (attr[ci].attisdropped) {
continue;
}
if (strcmp(name, attr[ci].attname.data) == 0) {
rstate->usExplicitAttrNos[ni] = ci + 1;
break;
if (name != NULL) {
for (int ci = 0; ci < colNum; ++ci) {
if (attr[ci].attisdropped) {
continue;
}
if (strcmp(name, attr[ci].attname.data) == 0) {
rstate->usExplicitAttrNos[ni] = ci + 1;
break;
}
}
}

View File

@ -105,3 +105,15 @@ drop table test_roundrobin;
--insert into pg_auth_history
insert into pg_auth_history values(10, '2015-110-10 08:00:00.57603+08', 'sha256232f8630ce6af1095f6db3ed4c05a48747038936d42176e1103594d43c7d1adc4aca54361a23e51c6cd9371ccc95776450219376e45bcca01e27a7f06bf8088a8b1a9e280cdcc315c8134879818442bc3e92064a70e27b2ea83fcf6990a607d0');
ERROR: Not allowed to insert into relation pg_auth_history.
-- insert upsert
drop table if exists t_grammer;
NOTICE: table "t_grammer" does not exist, skipping
create table t_grammer(c1 INT PRIMARY KEY, c2 int, C3 INT[3]);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_grammer_pkey" for table "t_grammer"
insert into t_grammer values(12,2) on duplicate key update c2=2,c3[1]=3;
select * from t_grammer;
c1 | c2 | c3
----+----+----
12 | 2 |
(1 row)

View File

@ -64,3 +64,9 @@ drop table test_roundrobin;
--insert into pg_auth_history
insert into pg_auth_history values(10, '2015-110-10 08:00:00.57603+08', 'sha256232f8630ce6af1095f6db3ed4c05a48747038936d42176e1103594d43c7d1adc4aca54361a23e51c6cd9371ccc95776450219376e45bcca01e27a7f06bf8088a8b1a9e280cdcc315c8134879818442bc3e92064a70e27b2ea83fcf6990a607d0');
-- insert upsert
drop table if exists t_grammer;
create table t_grammer(c1 INT PRIMARY KEY, c2 int, C3 INT[3]);
insert into t_grammer values(12,2) on duplicate key update c2=2,c3[1]=3;
select * from t_grammer;