Skip to content

Commit

Permalink
Fix(Postgres): Set INDEX_OFFSET to 1 (#1782)
Browse files Browse the repository at this point in the history
* Add failing test for array offset

* Add INDEX_OFFSET = 1 for Postgres
  • Loading branch information
vegarsti authored Jun 15, 2023
1 parent 3b95a46 commit 4a1068b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def _to_timestamp(args: t.List) -> exp.Expression:


class Postgres(Dialect):
INDEX_OFFSET = 1
NULL_ORDERING = "nulls_are_large"
TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'"
TIME_MAPPING = {
Expand Down
10 changes: 10 additions & 0 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def test_unnest(self):
},
)

def test_array_offset(self):
self.validate_all(
"SELECT col[1]",
write={
"hive": "SELECT col[0]",
"postgres": "SELECT col[1]",
"presto": "SELECT col[1]",
},
)

def test_postgres(self):
self.validate_identity("CAST(x AS INT4RANGE)")
self.validate_identity("CAST(x AS INT4MULTIRANGE)")
Expand Down

0 comments on commit 4a1068b

Please sign in to comment.