Debugging (displaying) SQL command sent to the db by SQLAlchemy
- by morpheous
I have an ORM class called Person, which wraps around a person table:
After setting up the connection to the db etc, I run the ff statement.
people = session.query(Person).all()
The person table does not contain any data (as yet), so when I print the variable people, I
get an empty list.
I renamed the table referred to in my ORM class People, to people_foo (which does not exist).
I then run the script again. I was surprised that no exception was thrown when attempting to access a table that does not exist.
I therefore have the following 2 questions:
How may I setup SQLAlchemy so that it propagates db errors back to the script?
How may I view (i.e. print) the SQL that is being sent to the db engine
If it helps, I am using PostgreSQL as the db