wulczer / pyhstore Goto Github PK
View Code? Open in Web Editor NEWPython extension module for bidirectional hstore to dictionary conversion in PL/Python
Home Page: http://wulczer.org/#pyhstore
Python extension module for bidirectional hstore to dictionary conversion in PL/Python
Home Page: http://wulczer.org/#pyhstore
This is pyhstore, a Python extension module that allows bidirectional transformation between PostgreSQL hstore and Python dictionary objects in PL/Python, the PostgreSQL embedded Python programming language. To build it you will need the Python and PostgreSQL development headers, as well as the header file for the hstore module. It has been tested on PostgreSQL 9.0 and Python 2.6, but should work on earlier versions. It will not work for Python 3. The easiest way to build and install pyhstore is: $ python setup.py build_py $ python setup.py build_ext -I $(pg_config --includedir-server):/usr/src/postgresql-x.x.x/contrib/hstore $ sudo python setup.py install After these steps check if you have correctly installed pyhstore, by connecting to your database and issuing as a superuser: =# do 'import pyhstore' language plpythonu; If the second command completed successfully, you're done with the installation. If not make sure that your server's PYTHONPATH includes the path where extension modules are installed. Using pyhstore ============== You use pyhstore inside your PL/Python functions to serialise and unserialise hstores from dictionaries. The serialisation functions actually accept and output text, but in the format that can then be interpreted by PostgreSQL as hstores. The module itself is a stopgap solution to enable easier hstore usage until PL/Python gets native hstore handling abilities. And example of using pyhstore in PL/Python would be: CREATE FUNCTION hstore_xform(h hstore) RETURNS hstore AS $$ import pyhstore d = pyhstore.parse_hstore(h) total = 0 for key, val in d.items(): v = int(val) total += v d[key] = str(2 * v) d["total"] = str(total) return pyhstore.serialize_hstore(d) $$ LANGUAGE plpythonu; select * from hstore_xform('John => 10, Mary => 30, Tom => 100'); The output will be a hstore with the value '"Tom"=>"200", "John"=>"20", "Mary"=>"60", "total"=>"140"'. The module is distributed under the MIT License. You can contact the author, Jan Urbanski, at [email protected].
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.