简体   繁体   中英

How to use LO datatype with postgresql?

What I'm currently trying to do:

I am using a software with Postgresql as the backend DB. The software supplies an API that uses a web service to communicate with the software/DB. I am trying to insert an image to the database through the api, which normally should be a BLOB, since postgresql doesn't support that, I created the lo extension with the postgresql-contrib package. Now, that the actual large objects are kept in it's own table, and the current table just keeps a reference to that object, however the API does not account for this. I currently have the datatype for the image column as a BYTEA, but I get an error saying "Column 'img' is of type bytea but expression is of type lo;". There is not much I can do within the API since the insertion is encapsulated in the backend of the webservice. Is there something I can do in Postgres itself to allow the api to insert large objects?

TL;DR:

Software API expects to put in large object (BLOB) to DB. Should work seamlessly if the DB recognizes the BLOB datatype. I've set up the lo extension in postgres. Currently I set the column datatype to bytea but get this error: "Column 'img' is of type bytea but expression is of type lo;".

How do I store lo's?

:::I'm using postgresql 9.1


I got it working. After dropping the tables, I forgot to re-create the lo extension, which is why it wasn't recognizing the datatype.

The easyes (but not the most eficient) way to transfer files to db is to encode files into HEX or base64 transfer them as varchar and decode into bytea type before storing into bytea field.

Same way you retrive files from db.

If you want to transfer bytea without encode/decode owerhead - then you have to study how you driver, language and framework can handle it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM