Home > database >  Postgres export bytea data error
Postgres export bytea data error

Time:10-05

, such an experiment will be deposited in the postgres images, but found the export data was memory address,,, try to other integer, character are normal, the following code:

Deposited in the code, forget to say the environment is python, Windows

 
If __name__=="__main__" :
Conn=psycopg2. Connect (database="test", is omitted)
Cur=conn. Cursor ()
Query_sql="select binarydump from bindump limit 1"
Img_buffer=None
With the open (" code files/b1. JPG ", 'rb') as reader:
Img_buffer=reader. The read ()
Insert_sql="update student2 set picture=(% s) where id=1"
Params=(psycopg2 Binary (img_buffer))
Cur. Execute (insert_sql, params)
Conn.com MIT ()


Export code
 
Conn=psycopg2. Connect (database="test", is omitted)
Cur=conn. Cursor ()
Cur. Execute (" select PIC from student2 where id=1 ")
Blob=cur. Fetchone ()
Print (blob)
Open (' code files/post. JPG ', 'wb), write (blob)
Cur. Close ()


Results:
Traceback (the most recent call last) :
The File "notebooks \ test. Py, line 79, in & lt; module>
Open (' code files/post. JPG ', 'wb), write (blob)
TypeError: a bytes - like the object is required, not 'a tuple

Strange strange,,

After import bytea data is the
\ 377\330\377\340\000\020 jfif \ 000\001\001\000\000\001\000\001\000\000\377\333\000 c \ 000\010\006\006\007\006\005\010\007\007\007\011\011\010\012\014\024\015\014\013\013\014\031\022\023\017\024\035\032\037\036\035\032\034\034 $. '", # \ 034\034 (7), 01444\037' 9=82 & lt; 342\377\300\000\013\010\000 o \ 001\032\001\001\021\000\377\304\000\037\000\000\001\005\001\001\001\001\001\001\000\000\000\000\000\000\000\000\001\002\003\004\005\006\007\010\011\012\013\377\304\000\265\020\000\002\001\003\003\002\004\003\005\005\004\004\000\000\001} \ 001\002\003\000\004\021\005\022! 1 a qa \ 007\006\023 "q \ 0242\201\221\241\010\261\301\025 # B $3 br \ r \ 321\360\202\011\012\026\030\031\027 032% & amp; '(* 456789) : CDEFGHIJSTUVWXYZcdefghijstuvwxyz \ 203\204\205\206\207\210\211\212\222\223\224\225\226\227\230\231\232\242\243\244\245\246\247\250\251\252\262\263\264\265\266\267\270\271\272\302\303\304\305\306\307\310\311\312\322\323\324\325\326\327\330\331\332\341\342\343\344\345\346\347\350\351\352\361\362\363\364\365\366\367\370\371\372\377\332\000\010\001\001\000\000? \ 000\367\372\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\212\242\212 (\ 242\271\377\000\030\370\272\317\301: \ 037\366\275\375\235\365\315\250\225 b \ 177\261\304\034\307\2738\313\000\027 \ f (\ 357 \ \ 014\347\253\034\037\264 w \ 203\270\212 'f \ ` Gp 264\326\255\226\361\336\225 @ "O. D '\ 003\257\000\327\237 @ k (\ 254\277\021\353\366 & gt; \ 026\360\375\346\265\2514\202\322\325\003? \ 226\273\231\211! U @ \ 365, @ h \ 347\003\236\034\327\231\377\000\303 gx? \ 376\201\272\347\375\370\207\377\000\216\327\024\024\260 qe qe qe \ 025\301\370\317\342\347 \ | 206\021\252 & amp; 231 ~ n \ 356\257\012\222 + $W0 o \ \ 203\215\273\3672\200 h9 \ n 003\223\216\001\031\347\340\375\242\274\0335\304 q=\ 246\263\002; 205 id \ \ 267\214\252\002\361\333! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related