Re: lastrowid and INSERT ... RETURNING

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <[email protected]>
Il giorno ven, 06/06/2008 alle 17.58 -0700, Cliff Wells ha scritto:
> On Wed, 2006-07-26 at 08:45 +0200, Federico Di Gregorio wrote:
> > Il giorno mar, 25/07/2006 alle 15.22 -0700, craigp ha scritto:
> > > there's a todo item at
> > > http://www.postgresql.org/docs/faqs.TODO.html (search
> > > for returning) which would return columns/expressions on
> > > insert/update. so
> > > if/when that's done there'll be a mechanism to support the use-case of
> > > returning the primary-key of a newly-inserted row (among others). 
> > 
> > That would be neat. Please, poke at me when it is ready in pg. :)
> 
> Poke.  Added in 8.2.4.
> 
> test=# create table foo ( id serial primary key not null, name text );
> 
> test=# insert into foo ( name ) values ( 'cliff' ) returning id;

RETURNING can return anything so does it make sense to hack some magic
to automatically populate .lastrowid when the query is an INSERT and the
value returned is a long (like the OID were) or is better to simply
accept that PostgreSQL does not support row ids and put the .fetchone()
in the code?

I am for the second but I can hack .lastrowid if enough people need it
to transition from old backends with automatic OIDs to the new ones
where OIDs are not geneated by default.

federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
              Una nazionale senza neanche una nazione. -- macchinavapore

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkiW0EUACgkQvcCgrgZGjeuNwwCghKvp00F4TaTNEEKnLRZiR0s9
fr8AnjT/XGdXxuggPw9XarDXObIGIeX9
=r2X0
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.