cPickle and pgsql...damn!!

Discussion in 'Python' started by Gerardo Herzig -Departamento de Proyectos Especial, Jul 20, 2004.

  1. 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!
    --
    Gerardo Herzig
    Departamento de Proyectos Especiales e Internet
    Facultad de Medicina
    U.B.A.
    Gerardo Herzig -Departamento de Proyectos Especial, Jul 20, 2004
    #1
    1. Advertising

  2. Gerardo Herzig -Departamento de Proyectos Especial

    Peter Maas Guest

    Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad de Medicina schrieb:
    >>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

    --
    -------------------------------------------------------------------
    Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
    E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
    -------------------------------------------------------------------
    Peter Maas, Jul 21, 2004
    #2
    1. Advertising

  3. > >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
    Harald Armin Massa, Jul 21, 2004
    #3
  4. I have not idea |o| I will try em out rigth now!!!

    Thank you all!

    Gerardo

    > > 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
    Gerardo Herzig -Departamento de Proyectos Especial, Jul 21, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Admin
    Replies:
    0
    Views:
    662
    Admin
    Jul 8, 2003
  2. Lukasz Lacki

    god damn ViewState.

    Lukasz Lacki, Nov 14, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    565
    Lukasz Lacki
    Nov 14, 2003
  3. Lars Netzel

    The damn Enter button and ASP.NET

    Lars Netzel, Aug 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,890
    Grant Merwitz
    Aug 16, 2005
  4. filippo
    Replies:
    6
    Views:
    247
    Lars Haugseth
    Mar 20, 2007
  5. Filippo
    Replies:
    1
    Views:
    108
    Filippo
    Apr 8, 2007
Loading...

Share This Page