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
4 changes: 4 additions & 0 deletions sqlglot/expressions/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class ArrayContainsAll(Expression, Binary, Func):
_sql_names = ["ARRAY_CONTAINS_ALL", "ARRAY_HAS_ALL"]


class ArrayContainedBy(Expression, Binary, Func):
pass


class ArrayExcept(Expression, Func):
arg_types = {"this": True, "expression": True, "is_multiset": False}

Expand Down
1 change: 1 addition & 0 deletions sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Generator:
),
exp.AnalyzeColumns: lambda self, e: self.sql(e, "this"),
exp.AnalyzeWith: lambda self, e: self.expressions(e, prefix="WITH ", sep=" "),
exp.ArrayContainedBy: lambda self, e: self.binary(e, "<@"),
exp.ArrayContainsAll: lambda self, e: self.binary(e, "@>"),
exp.ArrayOverlaps: lambda self, e: self.binary(e, "&&"),
exp.AssumeColumnConstraint: lambda self, e: f"ASSUME ({self.sql(e, 'this')})",
Expand Down
4 changes: 4 additions & 0 deletions sqlglot/generators/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ def arraycontainsall_sql(self, expression: exp.ArrayContainsAll) -> str:
self.unsupported("Array operations are not supported by MySQL")
return self.function_fallback_sql(expression)

def arraycontainedby_sql(self, expression: exp.ArrayContainedBy) -> str:
self.unsupported("Array operations are not supported by MySQL")
return self.function_fallback_sql(expression)

def dpipe_sql(self, expression: exp.DPipe) -> str:
return self.func("CONCAT", *expression.flatten())

Expand Down
2 changes: 1 addition & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ class Parser:
TokenType.IRLIKE: binary_range_parser(exp.RegexpILike),
TokenType.IS: lambda self, this: self._parse_is(this),
TokenType.LIKE: binary_range_parser(exp.Like),
TokenType.LT_AT: binary_range_parser(exp.ArrayContainsAll, reverse_args=True),
TokenType.LT_AT: binary_range_parser(exp.ArrayContainedBy),
TokenType.OVERLAPS: binary_range_parser(exp.Overlaps),
TokenType.RLIKE: binary_range_parser(exp.RegexpLike),
TokenType.SIMILAR_TO: binary_range_parser(exp.SimilarTo),
Expand Down
4 changes: 2 additions & 2 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,8 +1350,8 @@ def test_duckdb(self):
self.validate_identity("a ** b", "POWER(a, b)")
self.validate_identity("a ~~~ b", "a GLOB b")
self.validate_identity("a ~~ b", "a LIKE b")
self.validate_identity("a @> b")
self.validate_identity("a <@ b", "b @> a")
self.validate_identity("a @> b").assert_is(exp.ArrayContainsAll)
self.validate_identity("a <@ b").assert_is(exp.ArrayContainedBy)
self.validate_identity("a && b").assert_is(exp.ArrayOverlaps)
self.validate_identity("a ^@ b", "STARTS_WITH(a, b)")
self.validate_identity(
Expand Down
5 changes: 2 additions & 3 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ def test_postgres(self):
"SELECT SUBSTRING('Thomas' FOR 3 FROM 2)",
"SELECT SUBSTRING('Thomas' FROM 2 FOR 3)",
)
self.validate_identity(
"SELECT ARRAY[1, 2, 3] <@ ARRAY[1, 2]",
"SELECT ARRAY[1, 2] @> ARRAY[1, 2, 3]",
self.validate_identity("SELECT ARRAY[1, 2, 3] <@ ARRAY[1, 2]").expressions[0].assert_is(
exp.ArrayContainedBy
)
self.validate_identity(
"SELECT DATE_PART('isodow'::varchar(6), current_date)",
Expand Down
Loading