[Twisted-Python] Enterprise Rowobject and generating primary keys
![](https://secure.gravatar.com/avatar/9c47c451103e6d0cd32b018be1f0a530.jpg?s=120&d=mm&r=g)
Hi all, I have a problem creating primary key values for enterprise rowobjects. The KeyFactory class says "This is deprecated. Use the underlying database to generate keys, or just roll your own.". As I am using Postgresql the ideal solution would be to just use the 'nextval' function (which is used as default value for the primary key in my schema, therefore I could skip this column in my insert statement). The problem now is, that I need to assign a value to the rowobject primary key column, otherwise i get an exception from twisted ('instance has no attribute...'). Just excluding the primary key column from my rowColumns attribute doesn't work either as this results in twisted to hang. Manually selecting the nextval function with the adbapi and using the result as primary key works, but this solution isn't really nice. Any other proposals for an elegant solution to create primary keys when inserting new rowobjects? cu /gst
![](https://secure.gravatar.com/avatar/8ca35506ac08cebd833ab53032896c0b.jpg?s=120&d=mm&r=g)
as I remember, nextval is garuenteed to be unique (but definately not sequential) across transactions. Why not just fetch your own value and use it as the key? def mykey() c = pgsql.cursor() c.execute("SELECT nextval('myseqence')") return c.fetchone()[0] or is your question more subtle? *bings* Clark On Thu, May 27, 2004 at 11:25:39PM +0200, Guenther Starnberger wrote: | Hi all, | | I have a problem creating primary key values for enterprise rowobjects. | | The KeyFactory class says "This is deprecated. Use the underlying | database to generate keys, or just roll your own.". As I am using | Postgresql the ideal solution would be to just use the 'nextval' | function (which is used as default value for the primary key in my | schema, therefore I could skip this column in my insert statement). | | The problem now is, that I need to assign a value to the rowobject | primary key column, otherwise i get an exception from twisted | ('instance has no attribute...'). Just excluding the primary key | column from my rowColumns attribute doesn't work either as this | results in twisted to hang. Manually selecting the nextval function | with the adbapi and using the result as primary key works, but this | solution isn't really nice. | | Any other proposals for an elegant solution to create primary keys | when inserting new rowobjects? | | cu | /gst | | _______________________________________________ | Twisted-Python mailing list | Twisted-Python@twistedmatrix.com | http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python | -- Clark C. Evans Prometheus Research, LLC Chief Technology Officer Turning Data Into Knowledge cce@prometheusresearch.com www.prometheusresearch.com (main) 203.777.2550 (cell) 203.444.0557
![](https://secure.gravatar.com/avatar/3c6f9c62d1015960866823348f070ed7.jpg?s=120&d=mm&r=g)
Guenther Starnberger wrote:
There are some that believe that your primary key should come as a natural result of normalizing your data and sequences etc. are not really necessary at all. If that isn't an option and you don't like sequences, the your option is a UUID of some kind i guess. -darryl -- http://randomthoughts.vandorp.ca/WK/blog
![](https://secure.gravatar.com/avatar/8ca35506ac08cebd833ab53032896c0b.jpg?s=120&d=mm&r=g)
as I remember, nextval is garuenteed to be unique (but definately not sequential) across transactions. Why not just fetch your own value and use it as the key? def mykey() c = pgsql.cursor() c.execute("SELECT nextval('myseqence')") return c.fetchone()[0] or is your question more subtle? *bings* Clark On Thu, May 27, 2004 at 11:25:39PM +0200, Guenther Starnberger wrote: | Hi all, | | I have a problem creating primary key values for enterprise rowobjects. | | The KeyFactory class says "This is deprecated. Use the underlying | database to generate keys, or just roll your own.". As I am using | Postgresql the ideal solution would be to just use the 'nextval' | function (which is used as default value for the primary key in my | schema, therefore I could skip this column in my insert statement). | | The problem now is, that I need to assign a value to the rowobject | primary key column, otherwise i get an exception from twisted | ('instance has no attribute...'). Just excluding the primary key | column from my rowColumns attribute doesn't work either as this | results in twisted to hang. Manually selecting the nextval function | with the adbapi and using the result as primary key works, but this | solution isn't really nice. | | Any other proposals for an elegant solution to create primary keys | when inserting new rowobjects? | | cu | /gst | | _______________________________________________ | Twisted-Python mailing list | Twisted-Python@twistedmatrix.com | http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python | -- Clark C. Evans Prometheus Research, LLC Chief Technology Officer Turning Data Into Knowledge cce@prometheusresearch.com www.prometheusresearch.com (main) 203.777.2550 (cell) 203.444.0557
![](https://secure.gravatar.com/avatar/3c6f9c62d1015960866823348f070ed7.jpg?s=120&d=mm&r=g)
Guenther Starnberger wrote:
There are some that believe that your primary key should come as a natural result of normalizing your data and sequences etc. are not really necessary at all. If that isn't an option and you don't like sequences, the your option is a UUID of some kind i guess. -darryl -- http://randomthoughts.vandorp.ca/WK/blog
participants (3)
-
Clark C. Evans
-
darryl
-
Guenther Starnberger