Last active
May 11, 2017 19:43
-
-
Save davestgermain/7eae5c1b148a1e0dfa09d3818fdd1cfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
create_table = ''' | |
create table if not exists test_bt ( | |
v BYTEA | |
);''' | |
binary = b'\xff\xd8\xff\xe0\x00\x10' | |
conn = psycopg2.connect('postgresql://root@localhost:26257/test?sslmode=disable') | |
with conn as conn, conn.cursor() as c: | |
c.execute(create_table) | |
c.execute('insert into test_bt (v) values (%s)', (binary, )) | |
c.execute('select * from test_bt') | |
rv, = c.fetchone() | |
rv = bytes(rv) | |
print('got', repr(rv), 'expected', repr(binary)) | |
c.execute('drop table test_bt') | |
assert rv == binary | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment