Am 06.11.24 um 14:05 schrieb Wasim Devale:
Hi AllI have a table having bytea datatype. Anyone has worked on it how we can see the content as the files are in .csv, .pdf, .bin and .docx format.Can anyone help with this? Any SQL script or python script to view the content?Thanks, Wasim
Hi Wassim,You just have to take the contents of the bytea field, which usually is delivered by the query in pairs of hex digits, and write it to a file, which you then can open. The writing has to take place 8-bit clean, in binary.
In order to write a file, you must provide a file name, so somewhere else you have to get the name from, esp. the file extension.
If you don't have this information, you might use the file command in Linux to determine the type of content. The file command reads the first few bytes of a file and determines the type from the "magic number" found there.
Storing a binary file including its MIME type, just as attachments in mails are, can be easier in handling. The MIME-encoded binary file is text, so you can easily store it to text colums.
Big files belong into the file system though, not into the database as they make the database large and clumsy.
Kind Regards, Holger -- Holger Jakobs, Bergisch Gladbach
Attachment:
OpenPGP_signature
Description: OpenPGP digital signature