Jonathan Schaeffer wrote:
> I have an error while using the delete method on a table. The code is
> quite simple, delete a row which I got through a SELECT query.
>
> table=billinginfo
> for row in result.dictresult():
> db.delete(table, row)
>
> The python error is :
> ...
> KeyError: 'oid(public.billinginfo)'
The delete method is actually intended for deleting a (single) row that
has been retrieved with the get() method. The get() method injects the
oid with the key name oid(public.billinginfo) into the dictionary. If
you want to use dictresult, you need to do add the oid manually:
result = db.query('select oid as "oid(public.table_name)",* from
table_name').dictresult()
> Is it normal for the delete() method to build its qcl whith the
> 'public.' prefix?
Yes. This is for distinguishing between tables in different schemas.
> Can I expect the delete method to be quicker than doing a query "DELETE FROM
> " ?
No. db.query("delete from table_name") is the fastest way if you want to
delete every row in the table. If there are no foreign keys involved,
you can do it even faster with db.query("truncate table_name").
-- Chris
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql