MCPcopy Create free account
hub / github.com/PostHog/duckgres / ParseQualifiedIdentifier

Function ParseQualifiedIdentifier

server/sqlcore/identifier.go:7–45  ·  view source on GitHub ↗

ParseQualifiedIdentifier splits a one-or-more-part SQL identifier, preserving quoted identifier case and lowercasing unquoted identifiers.

(ref string)

Source from the content-addressed store, hash-verified

5// ParseQualifiedIdentifier splits a one-or-more-part SQL identifier, preserving
6// quoted identifier case and lowercasing unquoted identifiers.
7func ParseQualifiedIdentifier(ref string) ([]string, bool) {
8 ref = strings.TrimSpace(ref)
9 if ref == "" {
10 return nil, false
11 }
12
13 var parts []string
14 inQuotes := false
15 partStart := 0
16 for i := 0; i < len(ref); i++ {
17 ch := ref[i]
18 if ch == '"' {
19 if inQuotes && i+1 < len(ref) && ref[i+1] == '"' {
20 i++
21 continue
22 }
23 inQuotes = !inQuotes
24 continue
25 }
26 if ch == '.' && !inQuotes {
27 part, ok := parseIdentifierPart(ref[partStart:i])
28 if !ok {
29 return nil, false
30 }
31 parts = append(parts, part)
32 partStart = i + 1
33 }
34 }
35 if inQuotes {
36 return nil, false
37 }
38
39 part, ok := parseIdentifierPart(ref[partStart:])
40 if !ok {
41 return nil, false
42 }
43 parts = append(parts, part)
44 return parts, true
45}
46
47// CatalogFromSearchPath returns the catalog from the first search_path entry,
48// or "" when the first entry is an unqualified schema.

Callers 2

CatalogFromSearchPathFunction · 0.85

Calls 1

parseIdentifierPartFunction · 0.85

Tested by 1