[Twisted-Python] serial datatype in t.e.row
bruce at cubik.org
Sun Sep 15 19:09:01 EDT 2002
Sean Riley wrote:
> I have been looking at adding support for "serial" columns into
> twisted.enterprise.row and it appears to be harder than i originally
> ... snipped ...
> But.. using twisted enterprise:
> newRow = MyRow()
> does effectively the same thing, but the newRow object doesn't know the
> value of the index column (column1 in this case) that was just inserted, so
> it doesn't know how to update or delete itself!
> One solution may be to manually run a
> SELECT nextval('sequencename')
> to get the next value and use that for the insert, but this requires an
> extra step for each insert, and requires that the we know which tables have
> serial columns (suprisingly hard to figure out..) and makes the behavior for
> tables with serial columns and no serial columns very different.
Ignoring the various problems that you're needing to solve, if you're
using pyPgSQL, after an insert operation, the oid of the new row is
available on the underlying pyPgSQL cursor object. You can use that
along with a select to get back the serial column value inserted rather
than necessarily having to select off of the sequence.
More information about the Twisted-Python