mike bayer <mike...@zzzcomputing.com> writes: > However, we can improve upon the situation by adding a CAST, which seems to > send psycopg2 a little more information: > > row = s.query( > cast( > func.array_agg(tuple_(A.x, A.y)), ARRAY(Unicode) > ) > ).scalar() > print row
For one new application I'm writing I chose the "new" asyncpg[1] driver. The major problem I hit was related to this CASTing need ([2] and [3]): due to the way asyncpg talks to the database, in some cases it cannot guess the right format because on the PG side things may be ambiguous (e.g. when an operator is overloaded and works on different types of data, like the @> operator I used in [3]). To solve that I wrote a very simple custom PGDialect+PGCompiler duo to handle a new "paramstyle", basically translating the following SA construct:: oneyearago = date.today() - timedelta(days=365) q = sa.select([users.c.id]) \ .where(users.c.name == 'test') \ .where(users.c.validity.contains(oneyearago)) into this SQL statement:: SELECT auth.users.id FROM auth.users WHERE auth.users.name = $1::VARCHAR(64) AND (auth.users.validity @> $2::DATE) Since it eventually boils down to overriding a single "private" method (_apply_numbered_params), I wonder if it would be a welcome addition to standard SA, maybe allowing to set "paramstyle" to an user's arbitrary callable. What do you think? Thank you, ciao, lele. [1] https://github.com/MagicStack/asyncpg [2] https://github.com/CanopyTax/asyncpgsa/issues/12 [3] https://github.com/MagicStack/asyncpg/issues/32 -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.