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

Commit73b6ffb

Browse files
committed
Improvements to pg_dump to:
- dump ViewsSubmitted by: Keith Parks <emkxp01@mtcc.demon.co.uk>
1 parent1480031 commit73b6ffb

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 53 additions & 3 deletions
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.21 1996/12/30 23:05:16bryanh Exp $
23+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.22 1997/01/07 00:04:16scrappy Exp $
2424
*
2525
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2626
*
@@ -121,6 +121,44 @@ exit_nicely(PGconn* conn)
121121
}
122122

123123

124+
/*
125+
* isViewRule
126+
*Determine if the relation is a VIEW
127+
*
128+
*/
129+
bool
130+
isViewRule(char*relname)
131+
{
132+
PGresult*res;
133+
intntups;
134+
charquery[MAXQUERYLEN];
135+
136+
res=PQexec(g_conn,"begin");
137+
if (!res||
138+
PQresultStatus(res)!=PGRES_COMMAND_OK) {
139+
fprintf(stderr,"BEGIN command failed\n");
140+
exit_nicely(g_conn);
141+
}
142+
PQclear(res);
143+
144+
sprintf(query,"select relname from pg_class, pg_rewrite "
145+
"where pg_class.oid = ev_class "
146+
"and rulename = '_RET%s'",relname);
147+
148+
res=PQexec(g_conn,query);
149+
if (!res||
150+
PQresultStatus(res)!=PGRES_TUPLES_OK) {
151+
fprintf(stderr,"isViewRule(): SELECT failed\n");
152+
exit_nicely(g_conn);
153+
}
154+
155+
ntups=PQntuples(res);
156+
157+
PQclear(res);
158+
res=PQexec(g_conn,"end");
159+
PQclear(res);
160+
returnntups>0 ? TRUE : FALSE;
161+
}
124162

125163
#defineCOPYBUFSIZ 8192
126164

@@ -306,6 +344,10 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
306344
for(i=0;i<numTables;i++) {
307345
constchar*classname=tblinfo[i].relname;
308346

347+
/* Skip VIEW relations */
348+
if (isViewRule(tblinfo[i].relname))
349+
continue;
350+
309351
if (!onlytable|| (!strcmp(classname,onlytable))) {
310352
if (g_verbose)
311353
fprintf(stderr,"%s dumping out the contents of Table %s %s\n",
@@ -1074,6 +1116,7 @@ getIndices(int *numIndices)
10741116
inti_indproc;
10751117
inti_indkey;
10761118
inti_indclassname;
1119+
inti_indisunique;
10771120

10781121
/* find all the user-defined indices.
10791122
We do not handle partial indices.
@@ -1095,7 +1138,7 @@ getIndices(int *numIndices)
10951138
sprintf(query,
10961139
"SELECT t1.relname as indexrelname, t2.relname as indrelname, "
10971140
"i.indproc, i.indkey[0], o.opcname as indclassname, "
1098-
"a.amname as indamname from pg_index i, pg_class t1, "
1141+
"a.amname as indamname, i.indisunique from pg_index i, pg_class t1, "
10991142
"pg_class t2, pg_opclass o, pg_am a "
11001143
"where t1.oid = i.indexrelid and t2.oid = i.indrelid "
11011144
"and o.oid = i.indclass[0] and t1.relam = a.oid and "
@@ -1122,6 +1165,7 @@ getIndices(int *numIndices)
11221165
i_indproc=PQfnumber(res,"indproc");
11231166
i_indkey=PQfnumber(res,"indkey");
11241167
i_indclassname=PQfnumber(res,"indclassname");
1168+
i_indisunique=PQfnumber(res,"indisunique");
11251169

11261170
for (i=0;i<ntups;i++) {
11271171
indinfo[i].indexrelname=strdup(PQgetvalue(res,i,i_indexrelname));
@@ -1130,6 +1174,7 @@ getIndices(int *numIndices)
11301174
indinfo[i].indproc=strdup(PQgetvalue(res,i,i_indproc));
11311175
indinfo[i].indkey=strdup(PQgetvalue(res,i,i_indkey));
11321176
indinfo[i].indclassname=strdup(PQgetvalue(res,i,i_indclassname));
1177+
indinfo[i].indisunique=strdup(PQgetvalue(res,i,i_indisunique));
11331178
}
11341179
PQclear(res);
11351180
res=PQexec(g_conn,"end");
@@ -1450,6 +1495,10 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
14501495

14511496
if (!tablename|| (!strcmp(tblinfo[i].relname,tablename))) {
14521497

1498+
/* Skip VIEW relations */
1499+
if (isViewRule(tblinfo[i].relname))
1500+
continue;
1501+
14531502
/* skip archive names*/
14541503
if (isArchiveName(tblinfo[i].relname))
14551504
continue;
@@ -1583,7 +1632,8 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
15831632

15841633
if (!tablename|| (!strcmp(indinfo[i].indrelname,tablename))) {
15851634

1586-
sprintf(q,"CREATE INDEX %s on %s using %s (",
1635+
sprintf(q,"CREATE %s INDEX %s on %s using %s (",
1636+
(strcmp(indinfo[i].indisunique,"t")==0) ?"UNIQUE" :"",
15871637
indinfo[i].indexrelname,
15881638
indinfo[i].indrelname,
15891639
indinfo[i].indamname);

‎src/bin/pg_dump/pg_dump.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pg_dump.h,v 1.9 1996/12/27 23:12:57 bryanh Exp $
8+
* $Id: pg_dump.h,v 1.10 1997/01/07 00:04:19 scrappy Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -87,6 +87,7 @@ typedef struct _indInfo {
8787
char*indproc;/* oid of the function to compute the index, 0 if none*/
8888
char*indkey;/* attribute number of the key attribute */
8989
char*indclassname;/* name of the opclass of the key */
90+
char*indisunique;/* is this index unique? */
9091
}IndInfo;
9192

9293
typedefstruct_aggInfo {
@@ -161,6 +162,7 @@ extern void check_conn_and_db(void);
161162
externintstrInArray(constchar*pattern,char**arr,intarr_size);
162163
externvoidparseArgTypes(char**argtypes,constchar*str);
163164
externintisArchiveName(constchar*);
165+
externboolisViewRule(char*relname);
164166

165167
/*
166168
* version specific routines

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp