Locks in SQLAlchemy

Discussion in 'Databases' started by suji, Aug 28, 2015.

  1. suji

    suji

    Joined:
    Aug 28, 2015
    Messages:
    1
    Likes Received:
    0
    Hi,

    I am using SQLAlchemy to do transactions into PosgreSQL db using Python application.
    I don't know how to use locks in SQLAlchemy.

    Anybody can help me to use locks in SQLAlchemy.

    I am facing a problem as follows,

    While running two instances of a an application parallel, it tries to insert rows into a same table. Sometimes I am getting error of duplicate primary key. Can I resolve this using lock concept?


    Best Regards,
    Suji
     
    suji, Aug 28, 2015
    #1
    1. Advertisements

  2. suji

    vthalanki

    Joined:
    Feb 19, 2016
    Messages:
    2
    Likes Received:
    0
    1) If you are using postgres database you want to run the both instance with out the error of primary key use serial data type for the table.
    2) External locking procedure :

    conn = engine.connect()
    conn.execute("LOCK TABLES Pointer WRITE")
    #do stuff with conn
    conn.execute("UNLOCK TABLES")
     
    vthalanki, Feb 19, 2016
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.