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
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® in...@sferacarta.com
Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054
+------------------------------------------------------------+
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.
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Ž in...@sferacarta.com
It worked for me with the set() function.
It would be nice if SQLAlchemy has something to constrain distinct
values on save() or flush().
I think this is not work for SA....
if you have an unique field and do some
insert into table values ( 'boo');
you do an error and the DB do the unique check contraint for you....
in the same manner:
a = Table()
for x in ['boo','boo','boo']:
a.new( x );
i think is better let the DB do his work..... and SA remain the orm :-)
On Apr 3, 2:41 am, "Disrupt07" <cvbn...@gmail.com> 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