Re: BYTEA - Mailing list pgsql-general

From Tom Lane
Subject Re: BYTEA
Date
Msg-id 16192.1032533028@sss.pgh.pa.us
Whole thread Raw
In response to BYTEA  ("Timur V. Irmatov" <itvthor@sdf.lonestar.org>)
List pgsql-general
"Timur V. Irmatov" <itvthor@sdf.lonestar.org> writes:
> I'd like to hear background explanation of why strings used as bytea
> literals pass two phases of parsing?

Because there is no other alternative: the parser is not aware when it's
scanning a SQL command whether a string literal will end up being taken
as a BYTEA value or not.

One possibility for inserting BYTEA without quite so much quoting is to
insert via COPY IN instead of INSERT.  This is not a complete solution
however, since you still have to beware of COPY's escaping rules for
newlines and tabs.

If you really don't want to be bothered, you could think about defining
a function
    create function myinsert (..., bytea, ...) as '
    INSERT INTO mytable VALUES($1,$2,...)' language SQL;

and then invoking this function via the "fastpath" interface.  The
fastpath stuff is pretty ugly but it would let you send raw binary
data.

            regards, tom lane

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: timestamp parse error
Next
From: Stephan Szabo
Date:
Subject: Re: missed features and unhappy changes when pg 7.1->7.2