Get Media object (or binary data) from Data Table using psycopg2

Title says it all. Anyone have any experience doing this? I’ve tried a few things, but after running the following as a test query:

SELECT pg_typeof(image) FROM table_987654;

The returned type is text, the values usually being something like '45125', which to my eyes looks like a key or pointer of some type. I know Anvil does a lot of awesome magic for us when it comes to Data Tables, so is this just something that isn’t feasible with psycopg2 yet, or is there a way to use this returned value to find my binary data? I figure that I’ll have to change it to a Media object in python afterwards anyway, so just the binary would be fine.

Also, to clarify, the reason I’m trying to use psycopg2 for this rather than anvil.tables is because, as I understand it, mixing the two can cause issues with transactions. In this particular app, that may not really be a big deal because I’m probably not going to do a whole lot of writing, so this is mostly academic in nature.

Thanks!

EDIT - I’d also be interested in how you might go about writing a file object to a table with psycopg2. I haven’t done any research into this portion of the issue, but I had the thought and wanted to append it here.

Hi @bryndonlee,

Right now, the app_tables.foo methods are the only way to access Media objects in tables. I’ve consequently moved this to Feature Requests!

1 Like

Any news on this topic? I am facing the same problem using the anvil-app-server. We need to backup /access some video data without using the app.

When I connect with whatever client software I cannot find the binary data. Anyway to find them?

I’m not sure of all your constraints, but would backing up via an uplink script work? See this topic for sample code: Backup to SQLite via Uplink

Thanks a lot, I will look into it. What would be create, would be to have access to binary data in the anvil database directly when using a tool link pg_admin …