Re: "COPY FROM" recognize \xDD sequence - addition to copy.c - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: "COPY FROM" recognize \xDD sequence - addition to copy.c
Date
Msg-id 200210161655.g9GGtMj09202@candle.pha.pa.us
Whole thread Raw
In response to "COPY FROM" recognize \xDD sequence - addition to copy.c & idea 4 developers  ("Igor Georgiev" <gory@alphasoft-bg.com>)
Responses Re: "COPY FROM" recognize \xDD sequence - addition to copy.c
List 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@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: Greg Copeland
Date:
Subject: Re: Vacuum improvement
Next
From: Robert Treat
Date:
Subject: Re: Vacuum improvement