From a6d2bfb4baa0f5319a648c7e26823018d8d239f1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 9 Jun 2021 14:07:34 +0800 Subject: [PATCH] Compitable with cockroach (#1930) Fix #1292 Reviewed-on: https://gitea.com/xorm/xorm/pulls/1930 Co-authored-by: Lunny Xiao Co-committed-by: Lunny Xiao --- dialects/postgres.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index e76e5b7e..7a2cd87d 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -1221,7 +1221,8 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN continue } indexName = strings.Trim(indexName, `" `) - if strings.HasSuffix(indexName, "_pkey") { + // ignore primary index + if strings.HasSuffix(indexName, "_pkey") || strings.EqualFold(indexName, "primary") { continue } if strings.HasPrefix(indexdef, "CREATE UNIQUE INDEX") { @@ -1241,7 +1242,9 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)} for _, colName := range colNames { - index.Cols = append(index.Cols, strings.TrimSpace(strings.Replace(colName, `"`, "", -1))) + col := strings.TrimSpace(strings.Replace(colName, `"`, "", -1)) + fields := strings.Split(col, " ") + index.Cols = append(index.Cols, fields[0]) } index.IsRegular = isRegular indexes[index.Name] = index