Query a PSQL Database From Python 1

Query a PSQL Database From Python

conn = psycopg2.connect("dbname=suppliers user=postgres password=postgres")Code language: SQL (Structured Query Language) (sql)

Here is what the above code is Doing:
1. Import the psycopg2 library.
2. Create a connection to the database.
3. Create a cursor object.
4. Execute the SQL query.
5. Close the cursor and connection.

Similar Posts