3

I am working with the script below. If I change the script so I avoid the bytea datatype, I can easily copy data from my postgres table into a python variable.

But if the data is in a bytea postgres column, I encounter a strange object called memory which confuses me.

Here is the script which I run against anaconda python 3.5.2:

# bytea.py

import sqlalchemy

# I should create a conn
db_s = 'postgres://dan:dan@127.0.0.1/dan'
conn = sqlalchemy.create_engine(db_s).connect()

sql_s = "drop table if exists dropme"
conn.execute(sql_s)

sql_s = "create table dropme(c1 bytea)"
conn.execute(sql_s)

sql_s = "insert into dropme(c1)values( cast('hello' AS bytea) );"
conn.execute(sql_s)

sql_s = "select c1 from dropme limit 1"
result = conn.execute(sql_s)
print(result)
# <sqlalchemy.engine.result.ResultProxy object at 0x7fcbccdade80>

for row in result:
    print(row['c1'])

# <memory at 0x7f4c125a6c48>

How to get the data which is inside of memory at 0x7f4c125a6c48 ?

user3676943
  • 913
  • 1
  • 13
  • 27

1 Answers1

2

You can cast it use python bytes()

for row in result:
    print(bytes(row['c1']))
metmirr
  • 4,234
  • 2
  • 21
  • 34