diff --git a/src/hello_postgres/__main__.py b/src/hello_postgres/__main__.py index 225ed79..60e0f05 100644 --- a/src/hello_postgres/__main__.py +++ b/src/hello_postgres/__main__.py @@ -1,5 +1,6 @@ # https://www.freecodecamp.org/news/postgresql-in-python/ # https://www.datacamp.com/tutorial/tutorial-postgresql-python +# docker compose down && docker compose up -d && hello-postgres import psycopg2 import dotenv import os @@ -32,7 +33,18 @@ def main(): cursor.execute("INSERT INTO datacamp_courses(course_name, course_instructor, topic) VALUES('Hypothesis Testing in Python','James Chapman','Python')"); print("Committing the table to the database...") conn.commit() + print("Fetching all the available rows...") + cursor.execute('SELECT * FROM datacamp_courses;') + rows = cursor.fetchall() + for row in rows: + print(row) print("Closing the connection and the cursor...") + print("Changing topic \"Julia\" to \"SQL\"...") + cursor.execute("UPDATE datacamp_courses SET topic = 'SQL' WHERE course_name = 'Introduction to SQL';") + conn.commit() + print("Deleting \"Introduction to Statistics in R\"...") + cursor.execute("DELETE from datacamp_courses WHERE course_name = 'Introduction to Statistics in R';") + conn.commit() cursor.close() conn.close() # cursor.execute("SELECT * FROM DB_table WHERE id = 1")