[sqlalchemy] Re: remove duplicates - DISTINCT constraint

2007-05-24 Thread Eric Ongerth



On Apr 3, 2:41 am, Disrupt07 [EMAIL PROTECTED] wrote:
 It would be nice if SQLAlchemy has something to constrain distinct
 values on save() or flush().

You might be interested in this:
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: remove duplicates - DISTINCT constraint

2007-04-03 Thread Glauco

Disrupt07 ha scritto:
 I need to populate a table with author names
 for example the table name is author and it has a field authorname
 of type text.  authorname has the following values:
 W. Shakespear
 J. Smith
 W. Shakespear
 R. Williams
 K. Winslet
 ... and so on.

 Then I want SQLAlchemy to remove the duplicates, so that W.
 Shakespear will be saved only once.

 How can I achieve this using SQLAlchemy?
 Thanks
   
Primary Key  or unique constraint do this...


anyway if these names are stored in a list or something similar a 
sequence...
firt of all put it in a type 'set' ...so automatically your problem is 
gone..

In [21]: set( [ 'W. Shakespear', 'J. Smith', 'R. William', 'W. 
Shakespear', 'J. Smith'])
Out[21]: set(['W. Shakespear', 'R. William', 'J. Smith'])




Glauco

-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: remove duplicates - DISTINCT constraint

2007-04-03 Thread Glauco

Disrupt07 ha scritto:
 Thanks.  But what do you mean by a type 'set' ?  Is this a
 functionality of SQLAlchemy or of a list or some programming language?

   

What's your data sources ?  a python  list? a text file? another DB?

You can do a sequence of insert into with a unique contraint over that 
field so duplicate records will not be stored...




the set otherwise is only usable if you have a list (from a turbo Gear 
Form form for example )


a = Authors()
my_authors= [ 'W. Shakespear', 'J. Smith', 'R. William', 'W. 
Shakespear', 'J. Smith']

for x in set( my_authors )
 a.new(  x  )


 Please explain how to do it in SQLAlchemy because I want to populate
 the table initially with all of the data, then I want SQLAlchemy to
 save only unique distinct values.

   

Glauco

-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---