'SQLAlchemy how to escape a bind parameter inside of text()?
How can I escape a : inside of a string passed to text() to prevent SQLAlchemy from treating it like a bindparameter?
conn.execute(text("select 'My favorite emoticon is :p' from dual")).fetchone()
Will result in:
sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'p'
(Background on this error at: http://sqlalche.me/e/14/cd3x)
'
It's a bit confusing because from the context of selecting a string from the database select 'foo :bar baz' a bindparameter doesn't make much sense here.
It looks like I can use a \ to escape this, but it says it is deprecated:
>>> conn.execute(text("select 'My favorite emoticon is \:p' from dual")).fetchone()
<stdin>:1: DeprecationWarning: invalid escape sequence \:
('My favorite emoticon is :p',)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
