[Zope-dev] External method pulling data from an SQL method?

Jeff Bauer jeffbauer@bigfoot.com
Fri, 05 Mar 1999 09:04:28 -0600


[ Julian discusses using PostgreSQL arrays.  My post will *not*
  answer his question about how to use external methods. ;-) ]

I do something similar with large text fields.  Rather than
use PostgreSQL's unique (non-portable) array system, I store 
collections of primitives as strings and use eval() when reading 
the fields.

  >>> aList = [1, 'a', 2.5]
  >>> field_value = repr(aList)
    ... perform some database insert operation
    ... read the field back in
  >>> aList = eval(field_value)

This works well for lists and dictionaries that contain other
lists, dictionaries, and primitive data types.  It provides a
possible alternative to storing object data when you're
required to use a relational database system.

Portability is constrained to Python applications, but the
technique is not restricted to any particular database.  I'd 
be interested in learning if other people are using this 
technique (uh, er ... hack) in their Python/rdbms applications.

Best regards,

Jeff Bauer
Rubicon, Inc.


> I am using PostgreSQL's array system for a "categories" field 
> in a database, it return records in a format like:
> '{"foo"}'
> '{"foo","bar"}'
> '{"foo"}'
>
> I am trying to extract the list of unique categories - in 
> this example: ["foo","bar"]
>
> This would be a complete nuisance to do in DTML. I have decided
> to read the SQL method's results into an external method and edit
> them there - but first I need to know how to call a SQL method
> without the "in" DTML tag.