[Sqlalchemy-tickets] Issue #3644: text() colon-escaping behaviour (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Sebastian B. <iss...@bi...> - 2016-02-03 18:54:24
|
New issue 3644: text() colon-escaping behaviour https://bitbucket.org/zzzeek/sqlalchemy/issues/3644/text-colon-escaping-behaviour Sebastian Bank: Using the postgres double colon shortcut for `CAST(expression AS type)`, e.g.: ```python 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](http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.text) would suggest using `\:`s: ```python 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: ```python 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): ```python engine.execute(sa.text('SELECT * FROM pg_attribute WHERE attrelid = :tab ::regclass'), tab='pg_class') ``` But is this the intended way? |