Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 93e5467

Browse files
committed
pg_dump for domain constraints.
Rod Taylor
1 parent 6b603e6 commit 93e5467

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.306 2002/11/08 17:37:52 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.307 2002/11/15 02:52:18 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -3157,8 +3157,10 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
31573157
PQExpBuffer q = createPQExpBuffer();
31583158
PQExpBuffer delq = createPQExpBuffer();
31593159
PQExpBuffer query = createPQExpBuffer();
3160+
PQExpBuffer chkquery = createPQExpBuffer();
31603161
PGresult *res;
31613162
int ntups;
3163+
int i;
31623164
char *typnotnull;
31633165
char *typdefn;
31643166
char *typdefault;
@@ -3228,6 +3230,34 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
32283230
if (typdefault)
32293231
appendPQExpBuffer(q, " DEFAULT %s", typdefault);
32303232

3233+
/* Fetch and process CHECK Constraints */
3234+
appendPQExpBuffer(chkquery, "SELECT conname, consrc "
3235+
"FROM pg_catalog.pg_constraint "
3236+
"WHERE contypid = '%s'::pg_catalog.oid",
3237+
tinfo->oid);
3238+
3239+
res = PQexec(g_conn, chkquery->data);
3240+
if (!res ||
3241+
PQresultStatus(res) != PGRES_TUPLES_OK)
3242+
{
3243+
write_msg(NULL, "query to obtain domain constraint information failed: %s",
3244+
PQerrorMessage(g_conn));
3245+
exit_nicely();
3246+
}
3247+
3248+
/* Expecting a single result only */
3249+
ntups = PQntuples(res);
3250+
for (i = 0; i < ntups; i++)
3251+
{
3252+
char *conname;
3253+
char *consrc;
3254+
3255+
conname = PQgetvalue(res, i, PQfnumber(res, "conname"));
3256+
consrc = PQgetvalue(res, i, PQfnumber(res, "consrc"));
3257+
3258+
appendPQExpBuffer(q, " CONSTRAINT %s CHECK %s", fmtId(conname), consrc);
3259+
}
3260+
32313261
appendPQExpBuffer(q, ";\n");
32323262

32333263
(*deps)[depIdx++] = NULL; /* End of List */

0 commit comments

Comments
 (0)