Re: Bytea datatype content to view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 06.11.24 um 14:05 schrieb Wasim Devale:
Hi All

I 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


[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux