我有使用psycopg2調用一個PostgreSQL PROC python腳本。該過程具有以下簽名。psycopg2查詢參數類型
CREATE FUNCTION utility_function(p_id_file bigint, p_size bigint, p_id_volume smallint, p_id_type_file bigint, p_id_user bigint) RETURNS void
當我把它用下面的代碼,我得到這個錯誤...
Traceback (most recent call last):
File "/tmp/regenerate/regenerate.py", line 173, in <module>
execute_process(db, out_csv, out_file, start_date, end_date, limit, offset)
File "/tmp/regenerate/regenerate.py", line 57, in execute_process
db.execute(sql, (id_file, size, id_volume, id_type_file, id_user))
psycopg2.ProgrammingError: function utility_function(integer, integer, integer, integer, integer) does not exist
LINE 1: select * from utility_function(13456, 132456798, 0...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我無法弄清楚如何將參數轉換爲正確的PostgreSQL類型。
的Python代碼看起來是這樣的。
sql = 'select * from utility_function(%s, %s, %s, %s, %s)'
logging.debug(db.mogrify(sql, (id_file, size, id_volume, id_type_file, id_user)))
db.execute(sql, (id_file, size, id_volume, id_type_file, id_user))
db.mogrify返回此:
select * from utility_regenerate_tsstream(13456, 132456798, 0, 42, 1324)
在此先感謝您的幫助:) 山姆
發佈您的代碼,你賦值'id_file','size'等 – 2012-03-26 11:12:34
他們是從另一個查詢分配的一部分,如:db.execute(sql)id_file = db [0]等... – Nostradamnit 2012-03-26 11:56:11