From the course: Advanced Python: Working with Databases

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Manipulating with Postgres data using SQLAlchemy Core

Manipulating with Postgres data using SQLAlchemy Core - Python Tutorial

From the course: Advanced Python: Working with Databases

Manipulating with Postgres data using SQLAlchemy Core

- [Instructor] With the setup complete, let's walk through how to establish a connection to a Postgres database using SQL Alchemy Core. Engine dot connect creates a connection with the database. Inside the connection, we run a bunch of CRUD statements. CRUD stands for create, read, update, and delete. These are the main operations you'll run as you manipulate data in any database. Let's start with read. We pass in the sales table to a select statement and then select all the rows in the table. For each row, we print it out. Then we add a new piece of data to the database. It's a sale of a few books called "Understanding Artificial Intelligence." Now, let's say the buyer, Syman Mapstone, gets the books in the mail and one of them has a few pages ripped out. We'd need to update the sales table so he gets a refund for the ruined book. We do that here with an update statement. We say, update the table where the order…

Contents