From b0cf9559f4456890eaf110fda08027a6a54733ce Mon Sep 17 00:00:00 2001 From: black Date: Mon, 20 Feb 2023 11:07:59 +0800 Subject: [PATCH] distinguish between schema.Time and tag time fix https://github.com/go-gorm/gorm/issues/6033 --- postgres.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/postgres.go b/postgres.go index 5d73d27..9057269 100644 --- a/postgres.go +++ b/postgres.go @@ -189,10 +189,17 @@ func (dialector Dialector) DataTypeOf(field *schema.Field) string { } return "text" case schema.Time: + var timeType string + // Distinguish between schema.Time and tag time + if val, ok := field.TagSettings["TYPE"]; ok { + timeType = val + } else { + timeType = "timestamptz" + } if field.Precision > 0 { - return fmt.Sprintf("timestamptz(%d)", field.Precision) + return fmt.Sprintf("%s(%d)", timeType, field.Precision) } - return "timestamptz" + return timeType case schema.Bytes: return "bytea" default: