Skip site navigation (1) Skip section navigation (2)

Patch for pg_dump (6.4) inheritance bug

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: patches(at)postgreSQL(dot)org, hackers(at)postgreSQL(dot)org
Subject: Patch for pg_dump (6.4) inheritance bug
Date: 1998-11-24 23:16:23
Message-ID: 199811242316.XAA01846@linda.lfix.co.uk (view raw or flat)
Thread:
Lists: pgsql-hackers
"Oliver Elphick" wrote:
  >I think this will do the job; can you please check it out:
  
It seems to work, at least for my database, so here is a patch:

*** postgresql-6.4/src/bin/pg_dump/pg_dump.c	Tue Nov 24 23:01:27 1998
--- postgresql-6.4.orig/src/bin/pg_dump/pg_dump.c	Mon Oct 26 01:05:07 1998
***************
*** 1459,1504 ****
  		tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
  		tblinfo[i].ntrig = atoi(PQgetvalue(res, i, i_reltriggers));
  
! 		/* Exclude inherited CHECKs from CHECK constraints total */
! 		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);
! 
! 			sprintf(query, "SELECT * from pg_relcheck, pg_inherits as i "
! 					"where rcrelid = '%s'::oid "
! 					" and exists "
! 					"  (select * from pg_relcheck as c "
! 					"    where c.rcname = pg_relcheck.rcname "
! 					"      and c.rcrelid = i.inhparent) "
! 					" and rcrelid = i.inhrel",
! 					tblinfo[i].oid);
! 			res2 = PQexec(g_conn, query);
! 			if (!res2 ||
! 				PQresultStatus(res2) != PGRES_TUPLES_OK)
! 			{
! 				fprintf(stderr, "getTables(): SELECT (for inherited CHECK) failed\n");
! 				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);
! 			}
! 		}
! 
! 		/* Get CHECK constraints originally defined for this table */
  		if (tblinfo[i].ncheck > 0)
  		{
  			PGresult   *res2;
--- 1459,1465 ----
  		tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
  		tblinfo[i].ntrig = atoi(PQgetvalue(res, i, i_reltriggers));
  
! 		/* Get CHECK constraints */
  		if (tblinfo[i].ncheck > 0)
  		{
  			PGresult   *res2;
***************
*** 1513,1531 ****
  						tblinfo[i].relname,
  						g_comment_end);
  
! 			sprintf(query, "SELECT DISTINCT rcname, rcsrc "
! 					"from pg_relcheck, pg_inherits as i "
! 					"where rcrelid = '%s'::oid "
! 					/* allow all checks from tables that do not inherit */
! 					"  and (not exists "
! 					"    (select * from pg_inherits "
! 					"       where inhrel = pg_relcheck.rcrelid)"
! 					/* and allow checks that are not inherited from other tables */
! 					"         or  (not exists "
! 					"           (select * from pg_relcheck as c "
! 					"             where c.rcname = pg_relcheck.rcname "
! 					"               and c.rcrelid = i.inhparent) "
! 					"         and rcrelid = i.inhrel))",
  					tblinfo[i].oid);
  			res2 = PQexec(g_conn, query);
  			if (!res2 ||
--- 1474,1481 ----
  						tblinfo[i].relname,
  						g_comment_end);
  
! 			sprintf(query, "SELECT rcname, rcsrc from pg_relcheck "
! 					"where rcrelid = '%s'::oid ",
  					tblinfo[i].oid);
  			res2 = PQexec(g_conn, query);
  			if (!res2 ||

-- 
Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "Jesus saith unto him, I am the way, the truth, and the
      life; no man cometh unto the Father, but by me."      
                                         John 14:6 


Responses

pgsql-hackers by date

Next:From: Mail Delivery SubsystemDate: 1998-11-25 01:25:26
Subject: Returned mail: User unknown
Previous:From: Oliver ElphickDate: 1998-11-24 19:22:02
Subject: Re: [HACKERS] Parser bug?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group