The following query takes out the parentheses from a string, i.e. it regex replaces them with nothing. It works as expected when I test it in pgAdimin III (1.12), but when part of a python script using psycopg2, it does not replace the parentheses at all.
SELECT
regexp_replace(location.name, '\\(|\\)', '', 'g') AS host
FROM
location
I’m running python 2.7.1 with psycopg2 2.3.2 and my OS is SLES 11 SP1.
I expect that a postgres query run in pgAdmin would return the same exact results as one ran with psycopg2, or is that an incorrect assumption? I can provide data if needed, but location.name is a string, e.g.
(goat) 172.10.x.x -> /var/log/messages
EDIT: Python code:
cursor.execute("""
SELECT
regexp_replace(location.name, '\\(|\\)', '', 'g') AS host
FROM
location
""")
The parameterized arguments looks like the answer.
Use parametrized arguments:
For example: