0

I have a "batch" table on my postgresql DB, and I would like to change a single value within column "id", replacing 70 with 15:

from sqlalchemy import create_engine

# Connection with DB
engine = create_engine('postgresql://xxx')

engine.connect()

# Update the value
...
5
  • you can use the SQL statement: UPDATE batch SET id=15 WHERE id=70. How to connect to PostgreSQL from sqlalchemy is answered here: stackoverflow.com/questions/9353822/… Commented Sep 19, 2021 at 9:42
  • Could you please complete the above code to fully answer? Thank you Commented Sep 19, 2021 at 9:47
  • Could you please take a try and do that yourself? (SO is not a code writing service) Commented Sep 19, 2021 at 9:50
  • I know, could you please check the edit? Thank you Commented Sep 19, 2021 at 9:54
  • Which edit ? and please mark your own answer as the 'accepted answer'. (If that solved your question. If not, then that answer should not have been posted as answer, but as an edit to your question. Commented Sep 19, 2021 at 12:11

1 Answer 1

0
# Connection with DB
engine = create_engine('postgresql://xxx')
engine.connect()

# Update the value

sql = f"""
    UPDATE batch
    SET id=15 
    WHERE id=70
"""

with engine.begin() as conn:     # TRANSACTION
    conn.execute(sql)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.