Skip to content

Commit

Permalink
Fix: postgres nested jsonb closes #1903
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jul 10, 2023
1 parent 273daf9 commit 6ccb595
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3074,7 +3074,13 @@ def _parse_types(
if self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET):
this = exp.DataType(
this=exp.DataType.Type.ARRAY,
expressions=[exp.DataType.build(type_token.value, expressions=expressions)],
expressions=[
exp.DataType(
this=exp.DataType.Type[type_token.value],
expressions=expressions,
nested=nested,
)
],
nested=True,
)

Expand Down Expand Up @@ -3135,7 +3141,7 @@ def _parse_types(
return value

return exp.DataType(
this=exp.DataType.Type[type_token.value.upper()],
this=exp.DataType.Type[type_token.value],
expressions=expressions,
nested=nested,
values=values,
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 @@ -9,6 +9,7 @@ class TestPostgres(Validator):
dialect = "postgres"

def test_ddl(self):
self.validate_identity("CREATE TABLE test (elems JSONB[])")
self.validate_identity("CREATE TABLE public.y (x TSTZRANGE NOT NULL)")
self.validate_identity("CREATE TABLE test (foo HSTORE)")
self.validate_identity("CREATE TABLE test (foo JSONB)")
Expand Down

0 comments on commit 6ccb595

Please sign in to comment.