Loading...

Python PostgreSQL

Python PostgreSQL Update

FILE: update.py

import psycopg2

conn = psycopg2.connect(database = "kwikl3arn", user = "postgres", password = "post123", host = "localhost", port = "5432")

conn.autocommit = True
print ("Opened database successfully")

cur = conn.cursor()

cur.execute("UPDATE customers SET address = 'Canyon 123' WHERE address = 'apple'")

print(cur.rowcount, "record(s) affected")

RUN:

C:\Users\Your Name>python update.py


1 record(s) affected