Re: Bytea datatype content to view

From: Holger Jakobs <holger(at)jakobs(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Bytea datatype content to view
Date: 2024-11-06 14:09:58
Message-ID: 20aee929-2bd4-3904-8f46-809570b8a900@jakobs.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Alvaro Herrera 2024-11-06 16:03:00 Re: Bytea datatype content to view
Previous Message Steve Cooper 2024-11-06 14:09:09 Re: Bytea datatype content to view