Cristóvão Dalla Costa wrote:
> I'm using libpq to interface my program to postgresql, and I need to store
> some binary data (around 30-40 bytes per element). I'm not sure of the best
> way to do so, since blobs seem awkward. How would you do it? How would you
> insert it in a text field?
> Thanks all,
I recommend BYTEA datatype for this. It works in a similar manner to
TEXT, but it is designed for binary data. You will need to escape
certain values on INSERT and unescape on SELECT. See:
for a recent post on this.
Hope this helps,
Note that in 7.2 (in beta now) there is a function in libpq specifically
for escaping BYTEA input strings (PQescapeBytea -- see fe-exec.c):
* PQescapeBytea - converts from binary string to the
* minimal encoding necessary to include the string in an SQL
* INSERT statement with a bytea type column as the target.
* The following transformations are applied
* '\0' == ASCII 0 == \\000
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
unsigned char *
PQescapeBytea(unsigned char *bintext, size_t binlen, size_t *bytealen)
In response to
pgsql-interfaces by date
|Next:||From: Alexaki Sofia||Date: 2001-11-14 13:46:26|
|Subject: how to use ODBC interface (fwd)|
|Previous:||From: Alex Pilosov||Date: 2001-11-14 00:08:49|
|Subject: Re: storing binary data|