Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit32eef5a

Browse files
committed
I've hacked up pg_dump so that it generates CONSTRAINT and CHECK
syntax that can be read back in with psql. I did this by addinga "-c" switch that controls moving the CONTSTRAINT statements insidethe CREATE TABLE statements and adding () around the CHECK arguments.Here's diffs against the 6.3.2 version of pg_dump.c.ccb
1 parent8d8bcda commit32eef5a

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.72 1998/06/15 19:30:01 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.73 1998/06/16 06:52:15 momjian Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -110,6 +110,7 @@ intdumpData;/* dump data using proper insert strings */
110110
intattrNames;/* put attr names into insert strings */
111111
intschemaOnly;
112112
intdataOnly;
113+
intcompatConstraint;
113114

114115
charg_opaque_type[10];/* name for the opaque type */
115116

@@ -125,6 +126,8 @@ usage(const char *progname)
125126
"usage: %s [options] dbname\n",progname);
126127
fprintf(stderr,
127128
"\t -a \t\t dump out only the data, no schema\n");
129+
fprintf(stderr,
130+
"\t -c \t\t generate pgsql-compatible CONSTRAINT syntax\n");
128131
fprintf(stderr,
129132
"\t -d \t\t dump data as proper insert strings\n");
130133
fprintf(stderr,
@@ -550,17 +553,21 @@ main(int argc, char **argv)
550553
g_comment_end[0]='\0';
551554
strcpy(g_opaque_type,"opaque");
552555

553-
dataOnly=schemaOnly=dumpData=attrNames=0;
556+
compatConstraint=dataOnly=schemaOnly=dumpData=attrNames=0;
554557

555558
progname=*argv;
556559

557-
while ((c=getopt(argc,argv,"adDf:h:op:st:vzu"))!=EOF)
560+
while ((c=getopt(argc,argv,"acdDf:h:op:st:vzu"))!=EOF)
558561
{
559562
switch (c)
560563
{
561564
case'a':/* Dump data only */
562565
dataOnly=1;
563566
break;
567+
case'c':/* generate constraint syntax that
568+
can be read back into postgreSQL */
569+
compatConstraint=1;
570+
break;
564571
case'd':/* dump data as proper insert strings */
565572
dumpData=1;
566573
break;
@@ -1491,7 +1498,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14911498
query[0]=0;
14921499
if (name[0]!='$')
14931500
sprintf(query,"CONSTRAINT %s ",name);
1494-
sprintf(query,"%sCHECK %s",query,expr);
1501+
if(compatConstraint ) {
1502+
sprintf(query,"%sCHECK (%s)",query,expr);
1503+
}
1504+
else {
1505+
sprintf(query,"%sCHECK %s",query,expr);
1506+
}
14951507
tblinfo[i].check_expr[i2]=strdup(query);
14961508
}
14971509
PQclear(res2);
@@ -2509,6 +2521,17 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
25092521
}
25102522
}
25112523

2524+
if(compatConstraint ) {
2525+
/* put the CONSTRAINTS inside the table def */
2526+
for (k=0;k<tblinfo[i].ncheck;k++)
2527+
{
2528+
sprintf(q,"%s%s %s",
2529+
q,
2530+
(actual_atts+k>0) ?", " :"",
2531+
tblinfo[i].check_expr[k]);
2532+
}
2533+
}
2534+
25122535
strcat(q,")");
25132536

25142537
if (numParents>0)
@@ -2524,8 +2547,9 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
25242547
strcat(q,")");
25252548
}
25262549

2527-
if (tblinfo[i].ncheck>0)
2550+
if( !compatConstraint)
25282551
{
2552+
/* put the CONSTRAINT defs outside the table def */
25292553
for (k=0;k<tblinfo[i].ncheck;k++)
25302554
{
25312555
sprintf(q,"%s%s %s",
@@ -2534,6 +2558,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
25342558
tblinfo[i].check_expr[k]);
25352559
}
25362560
}
2561+
25372562
strcat(q,";\n");
25382563
fputs(q,fout);
25392564
if (acls)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp