Skip to content

Commit

Permalink
Feat(postgres): add MONEY type, revert in Spark to use DECIMAL(15, 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Jul 6, 2023
1 parent 2ab8887 commit fafccf5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class Tokenizer(tokens.Tokenizer):
"DO": TokenType.COMMAND,
"HSTORE": TokenType.HSTORE,
"JSONB": TokenType.JSONB,
"MONEY": TokenType.MONEY,
"REFRESH": TokenType.COMMAND,
"REINDEX": TokenType.COMMAND,
"RESET": TokenType.COMMAND,
Expand Down
3 changes: 1 addition & 2 deletions sqlglot/dialects/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Parser(Spark2.Parser):
class Generator(Spark2.Generator):
TYPE_MAPPING = {
**Spark2.Generator.TYPE_MAPPING,
# https://stackoverflow.com/a/224866
exp.DataType.Type.MONEY: "DECIMAL(19, 4)",
exp.DataType.Type.MONEY: "DECIMAL(15, 4)",
exp.DataType.Type.SMALLMONEY: "DECIMAL(6, 4)",
exp.DataType.Type.UNIQUEIDENTIFIER: "STRING",
}
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_array_offset(self, logger):
)

def test_postgres(self):
self.validate_identity("CAST(x AS MONEY)")
self.validate_identity("CAST(x AS INT4RANGE)")
self.validate_identity("CAST(x AS INT4MULTIRANGE)")
self.validate_identity("CAST(x AS INT8RANGE)")
Expand Down
2 changes: 1 addition & 1 deletion tests/dialects/test_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_types_decimals(self):
self.validate_all(
"CAST(x as MONEY)",
write={
"spark": "CAST(x AS DECIMAL(19, 4))",
"spark": "CAST(x AS DECIMAL(15, 4))",
"tsql": "CAST(x AS MONEY)",
},
)
Expand Down

1 comment on commit fafccf5

@georgesittas
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the DECIMAL(19, 4) change because Spark seems to actually support up to 15 digits to the left of the fix point.

Please sign in to comment.