Closed
Description
Migrated issue, originally created by Sebastian Bank (@xflr6)
Using the postgres double colon shortcut for CAST(expression AS type)
, e.g.:
import sqlalchemy as sa
engine = sa.create_engine('postgresql://postgres@/')
engine.execute('SELECT * FROM pg_attribute WHERE attrelid = %(tab)s::regclass', tab='pg_class')
Trying this with text
, I think the docs would suggest using \:
s:
engine.execute(sa.text('SELECT * FROM pg_attribute WHERE attrelid = :tab\:\:regclass'), tab='pg_class')
But this raises ProgrammingError: (psycopg2.ProgrammingError)
(rendered as SELECT * FROM pg_attribute WHERE attrelid = %(tab)s\::regclass
).
As expected, this also raises:
engine.execute(sa.text('SELECT * FROM pg_attribute WHERE attrelid = :tab::regclass'), tab='pg_class')
(rendered as SELECT * FROM pg_attribute WHERE attrelid = :tab::regclass
)
This finally works (extra space):
engine.execute(sa.text('SELECT * FROM pg_attribute WHERE attrelid = :tab ::regclass'), tab='pg_class')
But is this the intended way?
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Feb 3, 2016
Michael Bayer (@zzzeek) wrote:
it's a bug. here's a patch:
sqlalchemy-bot commentedon Feb 3, 2016
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Feb 9, 2016
Michael Bayer (@zzzeek) wrote:
.expression.text
construct where a double-colonexpression would not escape properly, e.g.
some\:\:expr
, as is mostcommonly required when rendering Postgresql-style CAST expressions.
fixes text() colon-escaping behaviour #3644
→ 29dcaa2
sqlalchemy-bot commentedon Feb 9, 2016
Michael Bayer (@zzzeek) wrote:
.expression.text
construct where a double-colonexpression would not escape properly, e.g.
some\:\:expr
, as is mostcommonly required when rendering Postgresql-style CAST expressions.
fixes text() colon-escaping behaviour #3644
(cherry picked from commit 29dcaa2)
→ 498b072
sqlalchemy-bot commentedon Feb 9, 2016
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Feb 9, 2016
Michael Bayer (@zzzeek) wrote:
wow, what the crap, the compiler.py isn't in the commit
sqlalchemy-bot commentedon Feb 9, 2016
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Feb 9, 2016
Michael Bayer (@zzzeek) wrote:
OK, it got inadvertently committed in c1316a2 for master, is not in 1.0
sqlalchemy-bot commentedon Feb 9, 2016
Michael Bayer (@zzzeek) wrote:
present in the commit for master, having been inadvertently committed
on February 3. Source of this line is c1316a2.
→ 9a156c5
sqlalchemy-bot commentedon Feb 9, 2016
Changes by Michael Bayer (@zzzeek):