From 2f95c750c348309ae09cfafa87166ea6f9a62cc3 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 10 Mar 2020 06:11:42 +0000 Subject: [PATCH] jerry:add postgre data_type array (#1589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix err,add postgres column ARRAY fix err,add postgres column ARRAY Co-authored-by: Jerry <85411418@qq.com> Reviewed-on: https://gitea.com/xorm/xorm/pulls/1589 Reviewed-by: Lunny Xiao --- dialects/postgres.go | 2 ++ schemas/type.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/dialects/postgres.go b/dialects/postgres.go index 8412ad40..2111f195 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -1099,6 +1099,8 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att col.SQLType = schemas.SQLType{Name: schemas.Binary, DefaultLength: 0, DefaultLength2: 0} case "oid": col.SQLType = schemas.SQLType{Name: schemas.BigInt, DefaultLength: 0, DefaultLength2: 0} + case "array": + col.SQLType = schemas.SQLType{Name: schemas.Array, DefaultLength: 0, DefaultLength2: 0} default: startIdx := strings.Index(strings.ToLower(dataType), "string(") if startIdx != -1 && strings.HasSuffix(dataType, ")") { diff --git a/schemas/type.go b/schemas/type.go index 39f1bf4e..89459a4d 100644 --- a/schemas/type.go +++ b/schemas/type.go @@ -34,6 +34,7 @@ const ( BLOB_TYPE TIME_TYPE NUMERIC_TYPE + ARRAY_TYPE ) func (s *SQLType) IsType(st int) bool { @@ -59,6 +60,10 @@ func (s *SQLType) IsNumeric() bool { return s.IsType(NUMERIC_TYPE) } +func (s *SQLType) IsArray() bool { + return s.IsType(ARRAY_TYPE) +} + func (s *SQLType) IsJson() bool { return s.Name == Json || s.Name == Jsonb } @@ -123,6 +128,8 @@ var ( Json = "JSON" Jsonb = "JSONB" + Array = "ARRAY" + SqlTypes = map[string]int{ Bit: NUMERIC_TYPE, TinyInt: NUMERIC_TYPE, @@ -180,6 +187,8 @@ var ( Serial: NUMERIC_TYPE, BigSerial: NUMERIC_TYPE, + + Array: ARRAY_TYPE, } intTypes = sort.StringSlice{"*int", "*int16", "*int32", "*int8"}