Connect to PostgreSQL from Python (Using SQL in Python) | Python to PostgreSQL

preview_player
Показать описание
Connect to PostgreSQL from Python (Using SQL in Python) | Python to PostgreSQL
In this video, we shall understand how to connect to PostgreSQL Database from Python. We shall write a python program which will use the Psycopg2 module to connect to the PostgreSQL database and then perform some database or SQL transactions such as creating a table and then insert data to the table, updating a table data and delete records from the table using python code. We shall also see how to fetch table data from postgres database to python program.

At the end of the video, I will also cover how to use Context Manager to perform all of the above SQL operations. That is, we will use the WITH clause to connect to the database and also use the WITH clause to open the cursor. I will also mention what are the advantages of using WITH clause and why it is recommended to always use context manager or WITH clause when working with database in python.

Download the Python script used in this video from my blog. Link below:

Timeline:
00:00 Intro
00:42 Prerequisites for connecting to PostgreSQL from Python
02:18 Connecting to PostgreSQL from Python
05:33 Opening a cursor to perform database operations
07:52 CREATE Table in PostgreSQL database from Python program
10:37 INSERT single record to a table in PostgreSQL from Python program
12:23 INSERT multiple records to PostgreSQL table from Python program
14:30 FETCH data from PostgreSQL Table and display in Python program
17:23 UPDATE Table data in PostgreSQL database from Python program
18:50 DELETE Table record in PostgreSQL database from Python program
20:14 Using Context Manager to connect to PostgreSQL database from Python

We shall be using psycopg2 module to connect to PostgreSQL database from python, which is considered to be one of the best libraries to connect to postgres from python.

We shall start the video by covering the couple of pre-requisites which is to first install the psycopg2 module and then finding the credentials or information required to connect to the postgres database.

After this we shall write the python program which will initially connect to the PostgreSQL database and then open a cursor which will be then used to perform the database operations like CREATE TABLE, INSERT INTO Table, UPDATE Table data, DELETE table record and also how to fetch or retrieve table records or table data from the database to Python program.

Finally, we shall end the video by talking about context manager way of connecting to the database and also how to use context manager to open a cursor. Using context manager is simply using the WITH clause while connecting to the database and then also using the WITH clause while opening the cursor.
I will also mention the advantages of using a context manager over the traditional method or connecting to data and opening the cursor. And also mention why is it recommended to always use context manager when connecting to database in python.

Hopefully this video helped and gave you some useful information of using SQL within python program. If you liked it then please make sure to like the video and also subscribe to the channel.

🔴 WATCH MORE VIDEOS HERE 👇

✅ SQL Tutorial - Basic concepts:

✅ SQL Tutorial - Intermediate concepts:

✅ SQL Tutorial - Advance concepts:

✅ Practice Solving Basic SQL Queries:

✅ Practice Solving Intermediate SQL Queries:

✅ Practice Solving Complex SQL Queries:

✅ Data Analytics Career guidance:

✅ SQL Course, SQL Training Platform Recommendations:

✅ Python Tutorial:

✅ Git and GitHub Tutorial:

✅ Data Analytics Projects:

THANK YOU,
Thoufiq
Рекомендации по теме
Комментарии
Автор

As a old woman learning to upgrade, I found your videos handy and very clear to catch up.I am one of your subscriber.I watched your SQL contents and simply loved it. So are your python concepts. Thank you for all your hardwork and is not easy to deliver.God bless and keep teaching people like me and others🙏

girijashamak
Автор

Such a comprehensive and quick tutorial to get the basics! I recommend this tutorial after watching neural nine crash course for python and postgres. This really gives you more efficient and clean solutions for writting code.

gabip
Автор

This is really great stuff!
I'm a math, ml, guy and I feel like I'm learning great python techniques here
THANK YOU
Morgan

mtmanalyst
Автор

Instantly subscribed!
You mentioned all the details like preventing sql injection, using the 'with' clause, and so on (unlike other youtube tutors who just skip these ), so it's really helpful and you're a fantastic teacher! 💯

prathagautam
Автор

This video was quite helpful. Saved me a lot of time and very comprehensive too. Thank you🙏

ruthaipoh
Автор

This video is pure gold!!! Thank you for doing such a great job on this.

NiceChange
Автор

Dude. Love this video. demystifying postgres with python. Great work!!! this video goes in the vault. Thank you.

NiceChange
Автор

Very quick, clear and easy to catch. Thanks:)

DanjumaMuhammad
Автор

Very clear and instructions where easy to follow! Thanks for this video.

dogedingo
Автор

Thx for the video, very useful and easy to understand! great job!

kunrath
Автор

Very Nicely explained...Clarity was maintained from the beginning till the end of the video. Thank you so much!

dimplesantoshi
Автор

You saved me today. Thanks, awesome video. Can you do more videos like this one, please? I love your method of teaching you are a natural teacher. Thank you! Absolutely a fantastic

Makingdifference
Автор

Very nice video. Not only showing how to get things done but also details like the try block, the little scripts (to reuse code) and stuff.

osljpiq
Автор

You taught this fantastically! With your teaching I am able to immediately go away and use this knowledge on my own project - it's rare that anyone teaches me something that can enable me to do this with such ease. Look forward to watching more of your videos!

shakearound
Автор

woooo man THANK YOU SO MUCH you helped me a lot bro, you literally made this so easy to understand and spot on

I just started learning python and my manager is like I need results, you made my life easy by posting this video !!!!


🙏🙏🙏

piyushtalegaonkar
Автор

Thank you! Absolutely a fantastic I love your teaching method.

shiblyaziz
Автор

The explanation is really clear! It is easy to understand what you are doing. Great job!

blnqqgu
Автор

Great video, well explained, organized and efficient

ShenderRamos
Автор

Very helpful video.... Thank you so much😊😊

wbovvhx
Автор

Thank you so much for the video, I was having problems with rollback, any single mistake that I made, I had to start all over, but your video showed me a better approach.

ashaoluayanfe