4
我正在使用postgresql 9.2寫一個plpython函數。假設代碼已經執行了一個返回hstore字符串的查詢。我想,然後發出一個查詢:postgres與hstore字符串文字plpy.execute故障
SELECT hstore_to_matrix('hstorestring')
比方說,它是一個包含hstore字符串的字符串:A=>B
create or replace function testfreq()
returns text
as $$
hstorestring = '"GT"=>"thing","HS"=>"[-0.1,-0.2]"'
rv2 = plpy.execute("SELECT hstore_to_matrix(%s)" % (plpy.quote_literal(hstorestring)))
plpy.log("Hstore:",rv2[0])
return("done")
$$ LANGUAGE plpythonu;
運行方式
select testfreq();
返回
testdb=# select testfreq();
ERROR: plpy.Error: unrecognized error in PLy_spi_execute_fetch_result
CONTEXT: Traceback (most recent call last):
PL/Python function "testfreq", line 3, in <module>
rv2 = plpy.execute("SELECT hstore_to_matrix(%s)" % (plpy.quote_literal(hstorestring)))
PL/Python function "testfreq":
如果你r E放置在上面的代碼hstore_to_array,輸出爲:
testdb=# select testfreq();
LOG: ('Hstore:', {'hstore_to_array': ['GT', 'thing', 'HS', '[-0.1,-0.2]']})
CONTEXT: PL/Python function "testfreq"
testfreq
----------
done
(1 row)
我也曾嘗試使用hstore運營商,而不是功能,我已經嘗試了在pgSQL的終端這些功能,以確保在不嵌入在他們的工作蟒蛇。任何指針將不勝感激。
的字符串文字可以是紅色鯡魚。我得到與任何「SELECT yourdbfunc()」查詢字符串相同的錯誤。 – user2288586
另一個更新。我可以執行plpy.execute(「SELECT hstore_to_array(%s)」%(ploy.quote_literal(s)))。但不是hstore_to_matrix。耶因爲失敗。 – user2288586
請從「CREATE FUNCTION」開始編輯您的問題,以包含一個演示此問題的函數的*完整*示例。如果可能的話,我也想看看你的Python版本。請在此處註釋,以便我得到通知。 –