MCPcopy
hub / github.com/sqlc-dev/sqlc / quoteIdent

Method quoteIdent

internal/compiler/expand.go:50–70  ·  view source on GitHub ↗
(ident string)

Source from the content-addressed store, hash-verified

48var validPostgresIdent = regexp.MustCompile(`^[a-z_][a-z0-9_$]*$`)
49
50func (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
72func (c *Compiler) quote(x string) string {
73 switch c.conf.Engine {

Callers 1

expandStmtMethod · 0.95

Calls 2

quoteMethod · 0.95
IsReservedKeywordMethod · 0.65

Tested by

no test coverage detected