From e86b5375a57abd29962d836a72d5e93ba697ffc3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 6 Mar 2020 15:28:29 +0800 Subject: [PATCH] names with upper charactor on postgres will need quotes --- dialects/postgres.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index a3d95026..0049cee6 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -788,6 +788,18 @@ func (db *postgres) Init(d *core.DB, uri *URI) error { return nil } +func (db *postgres) needQuote(name string) bool { + if db.IsReserved(name) { + return true + } + for _, c := range name { + if c >= 'A' && c <= 'Z' { + return true + } + } + return false +} + func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) { switch quotePolicy { case QuotePolicyNone: @@ -796,7 +808,7 @@ func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) { db.quoter = q case QuotePolicyReserved: var q = postgresQuoter - q.IsReserved = db.IsReserved + q.IsReserved = db.needQuote db.quoter = q case QuotePolicyAlways: fallthrough