]> granicus.if.org Git - postgresql/commitdiff
Don't dump CHECK constraints with same source and names both
authorPhilip Warner <pjw@rhyme.com.au>
Wed, 4 Apr 2001 06:47:30 +0000 (06:47 +0000)
committerPhilip Warner <pjw@rhyme.com.au>
Wed, 4 Apr 2001 06:47:30 +0000 (06:47 +0000)
starting with '$'.

src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_dump.c

index fb85685fbc14ff761a6403d75f8859022f8c6417..22e263b7b258f8f389db3f02b0e0efa3cbcc103f 100644 (file)
@@ -17,7 +17,7 @@
  *
  *
  * IDENTIFICATION
- *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.29 2001/04/03 08:52:59 pjw Exp $
+ *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.30 2001/04/04 06:47:30 pjw Exp $
  *
  * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
  *     -       Initial version.
@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
 
 #define K_VERS_MAJOR 1
 #define K_VERS_MINOR 5
-#define K_VERS_REV 1 
+#define K_VERS_REV 2 
 
 /* Data block types */
 #define BLK_DATA 1
index c4a79aa054af3aa7258c0b2664e61322b5be6327..3ec4893606e225e8fdadcc8719f9ae5a3a911e36 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.199 2001/04/03 08:52:59 pjw Exp $
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.200 2001/04/04 06:47:30 pjw Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
  *             OID of the type functions, but type must be created after 
  *             the functions.
  *
+ * Modifications - 4-Apr-2001 - pjw@rhyme.com.au
+ *
+ *       - Don't dump CHECK constraints with same source and names both
+ *             starting with '$'.
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -2068,59 +2073,15 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                else
                        tblinfo[i].viewdef = NULL;
 
-               /*
+               /* 
+                * Get non-inherited CHECK constraints, if any.
+                *
                 * Exclude inherited CHECKs from CHECK constraints total. If a
                 * constraint matches by name and condition with a constraint
-                * belonging to a parent class, we assume it was inherited.
+                * belonging to a parent class (OR conditions match and both
+            * names start with '$', we assume it was inherited.
                 */
                if (tblinfo[i].ncheck > 0)
-               {
-                       PGresult   *res2;
-                       int                     ntups2;
-
-                       if (g_verbose)
-                               fprintf(stderr, "%s excluding inherited CHECK constraints "
-                                               "for relation: '%s' %s\n",
-                                               g_comment_start,
-                                               tblinfo[i].relname,
-                                               g_comment_end);
-
-                       /*
-                        * XXXX: Use LOJ maybe - need to compare with subsequent query
-                        * for non-inherited
-                        */
-                       resetPQExpBuffer(query);
-                       appendPQExpBuffer(query, "SELECT rcname from pg_relcheck, pg_inherits as i "
-                                                         "where rcrelid = '%s'::oid "
-                                                         " and rcrelid = i.inhrelid"
-                                                         " and exists "
-                                                         "  (select * from pg_relcheck as c "
-                                                         "    where c.rcname = pg_relcheck.rcname "
-                                                         "      and c.rcsrc = pg_relcheck.rcsrc "
-                                                         "      and c.rcrelid = i.inhparent) ",
-                                                         tblinfo[i].oid);
-                       res2 = PQexec(g_conn, query->data);
-                       if (!res2 ||
-                               PQresultStatus(res2) != PGRES_TUPLES_OK)
-                       {
-                               fprintf(stderr, "getTables(): SELECT (for inherited CHECK) failed.  "
-                                               "Explanation from backend: '%s'.\n", PQerrorMessage(g_conn));
-                               exit_nicely(g_conn);
-                       }
-                       ntups2 = PQntuples(res2);
-                       tblinfo[i].ncheck -= ntups2;
-                       if (tblinfo[i].ncheck < 0)
-                       {
-                               fprintf(stderr, "getTables(): found more inherited CHECKs than total for "
-                                               "relation %s\n",
-                                               tblinfo[i].relname);
-                               exit_nicely(g_conn);
-                       }
-                       PQclear(res2);
-               }
-
-               /* Get non-inherited CHECK constraints, if any */
-               if (tblinfo[i].ncheck > 0)
                {
                        PGresult   *res2;
                        int                     i_rcname,
@@ -2136,13 +2097,16 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
 
                        resetPQExpBuffer(query);
                        appendPQExpBuffer(query, "SELECT rcname, rcsrc from pg_relcheck "
-                                                         "where rcrelid = '%s'::oid "
+                                                         " where rcrelid = '%s'::oid "
                                                          "   and not exists "
-                                  "  (select * from pg_relcheck as c, pg_inherits as i "
-                                                         "   where i.inhrelid = pg_relcheck.rcrelid "
-                                                         "     and c.rcname = pg_relcheck.rcname "
-                                                         "     and c.rcsrc = pg_relcheck.rcsrc "
-                                                         "     and c.rcrelid = i.inhparent) "
+                                                         "  (select * from pg_relcheck as c, pg_inherits as i "
+                                                         "    where i.inhrelid = pg_relcheck.rcrelid "
+                                                         "      and (c.rcname = pg_relcheck.rcname "
+                                                         "          or (    c.rcname[0] = '$' "
+                                                         "              and pg_relcheck.rcname[0] = '$')"
+                                                         "          )"
+                                                         "      and c.rcsrc = pg_relcheck.rcsrc "
+                                                         "      and c.rcrelid = i.inhparent) "
                                                          " Order By oid ",
                                                          tblinfo[i].oid);
                        res2 = PQexec(g_conn, query->data);
@@ -2154,12 +2118,17 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                                exit_nicely(g_conn);
                        }
                        ntups2 = PQntuples(res2);
-                       if (ntups2 != tblinfo[i].ncheck)
+                       if (ntups2 > tblinfo[i].ncheck)
                        {
-                               fprintf(stderr, "getTables(): relation '%s': %d CHECKs were expected, but got %d\n",
+                               fprintf(stderr, "getTables(): relation '%s': a maximum of %d CHECKs "
+                                                                       "were expected, but got %d\n",
                                                tblinfo[i].relname, tblinfo[i].ncheck, ntups2);
                                exit_nicely(g_conn);
                        }
+
+                       /* Set ncheck to the number of *non-inherited* CHECK constraints */
+                       tblinfo[i].ncheck = ntups2;
+
                        i_rcname = PQfnumber(res2, "rcname");
                        i_rcsrc = PQfnumber(res2, "rcsrc");
                        tblinfo[i].check_expr = (char **) malloc(ntups2 * sizeof(char *));
@@ -3897,7 +3866,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
 
                                if (numParents > 0)
                                {
-                                       appendPQExpBuffer(q, "\ninherits (");
+                                       appendPQExpBuffer(q, "\nINHERITS (");
                                        for (k = 0; k < numParents; k++)
                                        {
                                                appendPQExpBuffer(q, "%s%s",