type-table-pgupgrade.patch
text/x-patch
Filename: type-table-pgupgrade.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_dump.c | 31 | 8 |
diff --git i/src/bin/pg_dump/pg_dump.c w/src/bin/pg_dump/pg_dump.c
index 5561295..4cea954 100644
--- i/src/bin/pg_dump/pg_dump.c
+++ w/src/bin/pg_dump/pg_dump.c
@@ -7889,6 +7889,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
int ntups;
int i_attname;
int i_atttypdefn;
+ int i_attisdropped;
int i_typrelid;
int i;
@@ -7900,11 +7901,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(query, "SELECT a.attname, "
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
+ "a.attisdropped, "
"typrelid "
"FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a "
"WHERE t.oid = '%u'::pg_catalog.oid "
"AND a.attrelid = t.typrelid "
- "AND NOT a.attisdropped "
"ORDER BY a.attnum ",
tyinfo->dobj.catId.oid);
@@ -7915,6 +7916,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
i_attname = PQfnumber(res, "attname");
i_atttypdefn = PQfnumber(res, "atttypdefn");
+ i_attisdropped = PQfnumber(res, "attisdropped");
i_typrelid = PQfnumber(res, "typrelid");
if (binary_upgrade)
@@ -7932,11 +7934,20 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
{
char *attname;
char *atttypdefn;
+ bool attisdropped;
attname = PQgetvalue(res, i, i_attname);
atttypdefn = PQgetvalue(res, i, i_atttypdefn);
+ attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
- appendPQExpBuffer(q, "\n\t%s %s", fmtId(attname), atttypdefn);
+ if (attisdropped)
+ {
+ if (binary_upgrade)
+ /* see under dumpTableSchema() */
+ appendPQExpBuffer(q, "\n\t%s INTEGER /* dummy */", fmtId(attname));
+ }
+ else
+ appendPQExpBuffer(q, "\n\t%s %s", fmtId(attname), atttypdefn);
if (i < ntups - 1)
appendPQExpBuffer(q, ",");
}
@@ -12105,14 +12116,26 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
tbinfo->attlen[j],
tbinfo->attalign[j]);
appendStringLiteralAH(q, tbinfo->attnames[j], fout);
- appendPQExpBuffer(q, "\n AND attrelid = ");
+ appendPQExpBuffer(q, "\n AND attrelid IN (");
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
- appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
+ appendPQExpBuffer(q, "::pg_catalog.regclass");
+ if (tbinfo->reloftype)
+ appendPQExpBuffer(q, ", '%s'::pg_catalog.regclass", tbinfo->reloftype);
+ appendPQExpBuffer(q, ");\n");
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
- fmtId(tbinfo->dobj.name));
- appendPQExpBuffer(q, "DROP COLUMN %s;\n",
- fmtId(tbinfo->attnames[j]));
+ if (tbinfo->reloftype)
+ {
+ appendPQExpBuffer(q, "ALTER TYPE %s ",
+ tbinfo->reloftype);
+ appendPQExpBuffer(q, "DROP ATTRIBUTE %s CASCADE;\n",
+ fmtId(tbinfo->attnames[j]));
+ }
+ else {
+ appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ fmtId(tbinfo->dobj.name));
+ appendPQExpBuffer(q, "DROP COLUMN %s;\n",
+ fmtId(tbinfo->attnames[j]));
+ }
}
else if (!tbinfo->attislocal[j])
{