English 中文(简体)
2. 与Elixir的粗金矿
原标题:Execute sql query with Elixir

在连接邮政数据库的项目中使用Elixir的Im。 我想对连接的Im数据库进行以下询问,但我不敢肯定如何把它作为Im而不是Eixir和Alchemy的新版本。 任何人都知道如何?

www.un.org/Depts/DGACM/index_spanish.htm

<>Update>

错误是:“不屈不".的迫害:找不到在Kingk或本届会议上配置的束缚”。 此前印发的会议结果相同。 我确实尝试了元数据。 但是,对于世界协调论坛来说,它说:“InternalError: (InternalError) VACUUM不能在交易集团内运作”,因此,我现在试图说明如何扭转这种情况。

<><>Update 2

我可以提出执行问题,但我仍然有同样的错误——即使我设立了一个新的会议并结束了前一届会议。

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()

以及我获得的产出

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  {}

<><>Update 3

感谢大家作出回应。 I wasn table to found the Solutions I Hope, but 我想,我只想到这里所说的解决办法: - 如何从交易栏外的代码中操作VACUUM?。 它并非理想,而是发挥作用。

最佳回答

Dammit. 我知道,答案是正确的。 假定你与我一样建立了联系。

metadata.bind =  postgres://user:pw@host/db 

解决办法简便。

conn = metadata.bind.engine.connect()

old_lvl = conn.connection.isolation_level
conn.connection.set_isolation_level(0)
conn.execute( vacuum analyze table )
conn.connection.set_isolation_level(old_lvl)

This is similar to what was suggested here PostgreSQL - how to run VACUUM from code outside transaction block? because underneath it all, sqlalchemy uses psycopg to make the connection to postgres. Connection.connection is a proxy to the psycopg connection. Once I realized this, this problem came back to mind and I decided to take another whack at it.

希望能帮助某人。

问题回答

您需要将本届会议与引擎挂钩

session.bind = metadata.bind
session.execute( YOUR SQL STATEMENT )

<代码> 不适用 Error 说,贵会议不受发动机的约束,无法从转至<代码>execute(的查询中发现发动机。 您可直接使用<代码>engine.execute(>,或通过附加>mapper para amount(或绘制与查询所用表格对应的图表模型)至session.execute(),以帮助KallAlchemy发现适当的发动机。

表示,你试图在明确(用BEGIN声明)内执行这一声明。 您是否在其面前发表了一些声明,但没有打上<条码>(<>commit(>)? 如果是的话,只有<代码>commit(>或rollback()方法在进行VACUUM之前结束交易。 还值得注意的是,在交易启动时,有几条参数:sessionmaker()。

如果您能出席Kalkacem会议,你可以通过其<条码>execute <<>Q>执行任意声明。 方法:

session.execute("VACUUM FULL ANALYZE table")

http://www.postgresql.org





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...