[Zope] ZSQL retreive auto_increment id inserted [Q]

chas panda@skinnyhippo.com
Fri, 19 Nov 1999 13:23:50 +0800


At 01:01 PM 11/18/1999 -0600, Jim Sanford wrote:
>In PostgreSQL there is a SERIAL data type that is an autoincrementing 4 byte
>integer.
>
>If you have a table called data1 with a field called recid that is created
>as a SERIAL type and a char field called name, you would add a record and
>get the recid like this:
>
>insert into data1 (name) values ('George Smith');
><dtml-var sql_delimiter>
>select last_value from data1_recid_seq;

Aaah, clunk - it was that <dtml-var sql_delimiter> that I 
was missing. Works a treat and Anthony's description becomes
clear. Thank you very much, Jim.

Just for the record (no pun intended), the MySQL equivalent 
is then a rather simple :

insert into data1 (name) values ('George Smith');
<dtml-var sql_delimiter>
select last_insert_id()

(Not certain if it requires the ugly patch to db.py in ZMySQLDA,
as per previous email, but certainly works with it)

chas