Hi Michael,
On Thu, 2006-07-13 at 14:54, Michael Bayer wrote:
> hey list -
> 
> im working on explicit CONSTRAINT objects, primarily a FOREIGN KEY  
> constraint which cleanly allows composite foreign keys that work in a  
> CREATE statement.  but while im adding "ForeignKeyConstraint", im  
> also adding a distinct "PrimaryKeyConstraint" as well as  
> "UniqueConstraint".
> 
> Thing is, we already have "unique" as an option on Column, which  
> results in the creation of a UNIQUE INDEX clause after that of the  
> Table itself.
> 
> The way this is going, it would be cleaner for Column(....,  
> unique=True) to create a CONSTRAINT instead of an INDEX, i.e.:
> 
>       CREATE TABLE foo (
>               col1 INTEGER PRIMARY KEY,
>               col2 VARCHAR(20),
>               UNIQUE (col2)
>       )
> 
> as opposed to:
> 
>       CREATE TABLE foo (
>               col1 INTEGER PRIMARY KEY,
>               col2 VARCHAR(20),
>       )
>       CREATE UNIQUE INDEX uix_foo_col2 ON foo (col2)

> its not immediately clear to me how these two things differ.  does  
> anyone have any comments on this ?   does this make a huge difference  
> for various DBs ?

IIRC most DBs implement the constraint as a unique index under the
hood, however they aren't required to.  Thus the unique constraint
would not necessarily carry the benefits of having an index.
In theory the constraint would *NOT* be a candidate for consideration
in query plan optimization whereas an index would be.

>    while the explicit Index object would still be  
> available, the "unique" keyword argument on column would result in  
> the first syntax instead of the second one.  is anything going to  
> break ?

I would not expect anything current to break. I do recall
working with one older DB engine (MySQL perhaps) that had the
unique constraint syntax just for easing porting, it didn't
actually enforce anything.  You had to create the index
if you really wanted to enforce uniqueness.

HTH,
William.



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to