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

2014年7月15日 10:45

在用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作者去世,后面没有更新维护了
 

 

Tags: webpy;postgres
评论(1) 阅读(2696)

postgres复制表结构

2014年6月17日 11:18

  • 复制表结构
create table his_process_data_201405 as 
( select * from his_process_data_201406 limit 0)
  • 完整复制一张表
create table his_process_data_201405 as 
( select * from his_process_data_201406)

 

 

评论(1) 阅读(4497)