On 07/04/11 22:40, Mark Sienkiewicz wrote:
> Hi,
>
> I have a portability issue that I'm not sure what to do with: I need an
> automatically unique column, but I don't see a portable way to ask for
> it in my code.
>
> For my example, I'm going to use column k as the key and v as the value,
> though in real life there are another 10 or so columns.
>
> In sqlite and mysql, I can do
> c.execute("insert into foo ( v ) values ( 'xyz' )")
> k = c.lastrowid
Declare k as "serial" and then do the following:
c.execute("INSERT INTO foo (v) VALUES ('xyz') RETURNING k")
k = c.fetchone()[0]
Hope this helps,
federico
--
Federico Di Gregorio federico.digregorio@dndg.it
Studio Associato Di Nunzio e Di Gregorio http://dndg.it
We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil. -- D.E.Knuth