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+ int ntups ;
134+ char query [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+ return ntups > 0 ? TRUE : FALSE;
161+ }
124162
125163#define COPYBUFSIZ 8192
126164
@@ -306,6 +344,10 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
306344for (i = 0 ;i < numTables ;i ++ ) {
307345const char * classname = tblinfo [i ].relname ;
308346
347+ /* Skip VIEW relations */
348+ if (isViewRule (tblinfo [i ].relname ))
349+ continue ;
350+
309351if (!onlytable || (!strcmp (classname ,onlytable ))) {
310352if (g_verbose )
311353fprintf (stderr ,"%s dumping out the contents of Table %s %s\n" ,
@@ -1074,6 +1116,7 @@ getIndices(int *numIndices)
10741116int i_indproc ;
10751117int i_indkey ;
10761118int i_indclassname ;
1119+ int i_indisunique ;
10771120
10781121/* find all the user-defined indices.
10791122 We do not handle partial indices.
@@ -1095,7 +1138,7 @@ getIndices(int *numIndices)
10951138sprintf (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)
11221165i_indproc = PQfnumber (res ,"indproc" );
11231166i_indkey = PQfnumber (res ,"indkey" );
11241167i_indclassname = PQfnumber (res ,"indclassname" );
1168+ i_indisunique = PQfnumber (res ,"indisunique" );
11251169
11261170for (i = 0 ;i < ntups ;i ++ ) {
11271171indinfo [i ].indexrelname = strdup (PQgetvalue (res ,i ,i_indexrelname ));
@@ -1130,6 +1174,7 @@ getIndices(int *numIndices)
11301174indinfo [i ].indproc = strdup (PQgetvalue (res ,i ,i_indproc ));
11311175indinfo [i ].indkey = strdup (PQgetvalue (res ,i ,i_indkey ));
11321176indinfo [i ].indclassname = strdup (PQgetvalue (res ,i ,i_indclassname ));
1177+ indinfo [i ].indisunique = strdup (PQgetvalue (res ,i ,i_indisunique ));
11331178 }
11341179PQclear (res );
11351180res = PQexec (g_conn ,"end" );
@@ -1450,6 +1495,10 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
14501495
14511496if (!tablename || (!strcmp (tblinfo [i ].relname ,tablename ))) {
14521497
1498+ /* Skip VIEW relations */
1499+ if (isViewRule (tblinfo [i ].relname ))
1500+ continue ;
1501+
14531502/* skip archive names*/
14541503if (isArchiveName (tblinfo [i ].relname ))
14551504continue ;
@@ -1583,7 +1632,8 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
15831632
15841633if (!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" :"" ,
15871637indinfo [i ].indexrelname ,
15881638indinfo [i ].indrelname ,
15891639indinfo [i ].indamname );