#15 Direct support for UNIQUE table constraint

closed-rejected
nobody
None
5
2005-11-18
2005-04-12
David M. Cook
No

This is a patch to provide direct support for UNIQUE
table constraints by marking each column in the
constraint with uniqueKey=True. I stole the idea from
hibernate (actually in hibernate you specify a
constraint name, so you can have multiple unique
constraints per table; this is just a first pass at the
idea and a RFC).

class Foo(SQLObject):
baz = StringCol(uniqueKey=True)
quux = StringCol(uniqueKey=True)

would produce

CREATE TABLE foo (
id INTEGER PRIMARY KEY,
quux TEXT,
baz TEXT,
UNIQUE(quux, baz)
);

Right now you can get the same practical effect with a
unique index, but this provides direct semantic (or is
it syntactic? I get them confused) support for unique
table constraints, and lets the database decide how it
will enforce the constraint.

I think all the supported DBs support UNIQUE table
constraints, I haven't checked yet. I'll try to come
up with some test cases later.

Discussion

  • David M. Cook
    David M. Cook
    2005-04-12

    Patch for UNIQUE table constraints

     
    Attachments
  • David M. Cook
    David M. Cook
    2005-04-13

    Logged In: YES
    user_id=668544

    Eh, after implementing this, even allowing multiple
    constraints per column, my enthusiasm has cooled. It's
    redundant, and I think doing it with unique indexes actually
    makes the intent clearer, e.g.

    c1 = DatabaseIndex('bar', 'baz', unique=True)
    c2 = DatabaseIndex('bar', 'quux', unique=True)

    vs.

    bar = StringCol(uniqueKey=('c1', 'c2'))
    baz = StringCol(uniqueKey='c1')
    quux = StringCol(uniqueKey='c2')

     
  • Oleg Broytman
    Oleg Broytman
    2005-09-13

    Logged In: YES
    user_id=4799

    Then close the patch, please.

     
  • Oleg Broytman
    Oleg Broytman
    2005-11-18

    • status: open --> closed-rejected