Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to export image file from postgresql database. In database, users_data_circulation table has photo (bytea) column. My command;

copy (select encode(photo,'hex') from users_data_circulation limit 1) TO '/tmp/imagetest.hext';

in operation system

$> xxd -p -r /tmp/imagetest.hex > /tmp/imagetest.jpg
$> file /tmp/imagetest.jpg
/tmp/imagetest.jpg: ASCII TEXT

I can't open jpg file. How can i convert this file to jpg?

EDIT

devinim@devinimpostgresql:~$ hexdump -C /tmp/image.hex | more
00000000  5c 5c 33 37 37 5c 5c 33  33 30 5c 5c 33 37 37 5c  |\\377\\330\\377\|
00000010  5c 33 34 30 5c 5c 30 30  30 10 4a 46 49 46 5c 5c  |\340\\000.JFIF\\|
00000020  30 30 30 01 02 5c 5c 30  30 30 5c 5c 30 30 30 01  |000..\\000\\000.|
00000030  5c 5c 30 30 30 01 5c 5c  30 30 30 5c 5c 30 30 30  |\\000.\\000\\000|
00000040  5c 5c 33 37 37 5c 5c 33  34 31 5c 5c 30 30 30 5c  |\\377\\341\\000\|
00000050  76 50 49 43 5c 5c 30 30  30 02 5c 6e 5c 6e 01 5c  |vPIC\\000.\n\n.\|
00000060  5c 30 30 30 5c 5c 33 37  37 5c 5c 33 37 36 5c 5c  |\000\\377\\376\\|
00000070  30 30 30 21 50 69 63 74  75 72 65 20 45 6c 65 6d  |000!Picture Elem|
00000080  65 6e 74 73 2c 20 49 6e  63 2e 20 49 53 45 2f 53  |ents, Inc. ISE/S|
... continues like that
share|improve this question
1  
This works for me. If you open the resulting in a text editor, what do you see? Or can you run it through hexdump -C and show the first few lines in the question? – Daniel Vérité Oct 1 at 12:33
    
I edited question – AhmetMelihBaşbuğ Oct 3 at 7:06
    
The content looks like it was generated by encode(photo,'escape') rather than encode(photo,'hex'). – Daniel Vérité Oct 3 at 12:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.