Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb92d055

Browse files
committed
Recent patch to dump nondefault attstorage settings broke pg_dump for
dropped columns. Fix by using LEFT JOIN rather than straight joinbetween pg_attribute and pg_type. Also, use pg_type.oid as input toformat_type, so that we don't get a failure on deleted types of deletedcolumns (this may be a change we ought to backpatch to 7.3....).
1 parent689eb53 commitb92d055

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.337 2003/07/2519:37:21 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.338 2003/07/2521:02:52 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -2371,6 +2371,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
23712371
j,
23722372
k;
23732373
PQExpBufferq=createPQExpBuffer();
2374+
inti_attnum;
23742375
inti_attname;
23752376
inti_atttypname;
23762377
inti_atttypmod;
@@ -2421,12 +2422,13 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24212422

24222423
if (g_fout->remoteVersion >=70300)
24232424
{
2425+
/* need left join here to not fail on dropped columns ... */
24242426
appendPQExpBuffer(q,"SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
2425-
"a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
2426-
"pg_catalog.format_type(a.atttypid,a.atttypmod) as atttypname "
2427-
"from pg_catalog.pg_attribute a, pg_catalog.pg_type t "
2428-
"where a.atttypid = t.oid "
2429-
"and a.attrelid = '%s'::pg_catalog.oid "
2427+
"a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
2428+
"pg_catalog.format_type(t.oid,a.atttypmod) as atttypname "
2429+
"from pg_catalog.pg_attribute a left join pg_catalog.pg_type t "
2430+
"on a.atttypid = t.oid "
2431+
"where a.attrelid = '%s'::pg_catalog.oid "
24302432
"and a.attnum > 0::pg_catalog.int2 "
24312433
"order by a.attrelid, a.attnum",
24322434
tbinfo->oid);
@@ -2439,19 +2441,19 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24392441
* been explicitly set or was just a default.
24402442
*/
24412443
appendPQExpBuffer(q,"SELECT a.attnum, a.attname, a.atttypmod, -1 as attstattarget, a.attstorage, t.typstorage, "
2442-
"a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
2443-
"format_type(a.atttypid,a.atttypmod) as atttypname "
2444-
"from pg_attribute a, pg_type t "
2445-
"where a.atttypid = t.oid "
2446-
"and a.attrelid = '%s'::oid "
2444+
"a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
2445+
"format_type(t.oid,a.atttypmod) as atttypname "
2446+
"from pg_attribute a left join pg_type t "
2447+
"on a.atttypid = t.oid "
2448+
"where a.attrelid = '%s'::oid "
24472449
"and a.attnum > 0::int2 "
24482450
"order by a.attrelid, a.attnum",
24492451
tbinfo->oid);
24502452
}
24512453
else
24522454
{
24532455
/* format_type not available before 7.1 */
2454-
appendPQExpBuffer(q,"SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage,'p' as typstorage, "
2456+
appendPQExpBuffer(q,"SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage,attstorage as typstorage, "
24552457
"attnotnull, atthasdef, false as attisdropped, null as attislocal, "
24562458
"(select typname from pg_type where oid = atttypid) as atttypname "
24572459
"from pg_attribute a "
@@ -2471,6 +2473,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24712473

24722474
ntups=PQntuples(res);
24732475

2476+
i_attnum=PQfnumber(res,"attnum");
24742477
i_attname=PQfnumber(res,"attname");
24752478
i_atttypname=PQfnumber(res,"atttypname");
24762479
i_atttypmod=PQfnumber(res,"atttypmod");
@@ -2501,6 +2504,12 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25012504

25022505
for (j=0;j<ntups;j++)
25032506
{
2507+
if (j+1!=atoi(PQgetvalue(res,j,i_attnum)))
2508+
{
2509+
write_msg(NULL,"invalid attribute numbering in table \"%s\"\n",
2510+
tbinfo->relname);
2511+
exit_nicely();
2512+
}
25042513
tbinfo->attnames[j]=strdup(PQgetvalue(res,j,i_attname));
25052514
tbinfo->atttypnames[j]=strdup(PQgetvalue(res,j,i_atttypname));
25062515
tbinfo->atttypmod[j]=atoi(PQgetvalue(res,j,i_atttypmod));
@@ -5410,7 +5419,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
54105419

54115420
/*
54125421
* Dump per-column storage information. The statement is only dumped if
5413-
* the storage has been changed.
5422+
* the storage has been changed from the type's default.
54145423
*/
54155424
if(!tbinfo->attisdropped[j]&&tbinfo->attstorage[j]!=tbinfo->typstorage[j])
54165425
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp