I'm writing a plpython function using postgresql 9.2. Assume the code has already executed a query that returns hstore strings. I wish to then issue a query:
SELECT hstore_to_matrix('hstorestring')
Let's say that it is a string containing the hstore string: 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;
Run as
select testfreq();
Returns
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":
If you replace with hstore_to_array in the code above, the output is:
testdb=# select testfreq();
LOG: ('Hstore:', {'hstore_to_array': ['GT', 'thing', 'HS', '[-0.1,-0.2]']})
CONTEXT: PL/Python function "testfreq"
testfreq
----------
done
(1 row)
I have also tried to use hstore operators instead of functions and I have tried out these functions in a pgsql terminal to make sure they work when not embedded in python. Any pointers would be greatly appreciated.