0

Is there a way to view the INSERT command the sqlalchemy is about to execute?

My scenario is as follow:

  1. adding an object to the session - session.add(my_obj)
  2. executing the insert by calling - session.flush()

I know how to view the content of a SELECT request:

print(q.statement.compile(compile_kwargs={"literal_binds": True}))

thanks to: How do I get a raw, compiled SQL query from a SQLAlchemy expression?

Gil
  • 21
  • 2
  • hello, isn't it so to put echo=True in the creation of the engine? engine = sqlalchemy.create_engine('postgres://foo/bar', echo=True) – Caio Filus May 05 '23 at 17:32
  • thank you @CaioFilus, I was hoping for something more detailed. I'm getting a truncated message: `[SQL: INSERT INTO my_table (id, name, ...) VALUES (%(id)s, %(name)s, ...)] [parameters: [{'id': 123, 'name': 'test' ... (276 characters truncated) ... ]]` – Gil May 05 '23 at 19:11

0 Answers0