Well only caveat here is that I am inserting a list of objects in one go 
using session.add_all() 

On Wednesday, July 23, 2014 2:01:18 PM UTC-5, Michael Bayer wrote:
>
> use a savepoint:
>
> from sqlalchemy import exc
> try:
>    with session.begin_nested():
>         session.add(MyObject())
>         session.flush()
> except exc.IntegrityError:
>     pass
> session.commit()
>
>
> personally I prefer just to emit a SELECT first, which may be a per-row 
> SELECT or may be a prefetch of all the rows from the table in question.
>
>
>
> On Jul 23, 2014, at 2:15 PM, Milind Vaidya <kav...@gmail.com <javascript:>> 
> wrote:
>
> I have a script which updates DB periodically. There are some base table 
> which may undergo some change but very rarely. In such case if this script 
> tries to insert the already present value it will throw integrity error. 
> Is there any way of dealing with this other that first fetch the value 
> manually and then only insert if not present ?
>
> -- 
> 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+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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/d/optout.

Reply via email to