diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-08-02 12:27:57 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-08-17 11:50:24 -0400 |
commit | 2e7117ab1b584e678380c70625ad1331cea551d0 (patch) | |
tree | 8defd69fd3202159842511dfc4e9d22e21ad9e7a /lib/sqlalchemy/dialects/postgresql/asyncpg.py | |
parent | a134ec1760df6295d537ff63df7aee83d957bf6a (diff) | |
download | sqlalchemy-2e7117ab1b584e678380c70625ad1331cea551d0.tar.gz |
JSONPATH type can be used in casts in PostgreSQL
Introduced the type :class:`_postgresql.JSONPATH` that can be used
in cast expressions. This is required by some PostgreSQL dialects
when using functions such as ``jsonb_path_exists`` or
``jsonb_path_match`` that accept a ``jsonpath`` as input.
Fixes: #8216
Change-Id: I3e7337eab91680cab1604e1f3058854a0a19c5be
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/asyncpg.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/asyncpg.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index 38f8fddee..6888959f0 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -122,7 +122,6 @@ client using this setting passed to :func:`_asyncio.create_async_engine`:: from __future__ import annotations import collections -import collections.abc as collections_abc import decimal import json as _py_json import re @@ -231,9 +230,15 @@ class AsyncpgJSONStrIndexType(sqltypes.JSON.JSONStrIndexType): class AsyncpgJSONPathType(json.JSONPathType): def bind_processor(self, dialect): def process(value): - assert isinstance(value, collections_abc.Sequence) - tokens = [str(elem) for elem in value] - return tokens + if isinstance(value, str): + # If it's already a string assume that it's in json path + # format. This allows using cast with json paths literals + return value + elif value: + tokens = [str(elem) for elem in value] + return tokens + else: + return [] return process |