31 messages in com.googlegroups.pylons-discussRe: sqlalchemy and threadlocal docs o...
FromSent OnAttachments
Michael Bayer18 Sep 2006 21:50 
Jamie Wilkinson18 Sep 2006 22:34 
Alexandre CONRAD19 Sep 2006 01:51 
Bayle19 Sep 2006 19:45 
Joe19 Sep 2006 20:19 
Larry19 Sep 2006 20:51 
Joe19 Sep 2006 21:29 
Larry20 Sep 2006 04:32 
Joe20 Sep 2006 07:36 
Michael Bayer20 Sep 2006 09:50 
James Gardner23 Sep 2006 19:01 
James Gardner24 Sep 2006 07:45 
ben adam24 Sep 2006 10:28 
ben adam24 Sep 2006 10:32 
Sergey Lipnevich24 Sep 2006 14:48 
James Gardner25 Sep 2006 02:48 
James Gardner25 Sep 2006 02:52 
Alexandre CONRAD25 Sep 2006 10:54 
Daniel Lyons25 Sep 2006 12:43 
Joe25 Sep 2006 18:55 
wyatt-bC25 Sep 2006 21:43 
John_Nowlan26 Sep 2006 09:22 
James Gardner27 Sep 2006 05:46 
James Gardner27 Sep 2006 05:55 
Michael G. Noll29 Sep 2006 07:40 
kevin02 Oct 2006 04:22 
owl04 Oct 2006 08:31 
paul26 Nov 2006 00:17 
Michele Campeotto26 Nov 2006 02:40 
Michele Campeotto26 Nov 2006 02:46 
paul26 Nov 2006 09:19 
Subject:Re: sqlalchemy and threadlocal docs on pylons tutorial
From:Michael Bayer (mike@zzzcomputing.com)
Date:09/20/2006 09:50:39 AM
List:com.googlegroups.pylons-discuss

an important article (well, a blog post that links to an important article) against the usage of surrogate primary keys:

http://spyced.blogspot.com/2006/07/single-column-primary-keys-should- be.html

On Sep 19, 2006, at 11:51 PM, Larry wrote:

Joe wrote:

<snip> it is generally preferable to use "natural" or "standard" IDs as primary keys. Since the page title in the wiki is unique it's a "natural" choice. <snip>

For almost every project where we used natural primary keys, I've needed to later add some utility to allow the user to alter them. This code needs to look accross every table that reference this primary key and alter it there. Running it without concurrency problems is difficult and so dealing with the entire issue is just extra work and a headache. It also introduces another user interface element that I have to train to users (key changes must be done in single user mode using this special key change menu item, blah-blah-blah). So a while back, I switched to never using natural primary keys. I've also heard that integers are more efficient but it's not the reason I use them.

Surogate primary keys are also the most common pattern I see from experienced DBAs/developers/teams. SQLObject even defaults that way not because it is more simple, but I suspect because Ian and others must think it is good practice.

Even on the wikipedia page you reference, it says, "Having the key independent of all other columns insulates the database relationships from changes in data values or database design (making your database more agile) and guarantees uniqueness. Some database designers use surrogate keys religiously regardless of the suitability of other candidate keys, while others will use a key already present in the data, if there is one."

That said, I don't like my tools to place unecessary restrictions on me. I like that SQLAlchemy will work equally well with databases that I designed years ago, before I saw the light and stopped using natural primary keys. I still like to design my database in the database and I find it trivial to manually add my own integer primary keys to every table. I'm more of a fan of autoload=True and SQLSoup than I am of ActiveMapper although I see the advantage of a Django Data Model Driven framework (or TG-FastData) for standing up new systems with no legacy to worry about and I see how ActiveMapper is a necessary part of that. That's just not usually the space where I usually work and SQLAlchemy is the ideal tool for either situation.