0

I am working on a base-datatable with a VARBINARY variable. Now I want to read the table via SQLAlchemy into a pandas dataframe. Going the usual way

df = pandas.read_sql_query("select key from xxx", engine)

I get an uninterpretable memoryview as data type. I can convert this via lambda function

df.key.apply(lambda x: x.tobytes().hex())

into the desired readable format. But I would like to know if the casting can also be placed directly into the pandas.read_sql_query()-statement:

  • via numpy dtypes or maybe

  • directly into the SQL-query

Many greetings and best thanks

  • SELECT CONVERT(varchar(5000), yourvarbincolumn, 0) seemed to do the trick within MS-SQL Server. I am guessing call native SQL within SQLAlchemy.. will investigate further. See here: https://stackoverflow.com/questions/3289988/varbinary-to-string-on-sql-server https://www.geeksforgeeks.org/how-to-execute-raw-sql-in-sqlalchemy/ – JGFMK Jul 27 '23 at 13:27

0 Answers0