split problem if the delimiter is inside the text limiter
python.list at tim.thechases.com
Wed Mar 18 20:26:13 CET 2009
> sql = ''' INSERT INTO table (column1,column2, ...) VALUES ( %s,
> %s, ....); '''
> for row in rows:
> connection.cursor.execute(sql % (row,row,....))
> but something binary in a cell, the pgdb says it is not in utf-8
> format, or something like this.
> I know it's a newbie solution :))
> better solution?
The first step is to use the database's quoting to prevent
problems where miscreant characters (such as a single-quote)
appear in the data:
connection.cursor.exeute(sql, (row, row))
connection.cursor.exeute(sql % (row, row))
(if your columns in your CSV happen to match the order of your
INSERT statement, you can just use
As for the UTF-8 exception, without knowing more about the data
and the table-definitions, it's hard to offer a tangible solution.
More information about the Python-list