In a previous article I introduced the psycopg2 Python/PostgreSQL interface and used it to create a database, a few tables and a view. In this post I will demonstrate inserting, updating, deleting and selecting data using the database created in the previous post, as well as showing what happens if we try to violate database constraints.

This article builds on the previous one so assumes you have read it and run the code, and still have the database.

The source code for this project consists of the following two files:

You can copy the code from this article or clone/download the Github repository if you prefer. This project shares a file, pgconnection.py, with the previous post so you might like to save the files for this post in the same folder and share pgconnection.py.

Now let’s look at the code…

#postgresql #python #databases

PostgreSQL Data Manipulation in Python
2.00 GEEK