Skip to content

Commit 320e5b1

Browse files
committed
string: Fix split_ident() to handle idents with '_' and/or digits
string.split_ident() used ad-hoc logic to determine if an identifier must be quoted, effectively prohibiting identifiers with underscores or digits, which are both considered to be safe by PostgreSQL.
1 parent 99b0057 commit 320e5b1

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

postgresql/string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def split_ident(text, sep = ',', quote = '"', maxsplit = -1):
197197
)
198198
else:
199199
nr.append(x[1:-1].replace('""', '"'))
200-
elif not x.isalpha():
200+
elif needs_quoting(x):
201201
raise ValueError(
202-
"non-alpha characters in unquoted identifier", x
202+
"non-ident characters in unquoted identifier", x
203203
)
204204
else:
205205
# postgres implies a lower, so to stay consistent

postgresql/test/test_string.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
('"schema.base"', ['schema.base'], '"schema.base"'),
2424
('schEmÅ."base"', ['schemå', 'base'], 'schemå.base'),
2525
('scheMa."base"', ['schema', 'base'], 'schema.base'),
26+
('sche_ma.base', ['sche_ma', 'base'], 'sche_ma.base'),
27+
('_schema.base', ['_schema', 'base'], '_schema.base'),
28+
('a000.b111', ['a000', 'b111'], 'a000.b111'),
2629
('" schema"."base"', [' schema', 'base'], '" schema".base'),
2730
('" schema"."ba se"', [' schema', 'ba se'], '" schema"."ba se"'),
2831
('" ""schema"."ba""se"', [' "schema', 'ba"se'], '" ""schema"."ba""se"'),

0 commit comments

Comments
 (0)