jbauer at rubic
Mar 5, 1999, 8:04 AM
Post #3 of 3
[. Julian discusses using PostgreSQL arrays. My post will *not*
Re: External method pulling data from an SQL method?
[In reply to]
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
>>> 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.
> I am using PostgreSQL's array system for a "categories" field
> in a database, it return records in a format like:
> 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.