1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Code review for standalone composite types, query-specified composite

types, SRFs.  Not happy with memory management yet, but I'll commit these
other changes.
This commit is contained in:
Tom Lane
2002-08-29 00:17:06 +00:00
parent 7483749d82
commit 64505ed58b
41 changed files with 836 additions and 744 deletions

View File

@@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.294 2002/08/28 20:57:22 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.295 2002/08/29 00:17:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1148,10 +1148,6 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
if (tblinfo[i].relkind == RELKIND_VIEW)
continue;
/* Skip TYPE relations */
if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
continue;
if (tblinfo[i].relkind == RELKIND_SEQUENCE) /* already dumped */
continue;
@@ -1581,7 +1577,8 @@ getTypes(int *numTypes)
"typnamespace, "
"(select usename from pg_user where typowner = usesysid) as usename, "
"typelem, typrelid, "
"(select relkind from pg_class where oid = typrelid) as typrelkind, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
"typtype, typisdefined "
"FROM pg_type");
}
@@ -1591,7 +1588,8 @@ getTypes(int *numTypes)
"0::oid as typnamespace, "
"(select usename from pg_user where typowner = usesysid) as usename, "
"typelem, typrelid, "
"''::char as typrelkind, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
"typtype, typisdefined "
"FROM pg_type");
}
@@ -2120,7 +2118,6 @@ getTables(int *numTables)
}
else if (g_fout->remoteVersion >= 70200)
{
/* before 7.3 there were no type relations with relkind 'c' */
appendPQExpBuffer(query,
"SELECT pg_class.oid, relname, relacl, relkind, "
"0::oid as relnamespace, "
@@ -2392,10 +2389,6 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
if (tbinfo->relkind == RELKIND_SEQUENCE)
continue;
/* Don't bother to collect info for type relations */
if (tbinfo->relkind == RELKIND_COMPOSITE_TYPE)
continue;
/* Don't bother with uninteresting tables, either */
if (!tbinfo->interesting)
continue;
@@ -3210,7 +3203,7 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP DOMAIN %s.",
fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s RESTRICT;\n",
appendPQExpBuffer(delq, "%s;\n",
fmtId(tinfo->typname));
appendPQExpBuffer(q,
@@ -3263,15 +3256,10 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo)
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
int ntups;
char *attname;
char *atttypdefn;
char *attbasetype;
const char *((*deps)[]);
int depIdx = 0;
int i_attname;
int i_atttypdefn;
int i;
deps = malloc(sizeof(char *) * 10);
/* Set proper schema search path so type references list correctly */
selectSourceSchema(tinfo->typnamespace->nspname);
@@ -3279,11 +3267,12 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo)
/* We assume here that remoteVersion must be at least 70300 */
appendPQExpBuffer(query, "SELECT a.attname, "
"pg_catalog.format_type(a.atttypid, a.atttypmod) as atttypdefn, "
"a.atttypid as attbasetype "
"pg_catalog.format_type(a.atttypid, a.atttypmod) as atttypdefn "
"FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a "
"WHERE t.oid = '%s'::pg_catalog.oid "
"AND a.attrelid = t.typrelid",
"AND a.attrelid = t.typrelid "
"AND NOT a.attisdropped "
"ORDER BY a.attnum ",
tinfo->oid);
res = PQexec(g_conn, query->data);
@@ -3302,37 +3291,35 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo)
exit_nicely();
}
/* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s RESTRICT;\n",
fmtId(tinfo->typname));
i_attname = PQfnumber(res, "attname");
i_atttypdefn = PQfnumber(res, "atttypdefn");
appendPQExpBuffer(q,
"CREATE TYPE %s AS (",
appendPQExpBuffer(q, "CREATE TYPE %s AS (",
fmtId(tinfo->typname));
for (i = 0; i < ntups; i++)
{
attname = PQgetvalue(res, i, PQfnumber(res, "attname"));
atttypdefn = PQgetvalue(res, i, PQfnumber(res, "atttypdefn"));
attbasetype = PQgetvalue(res, i, PQfnumber(res, "attbasetype"));
char *attname;
char *atttypdefn;
attname = PQgetvalue(res, i, i_attname);
atttypdefn = PQgetvalue(res, i, i_atttypdefn);
if (i > 0)
appendPQExpBuffer(q, ",\n\t %s %s", attname, atttypdefn);
else
appendPQExpBuffer(q, "%s %s", attname, atttypdefn);
/* Depends on the base type */
(*deps)[depIdx++] = strdup(attbasetype);
appendPQExpBuffer(q, ",\n\t");
appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
}
appendPQExpBuffer(q, ");\n");
(*deps)[depIdx++] = NULL; /* End of List */
/* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s;\n",
fmtId(tinfo->typname));
ArchiveEntry(fout, tinfo->oid, tinfo->typname,
tinfo->typnamespace->nspname,
tinfo->usename, "TYPE", deps,
tinfo->usename, "TYPE", NULL,
q->data, delq->data, NULL, NULL, NULL);
/*** Dump Type Comments ***/
@@ -3365,7 +3352,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
if (!tinfo[i].typnamespace->dump)
continue;
/* skip relation types for non-stand-alone type relations*/
/* skip complex types, except for standalone composite types */
if (atooid(tinfo[i].typrelid) != 0 && tinfo[i].typrelkind != 'c')
continue;
@@ -5046,8 +5033,6 @@ dumpTables(Archive *fout, TableInfo tblinfo[], int numTables,
if (tbinfo->relkind == RELKIND_SEQUENCE) /* already dumped */
continue;
if (tbinfo->relkind == RELKIND_COMPOSITE_TYPE) /* dumped as a type */
continue;
if (tbinfo->dump)
{