Fixed SQL handling for "insertmanyvalues" when using the
:class:`.postgresql.BIT` datatype with the asyncpg backend. The
:class:`.postgresql.BIT` on asyncpg apparently requires the use of an
asyncpg-specific `BitString` type which is currently exposed when using
this DBAPI, making it incompatible with other PostgreSQL DBAPIs that all
work with plain bitstrings here. A future fix in version 2.1 will
normalize this datatype across all PG backends. Pull request courtesy
Sören Oldag.
Fixes: #10532
Closes: #10533
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10533
Pull-request-sha:
528607d5b5b67c1b9c2edb39176b7e005db371f6
Change-Id: I879f2fc24b5650467b85f170c0def15834f75456
--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 10532
+
+ Fixed SQL handling for "insertmanyvalues" when using the
+ :class:`.postgresql.BIT` datatype with the asyncpg backend. The
+ :class:`.postgresql.BIT` on asyncpg apparently requires the use of an
+ asyncpg-specific `BitString` type which is currently exposed when using
+ this DBAPI, making it incompatible with other PostgreSQL DBAPIs that all
+ work with plain bitstrings here. A future fix in version 2.1 will
+ normalize this datatype across all PG backends. Pull request courtesy
+ Sören Oldag.
+
from .base import PGIdentifierPreparer
from .base import REGCLASS
from .base import REGCONFIG
+from .types import BIT
from .types import BYTEA
from .types import CITEXT
from ... import exc
render_bind_cast = True
+class AsyncpgBit(BIT):
+ render_bind_cast = True
+
+
class AsyncpgByteA(BYTEA):
render_bind_cast = True
{
sqltypes.String: AsyncpgString,
sqltypes.ARRAY: AsyncpgARRAY,
+ BIT: AsyncpgBit,
CITEXT: CITEXT,
REGCONFIG: AsyncpgREGCONFIG,
sqltypes.Time: AsyncpgTime,
from sqlalchemy.dialects.postgresql import array_agg
from sqlalchemy.dialects.postgresql import asyncpg
from sqlalchemy.dialects.postgresql import base
+from sqlalchemy.dialects.postgresql import BIT
from sqlalchemy.dialects.postgresql import BYTEA
from sqlalchemy.dialects.postgresql import CITEXT
from sqlalchemy.dialects.postgresql import DATEMULTIRANGE
__backend__ = True
@testing.combinations(
- ("PG BYTEA", BYTEA(), b"7\xe7\x9f"),
+ ("BYTEA", BYTEA(), b"7\xe7\x9f"),
+ ("BIT", BIT(3), "011"),
argnames="type_,value",
id_="iaa",
)
t.create(connection)
+ if type_._type_affinity is BIT and testing.against("+asyncpg"):
+ import asyncpg
+
+ value = asyncpg.BitString(value)
+
result = connection.execute(
t.insert().returning(
t.c.id,