22
22
*
23
23
*
24
24
* 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 $
26
26
*
27
27
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
28
28
*
122
122
* OID of the type functions, but type must be created after
123
123
* the functions.
124
124
*
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
+ *
125
130
*-------------------------------------------------------------------------
126
131
*/
127
132
@@ -2068,59 +2073,15 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2068
2073
else
2069
2074
tblinfo [i ].viewdef = NULL ;
2070
2075
2071
- /*
2076
+ /*
2077
+ * Get non-inherited CHECK constraints, if any.
2078
+ *
2072
2079
* Exclude inherited CHECKs from CHECK constraints total. If a
2073
2080
* 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.
2075
2083
*/
2076
2084
if (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 )
2124
2085
{
2125
2086
PGresult * res2 ;
2126
2087
int i_rcname ,
@@ -2136,13 +2097,16 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2136
2097
2137
2098
resetPQExpBuffer (query );
2138
2099
appendPQExpBuffer (query , "SELECT rcname, rcsrc from pg_relcheck "
2139
- "where rcrelid = '%s'::oid "
2100
+ " where rcrelid = '%s'::oid "
2140
2101
" 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) "
2146
2110
" Order By oid " ,
2147
2111
tblinfo [i ].oid );
2148
2112
res2 = PQexec (g_conn , query -> data );
@@ -2154,12 +2118,17 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2154
2118
exit_nicely (g_conn );
2155
2119
}
2156
2120
ntups2 = PQntuples (res2 );
2157
- if (ntups2 != tblinfo [i ].ncheck )
2121
+ if (ntups2 > tblinfo [i ].ncheck )
2158
2122
{
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" ,
2160
2125
tblinfo [i ].relname , tblinfo [i ].ncheck , ntups2 );
2161
2126
exit_nicely (g_conn );
2162
2127
}
2128
+
2129
+ /* Set ncheck to the number of *non-inherited* CHECK constraints */
2130
+ tblinfo [i ].ncheck = ntups2 ;
2131
+
2163
2132
i_rcname = PQfnumber (res2 , "rcname" );
2164
2133
i_rcsrc = PQfnumber (res2 , "rcsrc" );
2165
2134
tblinfo [i ].check_expr = (char * * ) malloc (ntups2 * sizeof (char * ));
@@ -3897,7 +3866,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
3897
3866
3898
3867
if (numParents > 0 )
3899
3868
{
3900
- appendPQExpBuffer (q , "\ninherits (" );
3869
+ appendPQExpBuffer (q , "\nINHERITS (" );
3901
3870
for (k = 0 ; k < numParents ; k ++ )
3902
3871
{
3903
3872
appendPQExpBuffer (q , "%s%s" ,
0 commit comments