Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 11:23 PM
Bruce Momjian
 
Posts: n/a
Default Re: [HACKERS] patches for items from TODO list

Here is an updated version of the COPY \x patch. It is the first patch
attached.

Also, I realized that if we support \x in COPY, we should also support
\x in strings to the backend. This is the second patch.

Third, I found out that psql has some unusual handling of escaped
numbers. Instead of using \ddd as octal, it has \ddd is decimal, \0ddd
is octal, and \0xddd is decimal. It is basically following the strtol()
rules for an escaped value. This seems confusing and contradicts how
the rest of our system works. I looked at 'bash' and found that it
supports the \000 and \x00 just like C, so I am confused why we have
the current behavior. This patch makes psql consistent with the rest of
our system for back slashes. It does break backward compatibility. It
wouldn't be a big deal to fix, except we document this in the psql
manual page, and that adds confusion.

FYI, here is the current psql behavior:

test=> \set x '\42'
test=> \echo :x
*
test=> \set x '\042'
test=> \echo :x
"
test=> \set x '\0x42'
test=> \echo :x
B

The new behavior is:

test=> \set x '\42'
test=> \echo :x
"
test=> \set x '\042'
test=> \echo :x
"
test=> \set x '\x42'
test=> \echo :x
B

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Index: doc/src/sgml/ref/copy.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v
retrieving revision 1.65
diff -c -c -r1.65 copy.sgml
*** doc/src/sgml/ref/copy.sgml 7 May 2005 02:22:45 -0000 1.65
--- doc/src/sgml/ref/copy.sgml 28 May 2005 14:02:59 -0000
***************
*** 424,436 ****
<entry>Backslash followed by one to three octal digits specifies
the character with that numeric code</entry>
</row>
</tbody>
</tgroup>
</informaltable>

! Presently, <command>COPY TO</command> will never emit an octal-digits
! backslash sequence, but it does use the other sequences listed above
! for those control characters.
</para>

<para>
--- 424,441 ----
<entry>Backslash followed by one to three octal digits specifies
the character with that numeric code</entry>
</row>
+ <row>
+ <entry><literal>\x</><replaceable>digits</></entry>
+ <entry>Backslash <literal>x</> followed by one or two hex digits specifies
+ the character with that numeric code</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>

! Presently, <command>COPY TO</command> will never emit an octal or
! hex-digits backslash sequence, but it does use the other sequences
! listed above for those control characters.
</para>

<para>
Index: src/backend/commands/copy.c
================================================== =================
RCS file: /cvsroot/pgsql/src/backend/commands/copy.c,v
retrieving revision 1.244
diff -c -c -r1.244 copy.c
*** src/backend/commands/copy.c 7 May 2005 02:22:46 -0000 1.244
--- src/backend/commands/copy.c 28 May 2005 14:03:07 -0000
***************
*** 2274,2279 ****
--- 2274,2291 ----
return result;
}

+ /*
+ * Return decimal value for a hexadecimal digit
+ */
+ static
+ int GetDecimalFromHex(char hex)
+ {
+ if (isdigit(hex))
+ return hex - '0';
+ else
+ return tolower(hex) - 'a' + 10;
+ }
+
/*----------
* Read the value of a single attribute, performing de-escaping as needed.
*
***************
*** 2335,2340 ****
--- 2347,2353 ----
case '5':
case '6':
case '7':
+ /* handle \013 */
{
int val;

***************
*** 2360,2365 ****
--- 2373,2402 ----
c = val & 0377;
}
break;
+ case 'x':
+ /* Handle \x3F */
+ if (line_buf.cursor < line_buf.len)
+ {
+ char hexchar = line_buf.data[line_buf.cursor];
+
+ if (isxdigit(hexchar))
+ {
+ int val = GetDecimalFromHex(hexchar);
+
+ line_buf.cursor++;
+ if (line_buf.cursor < line_buf.len)
+ {
+ hexchar = line_buf.data[line_buf.cursor];
+ if (isxdigit(hexchar))
+ {
+ line_buf.cursor++;
+ val = (val << 4) + GetDecimalFromHex(hexchar);
+ }
+ }
+ c = val & 0xff;
+ }
+ }
+ break;
case 'b':
c = '\b';
break;


Index: doc/src/sgml/datatype.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v
retrieving revision 1.157
diff -c -c -r1.157 datatype.sgml
*** doc/src/sgml/datatype.sgml 1 May 2005 15:54:46 -0000 1.157
--- doc/src/sgml/datatype.sgml 28 May 2005 14:02:40 -0000
***************
*** 1118,1124 ****
<para>
When entering <type>bytea</type> values, octets of certain values
<emphasis>must</emphasis> be escaped (but all octet values
! <emphasis>may</emphasis> be escaped) when used as part of a string
literal in an <acronym>SQL</acronym> 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
--- 1118,1124 ----
<para>
When entering <type>bytea</type> values, octets of certain values
<emphasis>must</emphasis> be escaped (but all octet values
! <emphasis>can</emphasis> be escaped) when used as part of a string
literal in an <acronym>SQL</acronym> 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
Index: doc/src/sgml/libpq.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v
retrieving revision 1.180
diff -c -c -r1.180 libpq.sgml
*** doc/src/sgml/libpq.sgml 26 Feb 2005 18:39:04 -0000 1.180
--- doc/src/sgml/libpq.sgml 28 May 2005 14:02:46 -0000
***************
*** 2229,2235 ****

<para>
Certain byte values <emphasis>must</emphasis> be escaped (but all
! byte values <emphasis>may</emphasis> be escaped) when used as part
of a <type>bytea</type> literal in an <acronym>SQL</acronym>
statement. In general, to escape a byte, it is converted into the
three digit octal number equal to the octet value, and preceded by
--- 2229,2235 ----

<para>
Certain byte values <emphasis>must</emphasis> be escaped (but all
! byte values <emphasis>can</emphasis> be escaped) when used as part
of a <type>bytea</type> literal in an <acronym>SQL</acronym>
statement. In general, to escape a byte, it is converted into the
three digit octal number equal to the octet value, and preceded by
Index: doc/src/sgml/syntax.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v
retrieving revision 1.99
diff -c -c -r1.99 syntax.sgml
*** doc/src/sgml/syntax.sgml 23 Dec 2004 05:37:40 -0000 1.99
--- doc/src/sgml/syntax.sgml 28 May 2005 14:02:58 -0000
***************
*** 254,270 ****

<para>
Another <productname>PostgreSQL</productname> extension is that
! C-style backslash escapes are available:
! <literal>\b</literal> is a backspace, <literal>\f</literal> is a
! form feed, <literal>\n</literal> is a newline,
! <literal>\r</literal> is a carriage return, <literal>\t</literal>
! is a tab, and <literal>\<replaceable>xxx</replaceable></literal>,
! where <replaceable>xxx</replaceable> is an octal number, is a
! byte with the corresponding code. (It is your responsibility
! that the byte sequences you create are valid characters in the
! server character set encoding.) Any other character following a
! backslash is taken literally. Thus, to include a backslash in a
! string constant, write two backslashes.
</para>

<para>
--- 254,271 ----

<para>
Another <productname>PostgreSQL</productname> extension is that
! C-style backslash escapes are available: <literal>\b</literal> is a
! backspace, <literal>\f</literal> is a form feed,
! <literal>\n</literal> is a newline, <literal>\r</literal> is a
! carriage return, <literal>\t</literal> is a tab. Also supported is
! <literal>\<replaceable>digits</replaceable></literal>, where
! <replaceable>ddd</replaceable> represents an octal byte value, and
! <literal>\x<replaceable>hexdigits</replaceable></literal>, where
! <replaceable>hexdigits</replaceable> represents a hexadecimal byte value.
! (It is your responsibility that the byte sequences you create are
! valid characters in the server character set encoding.) Any other
! character following a backslash is taken literally. Thus, to
! include a backslash in a string constant, write two backslashes.
</para>

<para>
Index: src/backend/parser/scan.l
================================================== =================
RCS file: /cvsroot/pgsql/src/backend/parser/scan.l,v
retrieving revision 1.122
diff -c -c -r1.122 scan.l
*** src/backend/parser/scan.l 26 May 2005 01:24:29 -0000 1.122
--- src/backend/parser/scan.l 28 May 2005 14:03:10 -0000
***************
*** 193,200 ****
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7]
xqoctesc [\\][0-7]{1,3}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
--- 193,201 ----
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7x]
xqoctesc [\\][0-7]{1,3}
+ xqhexesc [\\]x[0-9A-Fa-f]{1,2}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
***************
*** 435,440 ****
--- 436,445 ----
unsigned char c = strtoul(yytext+1, NULL, 8);
addlitchar(c);
}
+ <xq>{xqhexesc} {
+ unsigned char c = strtoul(yytext+2, NULL, 16);
+ addlitchar(c);
+ }
<xq>{quotecontinue} {
/* ignore */
}

Index: doc/src/sgml/ref/psql-ref.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.135
diff -c -c -r1.135 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml 28 Apr 2005 13:09:59 -0000 1.135
--- doc/src/sgml/ref/psql-ref.sgml 28 May 2005 16:23:01 -0000
***************
*** 590,599 ****
precede it by a backslash. Anything contained in single quotes is
furthermore subject to C-like substitutions for
<literal>\n</literal> (new line), <literal>\t</literal> (tab),
! <literal>\</literal><replaceable>digits</replaceable>,
! <literal>\0</literal><replaceable>digits</replaceable>, and
! <literal>\0x</literal><replaceable>digits</replaceable> (the
! character with the given decimal, octal, or hexadecimal code).
</para>

<para>
--- 590,598 ----
precede it by a backslash. Anything contained in single quotes is
furthermore subject to C-like substitutions for
<literal>\n</literal> (new line), <literal>\t</literal> (tab),
! <literal>\</literal><replaceable>digits</replaceable>, and
! <literal>\x</literal><replaceable>digits</replaceable> (the
! character with the given octal or hexadecimal code).
</para>

<para>
Index: src/bin/psql/psqlscan.l
================================================== =================
RCS file: /cvsroot/pgsql/src/bin/psql/psqlscan.l,v
retrieving revision 1.10
diff -c -c -r1.10 psqlscan.l
*** src/bin/psql/psqlscan.l 26 May 2005 01:24:29 -0000 1.10
--- src/bin/psql/psqlscan.l 28 May 2005 16:23:10 -0000
***************
*** 849,877 ****
"\\r" { appendPQExpBufferChar(output_buf, '\r'); }
"\\f" { appendPQExpBufferChar(output_buf, '\f'); }

! "\\"[1-9][0-9]* {
! /* decimal case */
! appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
! }
!
! "\\"0[0-7]* {
/* octal case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
}

! "\\"0[xX][0-9A-Fa-f]+ {
/* hex case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
! }
!
! "\\"0[xX] {
! /* failed hex case */
! yyless(2);
! appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
}

"\\". { emit(yytext + 1, 1); }
--- 849,864 ----
"\\r" { appendPQExpBufferChar(output_buf, '\r'); }
"\\f" { appendPQExpBufferChar(output_buf, '\f'); }

! "\\"[0-7]{1,3} {
/* octal case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 8));
}

! "\\"x[0-9A-Fa-f]{1,2} {
/* hex case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 2, NULL, 16));
}

"\\". { emit(yytext + 1, 1); }


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 11:23 PM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] patches for items from TODO list

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Here is an updated version of the COPY \x patch. It is the first patch
> attached.
> Also, I realized that if we support \x in COPY, we should also support
> \x in strings to the backend. This is the second patch.


Do we really want to do any of these things? We've been getting beaten
up recently about the fact that we have non-SQL-spec string escapes
(ie, all the backslash stuff) so I'm a bit dubious about adding more,
especially when there's little if any demand for it.

I don't object too much to the COPY addition, since that's outside any
spec anyway, but I do think we ought to think twice about adding this
to SQL literal handling.

> Third, I found out that psql has some unusual handling of escaped
> numbers. Instead of using \ddd as octal, it has \ddd is decimal, \0ddd
> is octal, and \0xddd is decimal. It is basically following the strtol()
> rules for an escaped value. This seems confusing and contradicts how
> the rest of our system works.


I agree, that's just going to confuse people.

> ! xqescape [\\][^0-7x]


If you are going to insist on this, at least make it case-insensitive.

regards, tom lane

---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 11:23 PM
Michael Paesold
 
Posts: n/a
Default Re: [HACKERS] patches for items from TODO list



Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
>
>>Here is an updated version of the COPY \x patch. It is the first patch
>>attached.
>>Also, I realized that if we support \x in COPY, we should also support
>>\x in strings to the backend. This is the second patch.

>
>
> Do we really want to do any of these things? We've been getting beaten
> up recently about the fact that we have non-SQL-spec string escapes
> (ie, all the backslash stuff) so I'm a bit dubious about adding more,
> especially when there's little if any demand for it.
>
> I don't object too much to the COPY addition, since that's outside any
> spec anyway, but I do think we ought to think twice about adding this
> to SQL literal handling.


+1 from me on this for Tom -- please don't break spec compliance!

Best Regards,
Michael Paesold


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 11:23 PM
Bruce Momjian
 
Posts: n/a
Default Re: [HACKERS] patches for items from TODO list

Tom Lane wrote:
> > Third, I found out that psql has some unusual handling of escaped
> > numbers. Instead of using \ddd as octal, it has \ddd is decimal, \0ddd
> > is octal, and \0xddd is decimal. It is basically following the strtol()
> > rules for an escaped value. This seems confusing and contradicts how
> > the rest of our system works.

>
> I agree, that's just going to confuse people.


Fixed and applied, with no hex addition.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Index: src/bin/psql/psqlscan.l
================================================== =================
RCS file: /cvsroot/pgsql/src/bin/psql/psqlscan.l,v
retrieving revision 1.10
diff -c -c -r1.10 psqlscan.l
*** src/bin/psql/psqlscan.l 26 May 2005 01:24:29 -0000 1.10
--- src/bin/psql/psqlscan.l 30 May 2005 14:35:43 -0000
***************
*** 849,877 ****
"\\r" { appendPQExpBufferChar(output_buf, '\r'); }
"\\f" { appendPQExpBufferChar(output_buf, '\f'); }

! "\\"[1-9][0-9]* {
! /* decimal case */
! appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
! }
!
! "\\"0[0-7]* {
/* octal case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
! }
!
! "\\"0[xX][0-9A-Fa-f]+ {
! /* hex case */
! appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
! }
!
! "\\"0[xX] {
! /* failed hex case */
! yyless(2);
! appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 0));
}

"\\". { emit(yytext + 1, 1); }
--- 849,858 ----
"\\r" { appendPQExpBufferChar(output_buf, '\r'); }
"\\f" { appendPQExpBufferChar(output_buf, '\f'); }

! "\\"[0-7]{1,3} {
/* octal case */
appendPQExpBufferChar(output_buf,
! (char) strtol(yytext + 1, NULL, 8));
}

"\\". { emit(yytext + 1, 1); }


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 11:23 PM
Bruce Momjian
 
Posts: n/a
Default Adding \x escape processing to COPY, psql, backend

Bruce Momjian wrote:
> Here is an updated version of the COPY \x patch. It is the first patch
> attached.
>
> Also, I realized that if we support \x in COPY, we should also support
> \x in strings to the backend. This is the second patch.


Here is a new version of the three \x hex support patches. I have added
\x for psql variables, which is the last patch.

I have IM'ed with Peter and he is now OK with the idea of supporting \x,
with the underestanding that it doesn't take us any farther away from
compatibility than we are now.

I have already fixed the psql octal/decimal/hex behavior in another
patch.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Index: doc/src/sgml/ref/copy.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v
retrieving revision 1.65
diff -c -c -r1.65 copy.sgml
*** doc/src/sgml/ref/copy.sgml 7 May 2005 02:22:45 -0000 1.65
--- doc/src/sgml/ref/copy.sgml 28 May 2005 14:02:59 -0000
***************
*** 424,436 ****
<entry>Backslash followed by one to three octal digits specifies
the character with that numeric code</entry>
</row>
</tbody>
</tgroup>
</informaltable>

! Presently, <command>COPY TO</command> will never emit an octal-digits
! backslash sequence, but it does use the other sequences listed above
! for those control characters.
</para>

<para>
--- 424,441 ----
<entry>Backslash followed by one to three octal digits specifies
the character with that numeric code</entry>
</row>
+ <row>
+ <entry><literal>\x</><replaceable>digits</></entry>
+ <entry>Backslash <literal>x</> followed by one or two hex digits specifies
+ the character with that numeric code</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>

! Presently, <command>COPY TO</command> will never emit an octal or
! hex-digits backslash sequence, but it does use the other sequences
! listed above for those control characters.
</para>

<para>
Index: src/backend/commands/copy.c
================================================== =================
RCS file: /cvsroot/pgsql/src/backend/commands/copy.c,v
retrieving revision 1.244
diff -c -c -r1.244 copy.c
*** src/backend/commands/copy.c 7 May 2005 02:22:46 -0000 1.244
--- src/backend/commands/copy.c 28 May 2005 14:03:07 -0000
***************
*** 2274,2279 ****
--- 2274,2291 ----
return result;
}

+ /*
+ * Return decimal value for a hexadecimal digit
+ */
+ static
+ int GetDecimalFromHex(char hex)
+ {
+ if (isdigit(hex))
+ return hex - '0';
+ else
+ return tolower(hex) - 'a' + 10;
+ }
+
/*----------
* Read the value of a single attribute, performing de-escaping as needed.
*
***************
*** 2335,2340 ****
--- 2347,2353 ----
case '5':
case '6':
case '7':
+ /* handle \013 */
{
int val;

***************
*** 2360,2365 ****
--- 2373,2402 ----
c = val & 0377;
}
break;
+ case 'x':
+ /* Handle \x3F */
+ if (line_buf.cursor < line_buf.len)
+ {
+ char hexchar = line_buf.data[line_buf.cursor];
+
+ if (isxdigit(hexchar))
+ {
+ int val = GetDecimalFromHex(hexchar);
+
+ line_buf.cursor++;
+ if (line_buf.cursor < line_buf.len)
+ {
+ hexchar = line_buf.data[line_buf.cursor];
+ if (isxdigit(hexchar))
+ {
+ line_buf.cursor++;
+ val = (val << 4) + GetDecimalFromHex(hexchar);
+ }
+ }
+ c = val & 0xff;
+ }
+ }
+ break;
case 'b':
c = '\b';
break;


Index: doc/src/sgml/syntax.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v
retrieving revision 1.99
diff -c -c -r1.99 syntax.sgml
*** doc/src/sgml/syntax.sgml 23 Dec 2004 05:37:40 -0000 1.99
--- doc/src/sgml/syntax.sgml 28 May 2005 14:02:58 -0000
***************
*** 254,270 ****

<para>
Another <productname>PostgreSQL</productname> extension is that
! C-style backslash escapes are available:
! <literal>\b</literal> is a backspace, <literal>\f</literal> is a
! form feed, <literal>\n</literal> is a newline,
! <literal>\r</literal> is a carriage return, <literal>\t</literal>
! is a tab, and <literal>\<replaceable>xxx</replaceable></literal>,
! where <replaceable>xxx</replaceable> is an octal number, is a
! byte with the corresponding code. (It is your responsibility
! that the byte sequences you create are valid characters in the
! server character set encoding.) Any other character following a
! backslash is taken literally. Thus, to include a backslash in a
! string constant, write two backslashes.
</para>

<para>
--- 254,271 ----

<para>
Another <productname>PostgreSQL</productname> extension is that
! C-style backslash escapes are available: <literal>\b</literal> is a
! backspace, <literal>\f</literal> is a form feed,
! <literal>\n</literal> is a newline, <literal>\r</literal> is a
! carriage return, <literal>\t</literal> is a tab. Also supported is
! <literal>\<replaceable>digits</replaceable></literal>, where
! <replaceable>ddd</replaceable> represents an octal byte value, and
! <literal>\x<replaceable>hexdigits</replaceable></literal>, where
! <replaceable>hexdigits</replaceable> represents a hexadecimal byte value.
! (It is your responsibility that the byte sequences you create are
! valid characters in the server character set encoding.) Any other
! character following a backslash is taken literally. Thus, to
! include a backslash in a string constant, write two backslashes.
</para>

<para>
Index: src/backend/parser/scan.l
================================================== =================
RCS file: /cvsroot/pgsql/src/backend/parser/scan.l,v
retrieving revision 1.122
diff -c -c -r1.122 scan.l
*** src/backend/parser/scan.l 26 May 2005 01:24:29 -0000 1.122
--- src/backend/parser/scan.l 28 May 2005 14:03:10 -0000
***************
*** 193,200 ****
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7]
xqoctesc [\\][0-7]{1,3}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
--- 193,201 ----
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7x]
xqoctesc [\\][0-7]{1,3}
+ xqhexesc [\\]x[0-9A-Fa-f]{1,2}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
***************
*** 435,440 ****
--- 436,445 ----
unsigned char c = strtoul(yytext+1, NULL, 8);
addlitchar(c);
}
+ <xq>{xqhexesc} {
+ unsigned char c = strtoul(yytext+2, NULL, 16);
+ addlitchar(c);
+ }
<xq>{quotecontinue} {
/* ignore */
}

Index: doc/src/sgml/ref/psql-ref.sgml
================================================== =================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.137
diff -c -c -r1.137 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml 30 May 2005 15:24:23 -0000 1.137
--- doc/src/sgml/ref/psql-ref.sgml 30 May 2005 19:07:20 -0000
***************
*** 589,596 ****
single quote. To include a single quote into such an argument,
precede it by a backslash. Anything contained in single quotes is
furthermore subject to C-like substitutions for
! <literal>\n</literal> (new line), <literal>\t</literal> (tab), and
! <literal>\</literal><replaceable>digits</replaceable> (octal).
</para>

<para>
--- 589,597 ----
single quote. To include a single quote into such an argument,
precede it by a backslash. Anything contained in single quotes is
furthermore subject to C-like substitutions for
! <literal>\n</literal> (new line), <literal>\t</literal> (tab),
! <literal>\</literal><replaceable>digits</replaceable> (octal),
! <literal>\x</literal><replaceable>digits</replaceable> (hexadecimal).
</para>

<para>
Index: src/bin/psql/psqlscan.l
================================================== =================
RCS file: /cvsroot/pgsql/src/bin/psql/psqlscan.l,v
retrieving revision 1.12
diff -c -c -r1.12 psqlscan.l
*** src/bin/psql/psqlscan.l 30 May 2005 16:48:47 -0000 1.12
--- src/bin/psql/psqlscan.l 30 May 2005 19:07:25 -0000
***************
*** 250,257 ****
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7]
xqoctesc [\\][0-7]{1,3}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
--- 250,258 ----
xqstart {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
! xqescape [\\][^0-7x]
xqoctesc [\\][0-7]{1,3}
+ xqhexesc [\\]x[0-9A-Fa-f]{1,2}

/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
***************
*** 467,472 ****
--- 468,476 ----
<xq>{xqoctesc} {
ECHO;
}
+ <xq>{xqhexesc} {
+ ECHO;
+ }
<xq>{quotecontinue} {
ECHO;
}
***************
*** 855,860 ****
--- 859,870 ----
(char) strtol(yytext + 1, NULL, 8));
}

+ {xqhexesc} {
+ /* hex case */
+ appendPQExpBufferChar(output_buf,
+ (char) strtol(yytext + 2, NULL, 16));
+ }
+
"\\". { emit(yytext + 1, 1); }

{other}|\n { ECHO; }


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 11:23 PM
Tom Lane
 
Posts: n/a
Default Re: Adding \x escape processing to COPY, psql, backend

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Here is a new version of the three \x hex support patches. I have added
> \x for psql variables, which is the last patch.


> I have IM'ed with Peter and he is now OK with the idea of supporting \x,
> with the underestanding that it doesn't take us any farther away from
> compatibility than we are now.


Peter may be OK with it, but I object strongly to adding this to SQL
literals. This is exactly *not* the direction we want to be going in.

I don't really see the point for COPY and psql, either.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:48 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509