Skip to content

Instantly share code, notes, and snippets.

@davestgermain
Last active May 11, 2017 19:43
Show Gist options
  • Save davestgermain/7eae5c1b148a1e0dfa09d3818fdd1cfb to your computer and use it in GitHub Desktop.
Save davestgermain/7eae5c1b148a1e0dfa09d3818fdd1cfb to your computer and use it in GitHub Desktop.
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