2222 *
2323 *
2424 * IDENTIFICATION
25- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.199 2001/04/03 08:52:59 pjw Exp $
25+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.200 2001/04/04 06:47:30 pjw Exp $
2626 *
2727 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828 *
122122 *OID of the type functions, but type must be created after
123123 *the functions.
124124 *
125+ * Modifications - 4-Apr-2001 - pjw@rhyme.com.au
126+ *
127+ * - Don't dump CHECK constraints with same source and names both
128+ *starting with '$'.
129+ *
125130 *-------------------------------------------------------------------------
126131 */
127132
@@ -2068,59 +2073,15 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20682073else
20692074tblinfo [i ].viewdef = NULL ;
20702075
2071- /*
2076+ /*
2077+ * Get non-inherited CHECK constraints, if any.
2078+ *
20722079 * Exclude inherited CHECKs from CHECK constraints total. If a
20732080 * constraint matches by name and condition with a constraint
2074- * belonging to a parent class, we assume it was inherited.
2081+ * belonging to a parent class (OR conditions match and both
2082+ * names start with '$', we assume it was inherited.
20752083 */
20762084if (tblinfo [i ].ncheck > 0 )
2077- {
2078- PGresult * res2 ;
2079- int ntups2 ;
2080-
2081- if (g_verbose )
2082- fprintf (stderr ,"%s excluding inherited CHECK constraints "
2083- "for relation: '%s' %s\n" ,
2084- g_comment_start ,
2085- tblinfo [i ].relname ,
2086- g_comment_end );
2087-
2088- /*
2089- * XXXX: Use LOJ maybe - need to compare with subsequent query
2090- * for non-inherited
2091- */
2092- resetPQExpBuffer (query );
2093- appendPQExpBuffer (query ,"SELECT rcname from pg_relcheck, pg_inherits as i "
2094- "where rcrelid = '%s'::oid "
2095- " and rcrelid = i.inhrelid"
2096- " and exists "
2097- " (select * from pg_relcheck as c "
2098- " where c.rcname = pg_relcheck.rcname "
2099- " and c.rcsrc = pg_relcheck.rcsrc "
2100- " and c.rcrelid = i.inhparent) " ,
2101- tblinfo [i ].oid );
2102- res2 = PQexec (g_conn ,query -> data );
2103- if (!res2 ||
2104- PQresultStatus (res2 )!= PGRES_TUPLES_OK )
2105- {
2106- fprintf (stderr ,"getTables(): SELECT (for inherited CHECK) failed. "
2107- "Explanation from backend: '%s'.\n" ,PQerrorMessage (g_conn ));
2108- exit_nicely (g_conn );
2109- }
2110- ntups2 = PQntuples (res2 );
2111- tblinfo [i ].ncheck -= ntups2 ;
2112- if (tblinfo [i ].ncheck < 0 )
2113- {
2114- fprintf (stderr ,"getTables(): found more inherited CHECKs than total for "
2115- "relation %s\n" ,
2116- tblinfo [i ].relname );
2117- exit_nicely (g_conn );
2118- }
2119- PQclear (res2 );
2120- }
2121-
2122- /* Get non-inherited CHECK constraints, if any */
2123- if (tblinfo [i ].ncheck > 0 )
21242085{
21252086PGresult * res2 ;
21262087int i_rcname ,
@@ -2136,13 +2097,16 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21362097
21372098resetPQExpBuffer (query );
21382099appendPQExpBuffer (query ,"SELECT rcname, rcsrc from pg_relcheck "
2139- "where rcrelid = '%s'::oid "
2100+ " where rcrelid = '%s'::oid "
21402101" and not exists "
2141- " (select * from pg_relcheck as c, pg_inherits as i "
2142- " where i.inhrelid = pg_relcheck.rcrelid "
2143- " and c.rcname = pg_relcheck.rcname "
2144- " and c.rcsrc = pg_relcheck.rcsrc "
2145- " and c.rcrelid = i.inhparent) "
2102+ " (select * from pg_relcheck as c, pg_inherits as i "
2103+ " where i.inhrelid = pg_relcheck.rcrelid "
2104+ " and (c.rcname = pg_relcheck.rcname "
2105+ " or ( c.rcname[0] = '$' "
2106+ " and pg_relcheck.rcname[0] = '$')"
2107+ " )"
2108+ " and c.rcsrc = pg_relcheck.rcsrc "
2109+ " and c.rcrelid = i.inhparent) "
21462110" Order By oid " ,
21472111tblinfo [i ].oid );
21482112res2 = PQexec (g_conn ,query -> data );
@@ -2154,12 +2118,17 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21542118exit_nicely (g_conn );
21552119}
21562120ntups2 = PQntuples (res2 );
2157- if (ntups2 != tblinfo [i ].ncheck )
2121+ if (ntups2 > tblinfo [i ].ncheck )
21582122{
2159- fprintf (stderr ,"getTables(): relation '%s': %d CHECKs were expected, but got %d\n" ,
2123+ fprintf (stderr ,"getTables(): relation '%s': a maximum of %d CHECKs "
2124+ "were expected, but got %d\n" ,
21602125tblinfo [i ].relname ,tblinfo [i ].ncheck ,ntups2 );
21612126exit_nicely (g_conn );
21622127}
2128+
2129+ /* Set ncheck to the number of *non-inherited* CHECK constraints */
2130+ tblinfo [i ].ncheck = ntups2 ;
2131+
21632132i_rcname = PQfnumber (res2 ,"rcname" );
21642133i_rcsrc = PQfnumber (res2 ,"rcsrc" );
21652134tblinfo [i ].check_expr = (char * * )malloc (ntups2 * sizeof (char * ));
@@ -3897,7 +3866,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
38973866
38983867if (numParents > 0 )
38993868{
3900- appendPQExpBuffer (q ,"\ninherits (" );
3869+ appendPQExpBuffer (q ,"\nINHERITS (" );
39013870for (k = 0 ;k < numParents ;k ++ )
39023871{
39033872appendPQExpBuffer (q ,"%s%s" ,