[Zope] PostgreSQL, INSERT and new OID

News system cg@cdegroot.com
27 Mar 2001 14:03:22 +0200


Jeremy Cowgar <jcowgar@bhsys.com> said:
>In learning Zope, I came across a stumbling block, and that is how
>to retrieve the OID that an INSERT query will create when using
>Postgre.
>
You shouldn't use database internal oid's anywhere in your code, if that's
what you mean by OID. 

Give every table a primary key "ident" (or whatever - my favourite, "id",
doesn't work well in Zope; the second-best, "oid", is already in use under
pgsql).

Insert using "null" or "nextval('tablename_ident_seq')" (the exact
name of the sequence associated with the serial field is given during
the table create). Retrieve the newly inserted record's id by doing
"select currval('tablename_ident_seq')".