Skip to content

Commit

Permalink
fix None formatting to "NULL"
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Jan 16, 2021
1 parent 79e00b2 commit cc4b8a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Empty file removed mo_parsing/regex.py
Empty file.
2 changes: 2 additions & 0 deletions moz_sql_parser/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def dispatch(self, json):
return self.op(json)
if isinstance(json, string_types):
return escape(json, self.ansi_quotes, self.should_quote)
if json == None:
return "NULL"

return text(json)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_format_and_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,3 +1855,11 @@ def test_issue122_deep_column_name(self):
"from": {"value": {"generate_series": [1, 2]}, "name": {"S": ["a", "b"]}},
}
self.verify_formatting(expected_sql, expected_json)

def test_issue152(self):
expected_sql = "SELECT a, CASE WHEN some_columns = 'Bob' THEN 'helloworld' ELSE NULL END AS some_columns FROM mytable"
expected_json = {'select': [{'value': 'a'}, {'value': {
'case': [{'when': {'eq': ['some_columns', {'literal': 'Bob'}]}, 'then': {'literal': 'helloworld'}}, None]},
'name': 'some_columns'}], 'from': 'mytable'}

self.verify_formatting(expected_sql, expected_json)

0 comments on commit cc4b8a6

Please sign in to comment.