diff options
author | Guilherme Martins Crocetti <24530683+gmcrocetti@users.noreply.github.com> | 2023-01-04 10:27:26 -0500 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2023-01-05 21:19:07 +0100 |
commit | 6b0c3dd5fd0c0225636ce759bc4433c91c5efb83 (patch) | |
tree | b377c025b169ad21e9ab48d6e8281f63d8299ed0 /test/dialect/postgresql | |
parent | 1e7d45283645c57556b7aecbc3a370a92de409ce (diff) | |
download | sqlalchemy-6b0c3dd5fd0c0225636ce759bc4433c91c5efb83.tar.gz |
Implement missing `#-`, `@?` and `@@` Postgres' JSONB operators.
Fixes #7147.
Closes: #9038
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9038
Pull-request-sha: 8647aaf2d9f48c55c152673828deb8ed54966a11
Change-Id: Id2f611ed8080a2837c70d2ea4b41abc46d2bb026
Diffstat (limited to 'test/dialect/postgresql')
-rw-r--r-- | test/dialect/postgresql/test_types.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index e9d5e561f..22993ae7b 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -5683,6 +5683,24 @@ class JSONBTest(JSONTest): lambda self: self.jsoncol.contained_by({"foo": "1", "bar": None}), "test_table.test_column <@ %(test_column_1)s", ), + ( + lambda self: self.jsoncol.delete_path(["a", "b"]), + "test_table.test_column #- CAST(ARRAY[%(param_1)s, " + "%(param_2)s] AS TEXT[])", + ), + ( + lambda self: self.jsoncol.delete_path(array(["a", "b"])), + "test_table.test_column #- CAST(ARRAY[%(param_1)s, " + "%(param_2)s] AS TEXT[])", + ), + ( + lambda self: self.jsoncol.path_exists("$.k1"), + "test_table.test_column @? %(test_column_1)s", + ), + ( + lambda self: self.jsoncol.path_match("$.k1[0] > 2"), + "test_table.test_column @@ %(test_column_1)s", + ), ) def test_where(self, whereclause_fn, expected): super().test_where(whereclause_fn, expected) @@ -5712,6 +5730,19 @@ class JSONBRoundTripTest(JSONRoundTripTest): go("$.k1.k2", 0) go("$.k1.r6v1", 1) + @testing.combinations( + ["k1", "r6v1", "subr", 1], + array(["k1", "r6v1", "subr", 1]), + argnames="path", + ) + def test_delete_path(self, connection, path): + self._fixture_data(connection) + q = select(self.data_table.c.data.delete_path(path)).where( + self.data_table.c.name == "r6" + ) + res = connection.scalar(q) + eq_(res, {"k1": {"r6v1": {"subr": [1, 3]}}}) + class JSONBSuiteTest(suite.JSONTest): __requires__ = ("postgresql_jsonb",) |