Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 22113f8

Browse files
committed
This is a patch to pg_dump which fixes varchar and char printing in the
case where the attribute length is variable (stored as -1). Previously, you'd get output that looked like: CREATE TABLE foo (bar varchar(-1)); Monitor and psql don't like this at all :). Here is a fix: Submitted by: Adam Sussman <myddryn@vidya.com>
1 parent c13ef1a commit 22113f8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/bin/pg_dump/pg_dump.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
23+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.4 1996/07/27 02:29:51 scrappy Exp $
2424
*
2525
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2626
*
@@ -35,6 +35,10 @@
3535
* - Added single. quote to twin single quote expansion for 'insert' string
3636
* mode.
3737
*
38+
* Modifications - 7/26/96 - asussman@vidya.com
39+
*
40+
* - Fixed ouput lengths for char and varchar type where the length is variable (-1)
41+
*
3842
*-------------------------------------------------------------------------
3943
*/
4044

@@ -1210,20 +1214,30 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
12101214

12111215
/* Show lengths on bpchar and varchar */
12121216
if (!strcmp(tblinfo[i].typnames[j],"bpchar")) {
1213-
sprintf(q, "%s%s%s char(%d)",
1217+
sprintf(q, "%s%s%s char",
12141218
q,
12151219
(actual_atts > 0) ? ", " : "",
1216-
tblinfo[i].attnames[j],
1217-
tblinfo[i].attlen[j]);
1220+
tblinfo[i].attnames[j]);
1221+
1222+
/* stored length can be -1 (variable) */
1223+
if (tblinfo[i].attlen[j] > 0)
1224+
sprintf(q, "%s(%d)",
1225+
q,
1226+
tblinfo[i].attlen[j]);
12181227
actual_atts++;
12191228
}
12201229
else if (!strcmp(tblinfo[i].typnames[j],"varchar")) {
1221-
sprintf(q, "%s%s%s %s(%d)",
1230+
sprintf(q, "%s%s%s %s",
12221231
q,
12231232
(actual_atts > 0) ? ", " : "",
12241233
tblinfo[i].attnames[j],
1225-
tblinfo[i].typnames[j],
1226-
tblinfo[i].attlen[j]);
1234+
tblinfo[i].typnames[j]);
1235+
1236+
/* stored length can be -1 (variable) */
1237+
if (tblinfo[i].attlen[j] > 0)
1238+
sprintf(q, "%s(%d)",
1239+
q,
1240+
tblinfo[i].attlen[j]);
12271241
actual_atts++;
12281242
}
12291243
else {

0 commit comments

Comments
 (0)