Re: does the executemany() limitation with result sets apply to INSERT..RETURNING ?
James Henstridge <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Mar 2, 2009 at 5:32 PM, Michael Bayer <[email protected]> wrote: > > On Mar 2, 2009, at 3:09 AM, Federico Di Gregorio wrote: > >> Il giorno dom, 01/03/2009 alle 15.07 -0500, Michael Bayer ha scritto: >>> >>> - executemany() now return the numer of total INSERTed or UPDATEd >>> rows. Note that, as it has always been, executemany() should not >>> be used to execute multiple SELECT statements and while it will >>> execute the statements without any problem, it will return the >>> wrong value. >>> >>> This appears to be the case as well for INSERT...RETURNING as in the >>> example below. >> >> This has always been the case with any statement returning tuples. >> executemany() *is not* for gathering multiple result sets. > > well the only difference here is that an INSERT..RETURNING would in theory > return just one result set even for many statement executions, since each > insert only affects a single row. Not quite true. The following query will give a result set containing three rows: insert into foo (id) values (1), (2), (3) returning id; > but don't worry, im not asking for this, just confirming the behavior. Note that psycopg doesn't parse the SQL statements: it just sends them through to PostgreSQL. The response from PostgreSQL then indicates whether the statement produced a result set. So you shouldn't really expect psycopg to exhibit special behaviour for particular statements. James.