Bug and Patch for dump/restore of varchars

Поиск
Список
Период
Сортировка
Искать

Bug and Patch for dump/restore of varchars

От:
"Cary B. O'Brien" <cobrien@access.digex.net>
Дата:

OK, i finally got some time.  I know I should have gotten
this out long ago

I had three actual bugs I had to fix with 6.3.1 for our
production application.  

1) can't enter float .001  (FIXED)
2) Can't dump/restore varchar fields (See attached bug report/patch)
3) Problems with tcl interface, storing/retrieving lists  (under discussion)

Is this the right fix?  How do I get the patch applied?  
I haven't supplied patches before.  The patch is against
the latest snapshot.

-- cary

Bug report, can't restore varchar fields
---------------------------------------

Version:  postgresql snapshot dated oct 9 (well, that's when I downloaded it).

Problem:  Pg dump dumps varchar fields as varchar(-5).

cary=> create table fred (id int, name varchar, salary float);
CREATE
cary=> \q
[cary@jason new]$ pg_dump cary -t fred > /tmp/fred.sql
[cary@jason new]$ cat /tmp/fred.sql
CREATE TABLE "fred" ("id" "int4", "name" varchar(-5), "salary" "float8");
COPY "fred" FROM stdin;
\.
[cary@jason new]$ psql < /tmp/fred.sql
CREATE TABLE "fred" ("id" "int4", "name" varchar(-5), "salary" "float8");
ERROR:  parser: parse error at or near "-"
COPY "fred" FROM stdin;
EOF

Solution:  fix pg_dump
---------------------------------------- start patch ----------------------
[cary@jason pg_dump]$ rcsdiff -C 5 pg_dump.c
===================================================================
RCS file: RCS/pg_dump.c,v
retrieving revision 1.1
diff -C 5 -r1.1 pg_dump.c
*** pg_dump.c	1998/10/10 11:24:22	1.1
--- pg_dump.c	1998/10/10 11:34:47
***************
*** 2647,2660 ****
  						sprintf(q, "%s%s%s %s",
  								q,
  								(actual_atts > 0) ? ", " : "",
  								fmtId(tblinfo[i].attnames[j]),
  								tblinfo[i].typnames[j]);
! 
! 						sprintf(q, "%s(%d)",
  								q,
  								tblinfo[i].atttypmod[j] - VARHDRSZ);
  						actual_atts++;
  					}
  					else
  					{
  						strcpy(id1, fmtId(tblinfo[i].attnames[j]));
--- 2647,2664 ----
  						sprintf(q, "%s%s%s %s",
  								q,
  								(actual_atts > 0) ? ", " : "",
  								fmtId(tblinfo[i].attnames[j]),
  								tblinfo[i].typnames[j]);
! 						if(tblinfo[i].atttypmod[j] != -1) {
! 						        sprintf(q, "%s(%d)",
  								q,
  								tblinfo[i].atttypmod[j] - VARHDRSZ);
+ 						}
+ 						else {
+ 						        sprintf(q, "%s", q);
+ 						}
  						actual_atts++;
  					}
  					else
  					{
  						strcpy(id1, fmtId(tblinfo[i].attnames[j]));
---------------------- end of patch ------------------------------------------

Re: [HACKERS] Bug and Patch for dump/restore of varchars

От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
Applied


> 
> OK, i finally got some time.  I know I should have gotten
> this out long ago
> 
> I had three actual bugs I had to fix with 6.3.1 for our
> production application.  
> 
> 1) can't enter float .001  (FIXED)
> 2) Can't dump/restore varchar fields (See attached bug report/patch)
> 3) Problems with tcl interface, storing/retrieving lists  (under discussion)
> 
> Is this the right fix?  How do I get the patch applied?  
> I haven't supplied patches before.  The patch is against
> the latest snapshot.
> 
> -- cary
> 
> Bug report, can't restore varchar fields
> ---------------------------------------
> 
> Version:  postgresql snapshot dated oct 9 (well, that's when I downloaded it).
> 
> Problem:  Pg dump dumps varchar fields as varchar(-5).
> 
> cary=> create table fred (id int, name varchar, salary float);
> CREATE
> cary=> \q
> [cary@jason new]$ pg_dump cary -t fred > /tmp/fred.sql
> [cary@jason new]$ cat /tmp/fred.sql
> CREATE TABLE "fred" ("id" "int4", "name" varchar(-5), "salary" "float8");
> COPY "fred" FROM stdin;
> \.
> [cary@jason new]$ psql < /tmp/fred.sql
> CREATE TABLE "fred" ("id" "int4", "name" varchar(-5), "salary" "float8");
> ERROR:  parser: parse error at or near "-"
> COPY "fred" FROM stdin;
> EOF
> 
> Solution:  fix pg_dump
> ---------------------------------------- start patch ----------------------
> [cary@jason pg_dump]$ rcsdiff -C 5 pg_dump.c
> ===================================================================
> RCS file: RCS/pg_dump.c,v
> retrieving revision 1.1
> diff -C 5 -r1.1 pg_dump.c
> *** pg_dump.c	1998/10/10 11:24:22	1.1
> --- pg_dump.c	1998/10/10 11:34:47
> ***************
> *** 2647,2660 ****
>   						sprintf(q, "%s%s%s %s",
>   								q,
>   								(actual_atts > 0) ? ", " : "",
>   								fmtId(tblinfo[i].attnames[j]),
>   								tblinfo[i].typnames[j]);
> ! 
> ! 						sprintf(q, "%s(%d)",
>   								q,
>   								tblinfo[i].atttypmod[j] - VARHDRSZ);
>   						actual_atts++;
>   					}
>   					else
>   					{
>   						strcpy(id1, fmtId(tblinfo[i].attnames[j]));
> --- 2647,2664 ----
>   						sprintf(q, "%s%s%s %s",
>   								q,
>   								(actual_atts > 0) ? ", " : "",
>   								fmtId(tblinfo[i].attnames[j]),
>   								tblinfo[i].typnames[j]);
> ! 						if(tblinfo[i].atttypmod[j] != -1) {
> ! 						        sprintf(q, "%s(%d)",
>   								q,
>   								tblinfo[i].atttypmod[j] - VARHDRSZ);
> + 						}
> + 						else {
> + 						        sprintf(q, "%s", q);
> + 						}
>   						actual_atts++;
>   					}
>   					else
>   					{
>   						strcpy(id1, fmtId(tblinfo[i].attnames[j]));
> ---------------------- end of patch ------------------------------------------
> 
> 


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

FAQ