From c98930f8f2a5827f54376b5e23467d29acca6ef5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 3 Jun 2022 15:24:24 +0800 Subject: [PATCH] Fix oid index for postgres (#2154) Reviewed-on: https://gitea.com/xorm/xorm/pulls/2154 --- dialects/postgres.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index 83e4187f..ba73aad7 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -862,11 +862,11 @@ func (db *postgres) needQuote(name string) bool { func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) { switch quotePolicy { case QuotePolicyNone: - var q = postgresQuoter + q := postgresQuoter q.IsReserved = schemas.AlwaysNoReserve db.quoter = q case QuotePolicyReserved: - var q = postgresQuoter + q := postgresQuoter q.IsReserved = db.needQuote db.quoter = q case QuotePolicyAlways: @@ -1125,7 +1125,7 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A col.Name = strings.Trim(colName, `" `) if colDefault != nil { - var theDefault = *colDefault + theDefault := *colDefault // cockroach has type with the default value with ::: // and postgres with ::, we should remove them before store them idx := strings.Index(theDefault, ":::") @@ -1301,15 +1301,8 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN } colNames = getIndexColName(indexdef) - isSkip := false - //Oid It's a special index. You can't put it in - for _, element := range colNames { - if "oid" == element { - isSkip = true - break - } - } - if isSkip { + // Oid It's a special index. You can't put it in. TODO: This is not perfect. + if indexName == tableName+"_oid_index" && len(colNames) == 1 && colNames[0] == "oid" { continue }