postgres复制表结构

webpy在insert时psycopg2.OperationalError: ...currval 仍没被定义

妙音 posted @ 2014年7月15日 10:45 in postgres with tags webpy;postgres , 2651 阅读

在用webpy的db.insert()向postgres插入数据时出现

Traceback (most recent call last):
  File "upgrade2.0.py", line 170, in <module>
    copy_webservice()
  File "upgrade2.0.py", line 165, in copy_webservice
    db36.insert('top_node_location', **r)
  File "/usr/lib/python2.7/site-packages/web/db.py", line 777, in insert
    self._db_execute(db_cursor, sql_query)
  File "/usr/lib/python2.7/site-packages/web/db.py", line 587, in _db_execute
    out = cur.execute(query, params)
  File "/usr/lib/python2.7/site-packages/DBUtils/SteadyDB.py", line 631, in tough_method
    raise error # reraise the original error again
psycopg2.OperationalError: 错误:  在此会话中序列 "top_node_location_id_seq" 的 currval 仍没被定义   
 
找到/lib/python2.7/site-packages/web/db.py
def _process_insert_query(self, query, tablename, seqname):
    if seqname is None:
        # when seqname is not provided guess the seqname and make sure it exists
        seqname = tablename + "_id_seq"
        if seqname not in self._get_all_sequences():
            seqname = None
    
    if seqname:
        # 注释掉此句
        #query += "; SELECT currval('%s')" % seqname
        pass
        
    return query
原因是webpy在insert时,有一个额外的select使用currval获取当前序列值,但是在postgres9.3中已经不支持currval()了.
看来webpy作者去世,后面没有更新维护了
 

 

Avatar_small
Imamia Quran Academy 说:
2023年8月03日 06:49

These online Shia Quran Courses of Shia Quran Academy include basic learning of Yassarnal Quran which will make it easy for them to learn Quran and recite Holy Quran with correct Tajweed. Join our Online Shia Quran Academy now, and Start your free 3 days Trial.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter