Re: quoting psql varible as identifier - Mailing list pgsql-hackers

From Robert Haas
Subject Re: quoting psql varible as identifier
Date
Msg-id 603c8f071001191325m29d8ac08k3fd38e3a5540d3d0@mail.gmail.com
Whole thread Raw
In response to Re: quoting psql varible as identifier  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: quoting psql varible as identifier  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Jan 19, 2010 at 3:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> It seems to me that it might be
>> sensible to do it this way:
>
>> 1. Do a locale-aware scan of the input string and count the number of
>> characters we need to escape (num_to_escape).
>> 2. If num_to_escape is 0, fast path: allocate len+3 bytes and use
>> memcpy to copy the input data to the output buffer.
>> 3. Otherwise, allocate len+num_to_escape+5 bytes
>> (space-E-quote-quote-NUL) and do a second locale-aware scan of the
>> input string, copying and escaping as we go (or do you only want the
>> space-E if the escapable character that we find is \ rather than '?).
>
> Yeah, the fast path if no escaping is needed seems attractive.

Cool.

> I think that E should only be inserted if we have a backslash to deal
> with; no reason to generate nonstandard syntax if we don't have to.
> That would mean keeping two bits of state (escaping-needed and
> malloc-size) from the initial pass, but that's pretty cheap.

That's fine.

I'd like to proceed by committing an initial patch which changes the
"Escaping Strings for Inclusion in SQL Commands" to use a
<variablelist> with one <varlistentry> per function (as we do in
surrounding functions) and consolidates it with the following section,"Escaping Binary Strings for Inclusion in SQL
Commands". Then I'll
 
submit a patch implementing pqEscapeLiteral() and pqEscapeIdentifier()
as discussed here, and the doc diff hunks will actually be readable.

Objections?  If so, please state how you'd like to see the docs
organized because I don't see another way to do it that makes any
sense.

...Robert


pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: MySQL-ism help patch for psql
Next
From: Markus Wanner
Date:
Subject: Re: Testing with concurrent sessions