On 09/03/2016 01:25 AM, Rafał Rajko-Nenow wrote:

I'm struggling trying to "INSERT IGNORE" into mysql database.
I am using ORM.

All info I've found is about prefixing queries, found nothing about
possibility of prefixing inserts...

the prefix_with() method accomplishes this:

http://docs.sqlalchemy.org/en/latest/core/dml.html?highlight=prefix_with#sqlalchemy.sql.expression.Insert.prefix_with

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)
    x = Column(Integer)
    y = Column(Integer)

e = create_engine("mysql://scott:tiger@localhost/test", echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)

s = Session(e)
s.add(A(id=1, x=2, y=5))
s.commit()

s.execute(
    A.__table__.insert().prefix_with("ignore").values(id=1, x=5, y=10)
)






any help?


--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to