Re: "COPY FROM" recognize \xDD sequence - addition to copy.c

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Igor Georgiev <gory(at)alphasoft-bg(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: "COPY FROM" recognize \xDD sequence - addition to copy.c
Date: 2002-10-16 16:55:22
Message-ID: 200210161655.g9GGtMj09202@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Right now we assume \XXX is octal. We could support \x as hex because
\x isn't any special backslash character. However, no one has ever
asked for this. Does anyone else think this would be benficial?

---------------------------------------------------------------------------

Igor Georgiev wrote:
> 1. Why i do this:
> I try to migrate a database with a 200 tables from Sybase SQL Anywhere to PostgreSQL,
> but SQL Anywhere escapes special characters like a HEX values ( like \x0D \x2C ..... ).
> PostgreSQL COPY FROM recognize only OCT values ( lie \001 ... )
> 2. How-to it' easy :)))
> 2.1 - Open $UrSourceDir/src/backend/commands/copy.c
> 2.2 - Add #include <ctype.h> in te begining
> 2.3 find function
> static char *
> CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print)
> /*----------------*/
> /*-------- Add this code before it --------*/
> static int
> HEXVALUE( int c )
> {
> if (isdigit(c))
> {
> c -= '0';
> }
> else
> {
> if (islower(c))
> c= c-'a'+10;
> else
> c= c-'A'+10;
> }
> return(c);
> }
> 2.4 in body of CopyReadAttribute
> find this code and modify it like this
> if (c == '\\')
> {
> c = CopyGetChar(fp);
> if (c == EOF)
> goto endOfFile;
> switch (c)
> {
> /*------ Here is my additional code ------*/
> case 'x':
> case 'X':
> {
> int val;
> CopyDonePeek(fp, c, true /*pick up*/); /* Get x always */
> c = CopyPeekChar(fp); /* Get next */
> if (isxdigit(c))
> {
> val = HEXVALUE(c);
> c = CopyPeekChar(fp);
> if (isxdigit(c))
> {
> val = (val << 4) + HEXVALUE(c);
> CopyDonePeek(fp, c, true /*pick up*/);
> }
> else
> {
> if (c == EOF)
> goto endOfFile;
> CopyDonePeek(fp, c, false /*put back*/);
> }
> }
> else
> {
> if (c == EOF)
> goto endOfFile;
> CopyDonePeek(fp, c, false /*put back*/);
> }
> c = val;
> }
> break;
> /*------ End of my additional code ------*/
> case '0':
> case '1':
> case '2':
> case '3':
> case '4':
> case '5':
> case '6':
> case '7':
> {
> int val;
> val = OCTVALUE(c);
> 2.4 he he now make , make install ....
> 3. An idea to developers : maybe u include this addition to COPY in future releases
> 10x
>
> P.S. Excuse me for my English ( i'm better in C :)

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Treat 2002-10-16 17:18:25 Re: Vacuum improvement
Previous Message Greg Copeland 2002-10-16 16:52:43 Re: Vacuum improvement