X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1170E4758DC for ; Wed, 5 Feb 2003 05:22:19 -0500 (EST) Received: from ns.csis.hku.hk (ns.csis.hku.hk [147.8.178.10]) by postgresql.org (Postfix) with ESMTP id 53761474E44 for ; Wed, 5 Feb 2003 05:22:17 -0500 (EST) Received: from intraflow2.csis.hku.hk (intraflow2 [147.8.176.14]) by ns.csis.hku.hk (8.10.1/8.10.1) with SMTP id h15AMHi10053 for ; Wed, 5 Feb 2003 18:22:17 +0800 (HKT) Received: (from achongpc [147.8.177.32]) by intraflow2.csis.hku.hk (NAVGW 2.5.1.13) with SMTP id M2003020518213019278 ; Wed, 05 Feb 2003 18:21:30 +0800 Message-ID: <016d01c2cd00$d7a2a5d0$20b10893@achongpc> From: "Adrian Chong" To: "Christoph Haller" , References: <3E40E45A.6D20C6EE@rodos.fzk.de> Subject: Re: bytea Date: Wed, 5 Feb 2003 18:25:01 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/91 X-Sequence-Number: 11489 Hi Christoph, Thanks for your reply. But what I want to do is loading a file of a particular path with a sql statement in psql. Why I need to care about how the file looks like? Thanks. Adrian ----- Original Message ----- From: "Christoph Haller" To: Cc: Sent: Wednesday, February 05, 2003 6:15 PM Subject: Re: [SQL] bytea > > > > 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 > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >