how to pickle objects for database storage?

Laszlo Nagy gandalf at designaproduct.biz
Wed Apr 11 14:20:50 EDT 2007


krishnakant Mane írta:
> hello,
> I have a strange but very interesting requirement?
> provided that a database can provide for an object data type like
> binary large object (blob), can I store a pickeled python object in
> it?
>   
Why not?
> I know oracle has blob and clob and believe that mysql/ postgre sql
> has some thing similar to store direct objects?
>   
Yes, although PostgreSQL's large object interface is quite different. In 
Pg, a large object is more likely a file object that you can read/write, 
and it has limited support. The Python DB API does not define large 
object functions, and that is only the top of the iceberg....

If you do not want to store very big objects and if you really want 
something that is similar to blob fields found in other databases, then 
I recommend that you use the 'text' type and base64encode the pickled 
data. (AFAIK in PostgreSQL, the 'text' type can store 4GB of data, but 
you will run into problems if you try to store real binary data in it 
with SQL sentences...)
> if not then should a pickeled object wrapped inside a file and then stored in a database?
>   
Sorry, I do not understand this question. :-)

  Laszlo




More information about the Python-list mailing list