Interaction Python & PostgreSQL
PostgreSQL est un système de gestion de bases de données relationnelles open source. Nous verrons connecter se connecter à une base de donnée PostgreSQL et effectuer les opérations CRUD.
Packages
Paths & Config
Connection to database
Interaction with database
0. Create a table
1. CREATE : Insert data
sql3 = """
INSERT INTO customers (DepartmentID, Name, GroupName)
VALUES (1, 'Engineering', 'Research and Development'),
(2, 'Tool Design', 'Research and Development'),
(3, 'Sales', 'Sales and Marketing'),
(4, 'Marketing', 'Sales and Marketing'),
(5, 'Purchasing', 'Inventory Management'),
(6, 'Research and Development', 'Research and Development'),
(7, 'Production', 'Manufacturing'),
(8, 'Production Control', 'Manufacturing'),
(9, 'Human Resources', 'Executive General and Administration'),
(10, 'Finance', 'Executive General and Administration'),
(11, 'Information Services', 'Executive General and Administration'),
(12, 'Document Control', 'Quality Assurance'),
(13, 'Quality Assurance', 'Quality Assurance'),
(14, 'Facilities and Maintenance', 'Executive General and Administration'),
(15, 'Shipping and Receiving', 'Inventory Management'),
(16, 'Executive', 'Executive General and Administration');
"""
cur.execute(sql3)
conn.commit()
2. READ : Read data
3. UPDATE : Update table
4. DELETE : Delete data
Close connection
References
- Postgres: https://www.postgresql.org/download/
- Pysycopg Docs: https://www.psycopg.org/docs/install.html