File tree Expand file tree Collapse file tree 6 files changed +21
-1
lines changed
Expand file tree Collapse file tree 6 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ Bug Fixes
2727* Fix issue with strip_comments causing a syntax error (issue425, by fredyw).
2828* Fix formatting on INSERT which caused staircase effect on values (issue329,
2929 by fredyw).
30+ * Avoid formatting of psql commands (issue469).
3031
3132Internal Changes
3233
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ def is_keyword(value):
4343 (r'%(\(\w+\))?s' , tokens .Name .Placeholder ),
4444 (r'(?<!\w)[$:?]\w+' , tokens .Name .Placeholder ),
4545
46+ (r'\\\w+' , tokens .Command ),
47+
4648 # FIXME(andi): VALUES shouldn't be listed here
4749 # see https://github.com/andialbrecht/sqlparse/pull/64
4850 # IN is special, it may be followed by a parenthesis, but
Original file line number Diff line number Diff line change @@ -625,3 +625,7 @@ class Operation(TokenList):
625625
626626class Values (TokenList ):
627627 """Grouping of values"""
628+
629+
630+ class Command (TokenList ):
631+ """Grouping of CLI commands."""
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ def __repr__(self):
5555
5656# Generic types for non-source code
5757Generic = Token .Generic
58+ Command = Generic .Command
5859
5960# String and some others are not direct children of Token.
6061# alias them:
@@ -66,4 +67,3 @@ def __repr__(self):
6667DML = Keyword .DML
6768DDL = Keyword .DDL
6869CTE = Keyword .CTE
69- Command = Keyword .Command
Original file line number Diff line number Diff line change @@ -366,3 +366,10 @@ def test_issue322_concurrently_is_keyword():
366366def test_issue359_index_error_assignments (s ):
367367 sqlparse .parse (s )
368368 sqlparse .format (s , strip_comments = True )
369+
370+
371+ def test_issue469_copy_as_psql_command ():
372+ formatted = sqlparse .format (
373+ '\\ copy select * from foo' ,
374+ keyword_case = 'upper' , identifier_case = 'capitalize' )
375+ assert formatted == '\\ copy SELECT * FROM Foo'
Original file line number Diff line number Diff line change @@ -195,3 +195,9 @@ def test_parse_order_by():
195195 p = sqlparse .parse ('ORDER BY' )[0 ]
196196 assert len (p .tokens ) == 1
197197 assert p .tokens [0 ].ttype is T .Keyword
198+
199+
200+ def test_cli_commands ():
201+ p = sqlparse .parse ('\\ copy' )[0 ]
202+ assert len (p .tokens ) == 1
203+ assert p .tokens [0 ].ttype == T .Command
You can’t perform that action at this time.
0 commit comments