Hi,
First, some background:
psql (9.2.4)
Type "help" for help.
somedb=# create table a(a varchar(5));
CREATE TABLE
somedb=# insert into a values (E'\\');
INSERT 0 1
somedb=# select * from a where a = '\';
a
---
\
(1 row)
somedb=# select * from a where a like '\';
ERROR: LIKE pattern must not end with escape character
somedb=# select * from a where a like '\\';
a
---
\
(1 row)
somedb=# select * from a where a like E'\\\\';
a
---
\
(1 row)
Here's the relevant part of the documentation:
http://www.postgresql.org/docs/9.2/static/functions-matching.html
Section 9.7.1
So I guess we can safely say that it's a known and documented behaviour
and won't be considered to be a bug by the postgres team.
http://www.postgresql.org/docs/9.1/static/release-9-1.html Section
E.10.2.1 could also be slightly (as it says nothing about LIKE) relevant.
Here's what happens with sqlalchemy:
Python 3.3.2 (default, May 23 2013, 10:38:22)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> sqlalchemy.__version__
'0.8.1'
>>> from sqlalchemy import MetaData, create_engine
>>> e = create_engine("postgres://postgres:@localhost:5432/somedb")
>>> meta = MetaData(bind=e)
>>> meta.reflect()
>>> t=meta.tables['a']
>>> e.execute(t.select(t.c.a.like('\\')))
Traceback (most recent call last):
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 867, in _execute_context
context)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/default.py",
line 326, in do_execute
cursor.execute(statement, parameters)
psycopg2.DataError: LIKE pattern must not end with escape character
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 1614, in execute
return connection.execute(statement, *multiparams, **params)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 662, in execute
params)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 761, in _execute_clauseelement
compiled_sql, distilled_params
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 874, in _execute_context
context)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 1024, in _handle_dbapi_exception
exc_info
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/util/compat.py",
line 155, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/util/compat.py",
line 150, in reraise
raise value.with_traceback(tb)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/base.py",
line 867, in _execute_context
context)
File
"/home/plq/.local/lib64/python3.3/site-packages/SQLAlchemy-0.8.1-py3.3.egg/sqlalchemy/engine/default.py",
line 326, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (DataError) LIKE pattern must not end with
escape character
'SELECT a.a \nFROM a \nWHERE a.a LIKE %(a_1)s' {'a_1': '\\'}
>>>
Anything else I can do to help?
Best,
Burak