[Sqlalchemy-tickets] Issue #3245: postgres: insert into a table whith column name with parentheses
Brought to you by:
zzzeek
|
From: Joris V. d. B. <iss...@bi...> - 2014-11-10 20:17:44
|
New issue 3245: postgres: insert into a table whith column name with parentheses gives KeyError https://bitbucket.org/zzzeek/sqlalchemy/issue/3245/postgres-insert-into-a-table-whith-column Joris Van den Bossche: As the title says, when trying to insert data into a table with a column name containing parentheses, you get a KeyError. Small example: ``` from sqlalchemy import create_engine, MetaData, Table, Column, Integer engine = create_engine('postgresql://postgres@localhost:5432/test') meta = MetaData(engine) table = Table('test_parentheses', meta, Column('CT Volume (cc)', Integer) ) table.create() i = table.insert() i.execute({'CT Volume (cc)': 1}) ``` gives: ``` .... /home/joris/miniconda/envs/dev/lib/python2.7/site-packages/sqlalchemy/engine/default.pyc in do_execute(self, cursor, statement, parameters, context) 322 323 def do_execute(self, cursor, statement, parameters, context=None): --> 324 cursor.execute(statement, parameters) 325 326 def do_execute_no_params(self, cursor, statement, context=None): KeyError: 'CT Volume (cc' ``` This happens with postgresql (not with sqlite), and was reported at the pandas issue tracker (https://github.com/pydata/pandas/issues/8762), but I also saw references to the same issue here: https://github.com/onyxfish/csvkit/issues/317 and http://stackoverflow.com/questions/25917741/sqlalchemy-with-postgres-insert-into-a-table-whose-columns-have-parentheses. Is this possibly a sqlalchemy bug, or has it do to with the psycopg2 driver? |