On Mon, Sep 25, 2006 at 10:43:48PM -0500, Jeremy Lowery wrote:
> I am attempting to create a special kind of unique constraint on a 
> table. The database models users, groups and realms. I am attempting to 
> force usernames to be unique inside of a single realm.

If your table looks like

create table user (
        id int primary key,
        username varchar not null,
        realm_id int4);

you could easily get your constraint by doing this:

create unique index realmusername_unq on user (username, realm_id);

If the realm_id is nullable (as mentioned above) this unique key behaves
differently: as far as i know you can have multiple usernames with a
realm_id == NULL.

> I have a feeling there is an easier way to do this and I am just barking 
> up the wrong tree.

I would solve it using a database restraint instead of using the software
restraint: the database is really the one that should be enforcing your
rules.

Regards,
Kai
-- 
begin 600 .signature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to