(ident string)
| 48 | var validPostgresIdent = regexp.MustCompile(`^[a-z_][a-z0-9_$]*$`) |
| 49 | |
| 50 | func (c *Compiler) quoteIdent(ident string) string { |
| 51 | if c.parser.IsReservedKeyword(ident) { |
| 52 | return c.quote(ident) |
| 53 | } |
| 54 | // SQL identifiers and key words must begin with a letter (a-z, but also |
| 55 | // letters with diacritical marks and non-Latin letters) or an underscore |
| 56 | // (_). Subsequent characters in an identifier or key word can be letters, |
| 57 | // underscores, digits (0-9), or dollar signs ($). |
| 58 | // |
| 59 | // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS |
| 60 | if c.conf.Engine == config.EnginePostgreSQL { |
| 61 | // camelCase means the column is also camelCase |
| 62 | if strings.ToLower(ident) != ident { |
| 63 | return c.quote(ident) |
| 64 | } |
| 65 | if !validPostgresIdent.MatchString(strings.ToLower(ident)) { |
| 66 | return c.quote(ident) |
| 67 | } |
| 68 | } |
| 69 | return ident |
| 70 | } |
| 71 | |
| 72 | func (c *Compiler) quote(x string) string { |
| 73 | switch c.conf.Engine { |
no test coverage detected