Re: bytea

From: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Cc: achong(at)cecid(dot)hku(dot)hk
Subject: Re: bytea
Date: 2003-02-05 10:15:55
Message-ID: 3E40E45A.6D20C6EE@rodos.fzk.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> I have a table containing a field of type bytea:
>
> CREATE TABLE a_table (
> a_field bytea
> );
>
> How can I import a file in a SQL script? What function I can use?
>
The documentation says as in PostgreSQL 7.2.1 (I doubt this changed
significantly since)

Octets of certain values must be escaped (but all octet values may be
escaped) when used as part of a string literal in an SQL
statement. In general, to escape an octet, it is converted into the
three-digit octal number equivalent of its decimal octet value, and
preceded by two backslashes.

In general it goes like this
INSERT INTO a_table ( a_field ) VALUES ( '\\000\\001\\002\\003' ) ;
to load the first four ASCII characters.
You did not mention how your file looks like.
There is also a C function available called PQescapeBytea
which does all the required escaping to store memory areas in bytea
columns.
Refer to Command Execution Functions within libpq - C Library for
details.

Regards, Christoph

Responses

  • Re: bytea at 2003-02-05 10:25:01 from Adrian Chong

Browse pgsql-sql by date

  From Date Subject
Next Message Adrian Chong 2003-02-05 10:25:01 Re: bytea
Previous Message Adrian Chong 2003-02-05 09:55:39 bytea