Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute sql query with Elixir
    primarykey
    data
    text
    <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p> <p><code>VACUUM FULL ANALYZE table</code></p> <p><strong>Update</strong></p> <p>The error is: "UnboundExecutionError: Could not locate a bind configured on SQL expression or this Session". And the same result with session.close() issued before. I did try doing metadata.bind.execute() and that worked for a simple select. But for the VACUUM it said - "InternalError: (InternalError) VACUUM cannot run inside a transaction block", so now I'm trying to figure out how to turn that off.</p> <p><strong>Update 2</strong></p> <p>I can get the query to execute, but I'm still getting the same error - even when I create a new session and close the previous one.</p> <pre><code>from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker # ... insert stuff old_session.commit() old_session.close() new_sess = sessionmaker(autocommit=True) new_sess.configure(bind=create_engine('postgres://user:pw@host/db', echo=True)) sess = new_sess() sess.execute('VACUUM FULL ANALYZE table') sess.close() </code></pre> <p>and the output I get is </p> <pre><code>2009-12-10 10:00:16,769 INFO sqlalchemy.engine.base.Engine.0x...05ac VACUUM FULL ANALYZE table 2009-12-10 10:00:16,770 INFO sqlalchemy.engine.base.Engine.0x...05ac {} 2009-12-10 10:00:16,770 INFO sqlalchemy.engine.base.Engine.0x...05ac ROLLBACK finishing failed run, (InternalError) VACUUM cannot run inside a transaction block 'VACUUM FULL ANALYZE table' {} </code></pre> <p><strong>Update 3</strong></p> <p>Thanks to everyone who responded. <strike>I wasn't able to find the solution I wanted, but I think I'm just going to go with the one described here <a href="https://stackoverflow.com/questions/1017463/postgresql-how-to-run-vacuum-from-code-outside-transaction-block">PostgreSQL - how to run VACUUM from code outside transaction block?</a>. It's not ideal, but it works.</strike></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload