sql2csv: query does not escape %
Created by: edwardros
Python Version: 2.7.3 CSV Kit Version: 0.9.1 Database: Postgres 8.3.11
Input:
sql2csv --db 'postgres://user@host/db' --query "SELECT datname from pg_database where datname like '%'" -v
Expected output:
<List of all database names>
Actual output:
Traceback (most recent call last):
File "user/bin/sql2csv", line 9, in <module>
load_entry_point('csvkit==0.9.1', 'console_scripts', 'sql2csv')()
File "user/lib/python2.7/site-packages/csvkit/utilities/sql2csv.py", line 65, in launch_new_instance
utility.main()
File "user/lib/python2.7/site-packages/csvkit/utilities/sql2csv.py", line 52, in main
rows = conn.execute(query)
File "user/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 906, in execute
return self._execute_text(object, multiparams, params)
File "user/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
statement, parameters
File "user/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "user/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1344, in _handle_dbapi_exception
util.reraise(*exc_info)
File "user/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "user/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
TypeError: 'dict' object does not support indexing
Workaround: Use % twice to escape it from substitution
sql2csv --db 'postgres://user@host/db' --query "SELECT datname from pg_database where datname like '%%'" -v
Discussion: It looks like sqlalchemy is interpreting % as a string formatting marker; because there are no ways to pass arguments to sql2csv this is useless.