Skip site navigation (1) Skip section navigation (2)

Bug and Patch for dump/restore of varchars

From: "Cary B(dot) O'Brien" <cobrien(at)access(dot)digex(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Bug and Patch for dump/restore of varchars
Date: 1998-10-10 15:31:35
Message-ID: 199810101531.LAA04499@access1.digex.net (view raw or flat)
Thread:
Lists: pgsql-hackers
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(at)jason new]$ pg_dump cary -t fred > /tmp/fred.sql
[cary(at)jason new]$ cat /tmp/fred.sql
CREATE TABLE "fred" ("id" "int4", "name" varchar(-5), "salary" "float8");
COPY "fred" FROM stdin;
\.
[cary(at)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(at)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 ------------------------------------------

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 1998-10-10 15:41:54
Subject: Re: [HACKERS] Re: hackers-digest V1 #1013
Previous:From: Tom LaneDate: 1998-10-10 15:19:44
Subject: Re: [HACKERS] backslash in psql output

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group