*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.21 1996/12/30 23:05:16 bryanh Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.22 1997/01/07 00:04:16 scrappy Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
}
+/*
+ * isViewRule
+ * Determine if the relation is a VIEW
+ *
+ */
+bool
+isViewRule(char *relname)
+{
+ PGresult *res;
+ int ntups;
+ char query[MAXQUERYLEN];
+
+ res = PQexec(g_conn, "begin");
+ if (!res ||
+ PQresultStatus(res) != PGRES_COMMAND_OK) {
+ fprintf(stderr,"BEGIN command failed\n");
+ exit_nicely(g_conn);
+ }
+ PQclear(res);
+
+ sprintf(query, "select relname from pg_class, pg_rewrite "
+ "where pg_class.oid = ev_class "
+ "and rulename = '_RET%s'", relname);
+
+ res = PQexec(g_conn, query);
+ if (!res ||
+ PQresultStatus(res) != PGRES_TUPLES_OK) {
+ fprintf(stderr,"isViewRule(): SELECT failed\n");
+ exit_nicely(g_conn);
+ }
+
+ ntups = PQntuples(res);
+
+ PQclear(res);
+ res = PQexec(g_conn, "end");
+ PQclear(res);
+ return ntups > 0 ? TRUE : FALSE;
+}
#define COPYBUFSIZ 8192
for(i = 0; i < numTables; i++) {
const char *classname = tblinfo[i].relname;
+ /* Skip VIEW relations */
+ if (isViewRule(tblinfo[i].relname))
+ continue;
+
if (!onlytable || (!strcmp(classname,onlytable))) {
if (g_verbose)
fprintf(stderr, "%s dumping out the contents of Table %s %s\n",
int i_indproc;
int i_indkey;
int i_indclassname;
+ int i_indisunique;
/* find all the user-defined indices.
We do not handle partial indices.
sprintf(query,
"SELECT t1.relname as indexrelname, t2.relname as indrelname, "
"i.indproc, i.indkey[0], o.opcname as indclassname, "
- "a.amname as indamname from pg_index i, pg_class t1, "
+ "a.amname as indamname, i.indisunique from pg_index i, pg_class t1, "
"pg_class t2, pg_opclass o, pg_am a "
"where t1.oid = i.indexrelid and t2.oid = i.indrelid "
"and o.oid = i.indclass[0] and t1.relam = a.oid and "
i_indproc = PQfnumber(res,"indproc");
i_indkey = PQfnumber(res,"indkey");
i_indclassname = PQfnumber(res,"indclassname");
+ i_indisunique = PQfnumber(res,"indisunique");
for (i=0;i<ntups;i++) {
indinfo[i].indexrelname = strdup(PQgetvalue(res,i,i_indexrelname));
indinfo[i].indproc = strdup(PQgetvalue(res,i,i_indproc));
indinfo[i].indkey = strdup(PQgetvalue(res,i,i_indkey));
indinfo[i].indclassname = strdup(PQgetvalue(res,i,i_indclassname));
+ indinfo[i].indisunique = strdup(PQgetvalue(res,i,i_indisunique));
}
PQclear(res);
res = PQexec(g_conn,"end");
if (!tablename || (!strcmp(tblinfo[i].relname,tablename))) {
+ /* Skip VIEW relations */
+ if (isViewRule(tblinfo[i].relname))
+ continue;
+
/* skip archive names*/
if (isArchiveName(tblinfo[i].relname))
continue;
if (!tablename || (!strcmp(indinfo[i].indrelname,tablename))) {
- sprintf(q,"CREATE INDEX %s on %s using %s (",
+ sprintf(q,"CREATE %s INDEX %s on %s using %s (",
+ (strcmp(indinfo[i].indisunique, "t") == 0) ? "UNIQUE" : "",
indinfo[i].indexrelname,
indinfo[i].indrelname,
indinfo[i].indamname);
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_dump.h,v 1.9 1996/12/27 23:12:57 bryanh Exp $
+ * $Id: pg_dump.h,v 1.10 1997/01/07 00:04:19 scrappy Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
char *indproc; /* oid of the function to compute the index, 0 if none*/
char *indkey; /* attribute number of the key attribute */
char *indclassname; /* name of the opclass of the key */
+ char *indisunique; /* is this index unique? */
} IndInfo;
typedef struct _aggInfo {
extern int strInArray(const char* pattern, char** arr, int arr_size);
extern void parseArgTypes(char **argtypes, const char* str);
extern int isArchiveName(const char*);
+extern bool isViewRule(char *relname);
/*
* version specific routines