Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5313,6 +5313,12 @@ class Sub(Binary):
pass


# https://www.postgresql.org/docs/current/functions-range.html
# Represents range adjacency operator: -|-
class Adjacent(Binary):
pass


# Unary Expressions
# (NOT a)
class Unary(Condition):
Expand Down
1 change: 1 addition & 0 deletions sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Generator(metaclass=_Generator):

TRANSFORMS: t.Dict[t.Type[exp.Expression], t.Callable[..., str]] = {
**JSON_PATH_PART_TRANSFORMS,
exp.Adjacent: lambda self, e: self.binary(e, "-|-"),
exp.AllowedValuesProperty: lambda self,
e: f"ALLOWED_VALUES {self.expressions(e, flat=True)}",
exp.AnalyzeColumns: lambda self, e: self.sql(e, "this"),
Expand Down
1 change: 1 addition & 0 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ class Parser(metaclass=_Parser):
TokenType.QMARK_AMP: binary_range_parser(exp.JSONBContainsAllTopKeys),
TokenType.QMARK_PIPE: binary_range_parser(exp.JSONBContainsAnyTopKeys),
TokenType.HASH_DASH: binary_range_parser(exp.JSONBDeleteAtPath),
TokenType.ADJACENT: binary_range_parser(exp.Adjacent),
TokenType.OPERATOR: lambda self, this: self._parse_operator(this),
TokenType.AMP_LT: binary_range_parser(exp.ExtendsLeft),
TokenType.AMP_GT: binary_range_parser(exp.ExtendsRight),
Expand Down
2 changes: 2 additions & 0 deletions sqlglot/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TokenType(AutoName):
DAMP = auto()
AMP_LT = auto()
AMP_GT = auto()
ADJACENT = auto()
XOR = auto()
DSTAR = auto()
QMARK_AMP = auto()
Expand Down Expand Up @@ -739,6 +740,7 @@ class Tokenizer(metaclass=_Tokenizer):
"~~": TokenType.LIKE,
"~~*": TokenType.ILIKE,
"~*": TokenType.IRLIKE,
"-|-": TokenType.ADJACENT,
"ALL": TokenType.ALL,
"AND": TokenType.AND,
"ANTI": TokenType.ANTI,
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 @@ -1010,6 +1010,7 @@ def test_postgres(self):
"postgres": "CREATE TABLE table1 (a INT, b INT, PRIMARY KEY (a))",
},
)
self.validate_identity("SELECT NUMRANGE(1.1, 2.2) -|- NUMRANGE(2.2, 3.3)")

def test_ddl(self):
# Checks that user-defined types are parsed into DataType instead of Identifier
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,5 @@ SELECT CURRENT_DATABASE()
SELECT CURRENT_SCHEMAS(arg_bool)
SELECT UNIFORM(1, 10, 5)
SELECT UNIFORM(1, 10)
SELECT CURRENT_TIMEZONE()
SELECT CURRENT_TIMEZONE()
SELECT NUMRANGE(1.1, 2.2) -|- NUMRANGE(2.2, 3.3)