This document is a tutorial on performing CRUD operations with PostgreSQL using Python. It includes steps for downloading pgAdmin4, creating a database, installing the psycopg2 library, and executing SQL commands to create, insert, select, update, and delete data. The tutorial emphasizes the importance of using try and except blocks in the code for error handling.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views9 pages
PostgreSQL_Python
This document is a tutorial on performing CRUD operations with PostgreSQL using Python. It includes steps for downloading pgAdmin4, creating a database, installing the psycopg2 library, and executing SQL commands to create, insert, select, update, and delete data. The tutorial emphasizes the importance of using try and except blocks in the code for error handling.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
01
eC
TUTORIAL
@PostgreSQL
with
Python
CRUD opt with postgreSQl in python
@_python.py_
Python | Programming | Projects
Arvind Singh
Python FullStack Developer
SAVE ITA02
Download pgAdmin4
https://www.pgadmin.org/download/
Create new database I create ‘test’ name database
a = Here two database
postgres and test. we
use test database
aan an
@_python.py_ SAVE ITA
Python | Programming | Projects03
1. Install psycopg2
run this command - pip install psycopg2
2. Connect with database.
to check hostname, port and * ans E
username
right click + Properties and go
on Connection
password is same as you set
in installation time.
Move a
@_python.py_
ne pegeasare rep SAVE ITA04
3. Create table.
sute(create_script)
for check table in database run select query in pgAdmin
va allek ner for ais] a “Tel a fap Taalar re ieee esas ss) a) at
or Fn any query
table
@_python.py_ SAVE ITA
Python | Progamming | Projectsos
3. Insert data.
eae
Note: write code between in try and except
4. Select data.
@_python.py_ SAVE ITA
Pytion | Programming | Projects06
5. Update.
: rte(updat
erst)
print()
ee eceeg@)
Boner EW 89, owns opener SOL suteice Depend 1
eeey eas eee a aw 1 +o
@_python.py_ SAVE ITR
Python | Programming | Projacts07
6. Delete.
@_python.py_
Python | Programming | Projacts
SAVE ITR08
Source Code
SAVE ITAo9
cute( SELECT * FROM IG python’)
a eaeairTelo)
peuees eases un eae
se eu
etree)
print()
errs}
Ree aa eo nr
id = (‘_python.
Soars eid)
Teen rs aca oe CRs DD)
s .fetchall()
tag ica an
coe ei
aor)
print()
reins Pe
Pete ery
finally
@_python.py_
Python | Programming | Projects
SAVE ITR