MCPcopy Index your code
hub / github.com/dbcli/pgcli / parse_partial_identifier

Function parse_partial_identifier

pgcli/packages/parseutils/utils.py:121–141  ·  view source on GitHub ↗

Attempt to parse a (partially typed) word as an identifier word may include a schema qualification, like `schema_name.partial_name` or `schema_name.` There may also be unclosed quotation marks, like `"schema`, or `schema."partial_name` :param word: string representing a (partially

(word)

Source from the content-addressed store, hash-verified

119
120
121def parse_partial_identifier(word):
122 """Attempt to parse a (partially typed) word as an identifier
123
124 word may include a schema qualification, like `schema_name.partial_name`
125 or `schema_name.` There may also be unclosed quotation marks, like
126 `"schema`, or `schema."partial_name`
127
128 :param word: string representing a (partially complete) identifier
129 :return: sqlparse.sql.Identifier, or None
130 """
131
132 p = sqlparse.parse(word)[0]
133 n_tok = len(p.tokens)
134 if n_tok == 1 and isinstance(p.tokens[0], Identifier):
135 return p.tokens[0]
136 elif p.token_next_by(m=(Error, '"'))[1]:
137 # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar'
138 # Close the double quote, then reparse
139 return parse_partial_identifier(word + '"')
140 else:
141 return None

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected