public inbox for [email protected]
help / color / mirror / Atom feedFrom: Holger Jakobs <[email protected]>
To: [email protected]
Subject: Re: Bytea datatype content to view
Date: Wed, 6 Nov 2024 15:09:58 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAB5fag593g9wK+hDdWDqRDUnd-N1XLAFNaGKv37F95LngkvdgQ@mail.gmail.com>
References: <CAB5fag593g9wK+hDdWDqRDUnd-N1XLAFNaGKv37F95LngkvdgQ@mail.gmail.com>
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
Attachments:
[application/pgp-signature] OpenPGP_signature (203B, 2-OpenPGP_signature)
download
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Bytea datatype content to view
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox