
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, Pennsylvania 19073

Wed, 16 Oct 2002 12:55:22 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: "COPY FROM" recognize \xDD sequence - addition to copy.c
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 :)







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 
:)
Wed, 16 Oct 2002 19:48:05 +0200
"Igor Georgiev" <gory@alphasoft-bg.com>
"COPY FROM" recognize \xDD sequence - addition to copy.c & idea 4
	developers
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> 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?

Well, it seems pretty localized and harmless.  If it lets us import
Sybase dumps, doesn't that boost our plans for world domination? ;-)

			regards, tom lane

Wed, 16 Oct 2002 23:25:57 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: "COPY FROM" recognize \xDD sequence - addition to copy.c 
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > 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?
> 
> Well, it seems pretty localized and harmless.  If it lets us import
> Sybase dumps, doesn't that boost our plans for world domination? ;-)

Yes, it does.  I will add it to TODO:

	        o Allow copy to understand \x as hex

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

Wed, 16 Oct 2002 23:58:14 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: "COPY FROM" recognize \xDD sequence - addition to copy.c
On Wed, 16 Oct 2002, Tom Lane wrote:

> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > 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?
> 
> Well, it seems pretty localized and harmless.  If it lets us import
> Sybase dumps, doesn't that boost our plans for world domination? ;-)

Can we add:

		o	World Domination

To the TODO list?

Gavin


Thu, 17 Oct 2002 14:46:19 +1000 (EST)
Gavin Sherry <swm@linuxworld.com.au>
Re: "COPY FROM" recognize \xDD sequence - addition to
Gavin Sherry wrote:
> On Wed, 16 Oct 2002, Tom Lane wrote:
> 
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > 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?
> > 
> > Well, it seems pretty localized and harmless.  If it lets us import
> > Sybase dumps, doesn't that boost our plans for world domination? ;-)
> 
> Can we add:
> 
> 		o	World Domination
> 
> To the TODO list?

That's already in there, but in subliminal type.

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

Thu, 17 Oct 2002 14:55:34 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: "COPY FROM" recognize \xDD sequence - addition to