dbTalk Databases Forums  

[NOVICE] Need help importing dump with bytea into db

mailing.database.pgsql-novice mailing.database.pgsql-novice


Discuss [NOVICE] Need help importing dump with bytea into db in the mailing.database.pgsql-novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Philippe Dirkse
 
Posts: n/a

Default [NOVICE] Need help importing dump with bytea into db - 08-13-2012 , 02:56 AM






Hi,

I have the strangest problem. Scenario: Server running postgresql 8.4.10, 32-bit Ubuntu, local machine running postgresql 9.1.4, 64-bit OSX Snow Leopard. I want to create a local copy of the database running on the server for development purposes, as the server database is 'live'.

So, on my Mac I use pg_dump to create a dump from the server database. This database contains one table that has a bytea column which stores pictures (png,jpg). Examining the dump, I see this data is 'escaped' as octects for all 'non-readable' characters. Now, when I use psql (or pg_restore for that matter) to import the dump into my local database, the bytea data is not 'unescaped' properly. It appears as if the characters for the string representation of the actual bytes are returned.

To clarify, suppose the server contained the bytea 'AB BC 10'hex, then my query from the local db will return '4142 4243 3130'hex, so basically what I must do is convert the bytes to their ASCII values, group them by 2 and convert that string back to the actual byte value (41=A, 42=B, so together I again have 'AB').

I noticed that if I try and restore the dump into a new database on the server this issue does not occur. I tried dumping as plain text, custom format, I tried using inserts instead of copy, I tried psql and pg_restore but it all failed.

What am I missing or doing wrong? Any help will be greatly appreciated!

Met vriendelijke groeten,

Ir. Philippe Dirkse

Project Manager Alten PTS Development Center
Tel: +31-(0)40-2563080
Mob: +31-(0)6-23401846

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [NOVICE] Need help importing dump with bytea into db - 08-13-2012 , 09:23 AM






Philippe Dirkse <philippe.dirkse (AT) alten (DOT) nl> writes:
Quote:
I have the strangest problem. Scenario: Server running postgresql 8.4.10, 32-bit Ubuntu, local machine running postgresql 9.1.4, 64-bit OSX Snow Leopard. I want to create a local copy of the database running on the server for development purposes, as the server database is 'live'.

So, on my Mac I use pg_dump to create a dump from the server database. This database contains one table that has a bytea column which stores pictures (png,jpg). Examining the dump, I see this data is 'escaped' as octects for all 'non-readable' characters. Now, when I use psql (or pg_restore for that matter) to import the dump into my local database, the bytea data is not 'unescaped' properly. It appears as if the characters for the string representation of the actual bytes are returned.
My first guess is that there's nothing actually wrong with the data, but
you're getting confused by the fact that 9.1 by default outputs bytea
data in hex rather than the traditional "escaped" format. See the
bytea_output configuration parameter.

regards, tom lane


--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.