PL/Python - Mailing list pgsql-general

From Joe Abbate
Subject PL/Python
Date
Msg-id 4E852515.5010801@freedomcircle.com
Whole thread Raw
Responses Re: PL/Python  (Sim Zacks <sim@compulab.co.il>)
List pgsql-general
Hi,

I'm toying with the idea of making the Pyrseas utilities a true
PostgreSQL extension. Currently, the utilities (dbtoyaml and yamltodb)
rely on a library of Python functions: over 16 modules and 4000+ lines
of code.  The programs would remain as Python command line front-ends,
but there would be a PL/Python function, i.e., to_yaml() or to_map(),
that would return a YAML / JSON map, like this:

{'schema public': {'type greeting': {'attributes': [{'how': 'text'},
{'who': 'text'}]}, 'function pymax(a integer, b integer)': {'language':
'plpythonu', 'source': 'return a if a > b else b', 'returns':
'integer'}, 'description': 'standard public schema'}, 'language
plpythonu': {}}

(Looks nicer this way, in YAML):

language plpythonu: {}
schema public:
  description: standard public schema
  function pymax(a integer, b integer):
    language: plpythonu
    returns: integer
    source: return a if a > b else b
  type greeting:
    attributes:
    - how: text
    - who: text

Although there are no discussions or examples in the documentation, I've
determined that PL/Python supports Python new style classes like class
Test(object), and import of standard modules.

Now, in order for to_yaml/to_map to do its work, it needs to import 15
modules, e.g.,

from pyrseas.dbobject.language import LanguageDict

I'd be interested to know if anyone has tried something similar (in
terms of scope) and if so, how they tackled it.

The other function, diff_yaml() or diff_map(), is a bit trickier because
it requires reading in a YAML spec file, like the one above, and then
comparing it to the internal version of to_yaml/to_map, in order to
output SQL DDL statements.  The command line tool could read the spec
file locally and send it off as one big text argument.  Again, I'm
interested in similar experiences if any.

Recently in -hackers there was a discussion about splitting pg_dump.c
and some suggested breaking it up IIUC by catalog object type (much like
Pyrseas does) and providing, for example, access to functions that
output SQL DDL for a given object.  A side effect of turning Pyrseas
into an extension could be --with some extra work-- to provide such a
set of functions. I'd like to know if there is any interest in this
capability.

Joe

pgsql-general by date:

Previous
From: salah jubeh
Date:
Subject: Re: Identifying old/unused views and table
Next
From: Royce Ausburn
Date:
Subject: could not access file "$libdir/pg_buffercache": No such file or directory