Try adding a relationship between Person and Price.
Then, you could do something like:

    for x in range(1, 10901):
        person = session.query(Person).get(x)
        price = Price(int(array_name[x-1]), extra=0)
        session.add(price)
        person.price = price <http://price.id/>
    session.commit()

This way you can remove the flush, which is the cause of the slow
performance.

2013/6/30 MacVictor <witold.g...@gmail.com>

> I try to use this method, but it's also not a good idea:
>
>     for x in range(1, 10901):
>         person = session.query(Person).get(x)
>         price = Price(int(array_name[x-1]), extra=0)
>         session.add(price)
>         session.flush()
>         person.price_id = price.id
>         session.add(person)
>     session.commit()
>
> This method is slower than the first method
>
>
>
> W dniu niedziela, 30 czerwca 2013 12:46:43 UTC+2 użytkownik MacVictor
> napisał:
>
>> array_name contains 10900 price.
>>
>> create_price = []
>> for x in range(0, 10900):
>>     price = Price(int(array_name[x]), extra=0)
>>     create_price.append(price)
>> session.add_all(create_price)
>>
>> for y in range(1, 10901):
>>     session.query(Person).filter_**by(id=y).update({"price_id":
>> session.query(Price).get(y).**id},
>>
>>  synchronize_session=False)
>>     session.commit()
>>
>> But this is very slow..
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
----------------------------------
Pau Tallada Crespí
Dep. d'Astrofísica i Cosmologia
Port d'Informació Científica (PIC)
Tel: +34 93 586 8233
----------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to