cPickle and pgsql...damn!!

  • Thread starter Gerardo Herzig -Departamento de Proyectos Especial
  • Start date
G

Gerardo Herzig -Departamento de Proyectos Especial

Hi people, im having trouble when trying to UnPickle a 'pickled' field from a
psql (7.3) field.

I just want:
damnDict = {'foo' : 'bar'}
serializedDict = cPickle.dumps(damnDict)
print serializedDict
'}q\x01U\x03fooq\x03barq\x03s.'
pgconn.query('insert into TABLE values (%s)' % serializedDict)
result = pgconn.query('select * from TABLE').getresult()[0]
print result
'}qx01Ux03fooqx03barqx03s.'
And....voila!! There is not the same piece of crap!!
When i try to unpickle it (and get the original damnDict) i got 'Cant find
MARK' error msg. Maybe this is a PostgreSQL issue, but if someone have a
clue....
Here is the data
Python 2.2
PostgreSQL 7.3
The field where i put the serialized data is a text field.

Thanks!
 
P

Peter Maas

Gerardo said:
print serializedDict
'}q\x01U\x03fooq\x03barq\x03s.'
pgconn.query('insert into TABLE values (%s)' % serializedDict)
result = pgconn.query('select * from TABLE').getresult()[0]
print result
'}qx01Ux03fooqx03barqx03s.'

And....voila!! There is not the same piece of crap!!

You can embed octal representations in an SQL string:
'insert into TABLE(key,val) values ('embeddednewline','line1\012line2')'

Mit freundlichen Gruessen,

Peter Maas
 
H

Harald Armin Massa

serializedDict = cPickle.dumps(damnDict)
....
The field where i put the serialized data is a text field.

why don't you use bytea??? it's the field type CREATED for your purpose.

Harald
 
G

Gerardo Herzig -Departamento de Proyectos Especial

I have not idea |o| I will try em out rigth now!!!

Thank you all!

Gerardo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top