fix(contrib/drivers/pgsql): Fixed the problem of overlapping fields in the same table name in pgsql multiple schema mode (#4375)

Co-authored-by: hailaz <739476267@qq.com>
This commit is contained in:
iamcc
2025-11-19 18:03:52 +08:00
committed by GitHub
parent a85b221d32
commit 362d4202c4
2 changed files with 5 additions and 5 deletions

View File

@ -27,7 +27,7 @@ FROM pg_attribute a
left join pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid
left join pg_type t ON a.atttypid = t.oid
left join information_schema.columns ic on ic.column_name = a.attname and ic.table_name = c.relname
WHERE c.relname = '%s' and a.attisdropped is false and a.attnum > 0
WHERE c.oid = '%s'::regclass and a.attisdropped is false and a.attnum > 0
ORDER BY a.attnum`
)

View File

@ -339,8 +339,8 @@ int_col INT);`
IntCol int64
}
// pgsql converts table names to lowercase
// mark: [c.oid = '%s'::regclass] is not case-sensitive
tableName := "Error_table"
errStr := fmt.Sprintf(`The table "%s" may not exist, or the table contains no fields`, tableName)
_, err := db.Exec(ctx, fmt.Sprintf(createSql, tableName))
gtest.AssertNil(err)
defer dropTable(tableName)
@ -351,7 +351,7 @@ int_col INT);`
IntCol: 2,
}
_, err = db.Model(tableName).Data(data).Insert()
t.Assert(err, errStr)
t.AssertNE(err, nil)
// Insert a piece of test data using lowercase
_, err = db.Model(strings.ToLower(tableName)).Data(data).Insert()
@ -360,7 +360,7 @@ int_col INT);`
_, err = db.Model(tableName).Where("id", 1).Data(g.Map{
"int_col": 9999,
}).Update()
t.Assert(err, errStr)
t.AssertNE(err, nil)
})
// The inserted field does not exist in the table
@ -370,7 +370,7 @@ int_col INT);`
"int_col_22": 11111,
}
_, err = db.Model(tableName).Data(data).Insert()
t.Assert(err, errStr)
t.Assert(err, fmt.Errorf(`input data match no fields in table "%s"`, tableName))
lowerTableName := strings.ToLower(tableName)
_, err = db.Model(lowerTableName).Data(data).Insert()