PL/Python

From: Joe Abbate <jma(at)freedomcircle(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PL/Python
Date: 2011-09-30 02:10:29
Message-ID: 4E852515.5010801@freedomcircle.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Royce Ausburn 2011-09-30 02:45:10 could not access file "$libdir/pg_buffercache": No such file or directory
Previous Message salah jubeh 2011-09-30 00:37:09 Re: Identifying old/unused views and table