I guess you know that storing the actual bytecodes (or the source) of a
Python function in the database itself is not going to buy you much:

Since the function bytecodes or source
would be in Python, only a Python interpreter could run it to produce
the function result, and if you know you're going to be accessing
the database via a Python interpreter (most likely via SA), then you may as
well just bundle the function in a module, import it and use it there like
the rest of us do.

If your'e searching for some more "portable" database logic that can be run
from both a Python interpreter and other types of tools, you want database
user-defined functions (UDF)s and stored procedures. SA supports several
database that sport one or both of these tools:

Oracle             both
SQL Server      both
Mysql              both
Postgresql       functions only, but can modify data like stored procedures

All of these will run the UDF or the stored procedure in the process of the
database server, not in the context of your Python program. That means you
won't be able to access variables in your Python program from the UDF or
procedure, you'll need to supply them as parameters.

If you really have to have the function be a Python function, the PLPython
language for Postgresql allows you to run a real Python interpreter in the
context of the server itself. There was a guy named James Pye who was
working on a full-blown Python programming environment for Postgresql in
which Python would be a full stored procedure language and could share
variables with SQL and lots of other interesting stuff. Might be worth
checking into -- check PGforge or Postgres contrib.

Good luck with this,

Rick

On 11/11/07, luyang.han <[EMAIL PROTECTED]> wrote:
>
>
> Hello all. The problem I want to solve is a little tricky. .I have
> created a table with some columns, which use other python functions to
> generate the default values (default = _some_python_function_). The
> problem is that such function is not saved in the database itsself. By
> just simple reading from the database one cannot get this function
> out. So the problem is how to save such construction into the database
> as well as how to retrieve these.
>
> I have some ideas but have not yet experimented.
>
> 1. One can save the corresponding function as a separate py file and
> refer to this file in some metadata for the table, and the program
> tries to get this py file.
>
> 2. Or one can pickle this default python function and save it to the
> metadata for the table.
>
> 3. Or one can simple pickle the Table or Column object and save it to
> somewhere in the database?
>
> Does anyone has similar experience? Any advices?
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to