Junior — Middle
Have you had experience working with PostgreSQL database in your projects?
sobes.tech AI
Answer from AI
Yes, in Python projects I often used PostgreSQL as the main relational database. For interaction, I used libraries:
- psycopg2 — a low-level driver for connecting and executing SQL queries.
- SQLAlchemy — an ORM for convenient work with the database through Python objects.
Example of connecting and executing a query using psycopg2:
import psycopg2
conn = psycopg2.connect(
dbname="mydb",
user="user",
password="password",
host="localhost"
)
cur = conn.cursor()
cur.execute("SELECT * FROM users WHERE active = TRUE;")
rows = cur.fetchall()
for row in rows:
print(row)
cur.close()
conn.close()
PostgreSQL is valued for its reliability, extensibility, and support for complex queries, making it a popular choice for Python applications.