From f25d0eedf2b7aa38220c3ad4551d7eb8f940f389 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 24 Apr 2020 22:45:31 +0800 Subject: [PATCH] add greenplum support --- dialects/green_plum.go | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 dialects/green_plum.go diff --git a/dialects/green_plum.go b/dialects/green_plum.go new file mode 100644 index 00000000..88b3bbb9 --- /dev/null +++ b/dialects/green_plum.go @@ -0,0 +1,64 @@ +// Copyright 2020 The Xorm Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package dialects + +import ( + "fmt" + "strings" + + "xorm.io/xorm/schemas" +) + +type greenplum struct { + postgres +} + + +func (db *greenplum) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) { + var sql string + sql = "CREATE TABLE IF NOT EXISTS " + if tableName == "" { + tableName = table.Name + } + + quoter := db.Quoter() + sql += quoter.Quote(tableName) + sql += " (" + + if len(table.ColumnsSeq()) > 0 { + var uniqueCols []string + pkList := table.PrimaryKeys + + for _, colName := range table.ColumnsSeq() { + col := table.GetColumn(colName) + s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) + sql += s + sql = strings.TrimSpace(sql) + sql += ", " + + for _, v := range col.Indexes { + if v == schemas.UniqueType { + uniqueCols = append(uniqueCols, colName) + break + } + } + } + + if len(pkList) > 1 { + sql += "PRIMARY KEY ( " + sql += quoter.Join(pkList, ",") + sql += " ), " + } + + sql = sql[:len(sql)-2] + + if len(uniqueCols) > 0 { + sql += fmt.Sprintf(" distributed by (%s)", strings.Join(uniqueCols, ",")) + } + } + sql += ")" + + return []string{sql}, true +} \ No newline at end of file