File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,16 +14,6 @@ def filter_lines(text):
1414 return '' .join (lines )
1515
1616
17- def sort_create_table_columns (match ):
18- """Sort column lines in a CREATE TABLE block alphabetically"""
19- lines = [
20- line .strip ().rstrip (',' )
21- for line in match .group (1 ).split ('\n ' )
22- if line .strip ()
23- ]
24- return '(\n ' + ',\n ' .join (sorted (lines )) + '\n )'
25-
26-
2717def sort_copy_columns (text ):
2818 """Sort columns in COPY blocks and reorder the data rows accordingly"""
2919 result = []
@@ -49,6 +39,16 @@ def sort_copy_columns(text):
4939 return '\n ' .join (result )
5040
5141
42+ def sort_create_table_columns (match ):
43+ """Sort column lines in a CREATE TABLE block alphabetically"""
44+ lines = [
45+ line .strip ().rstrip (',' )
46+ for line in match .group (1 ).split ('\n ' )
47+ if line .strip ()
48+ ]
49+ return '(\n ' + ',\n ' .join (sorted (lines )) + '\n )'
50+
51+
5252text = filter_lines (sys .stdin .read ())
5353text = re .sub (r'\(((?:\n [^\n]+)+)\n\)' , sort_create_table_columns , text )
5454text = sort_copy_columns (text )
You can’t perform that action at this time.
0 commit comments