summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-05-11 17:57:14 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-05-11 17:57:14 +0000
commitbc8036fc666a8f846b1d4b2f935af7edd90eb5aa (patch)
tree7915d1a5cce3d9b5acdff19d8f12382ad5299485 /src/bin
parentb1110aaa8bc7da6f7ebdc12fb550ed378b72ef6e (diff)
downloadpostgresql-bc8036fc666a8f846b1d4b2f935af7edd90eb5aa.tar.gz
Support arrays of composite types, including the rowtypes of regular tables
and views (but not system catalogs, nor sequences or toast tables). Get rid of the hardwired convention that a type's array type is named exactly "_type", instead using a new column pg_type.typarray to provide the linkage. (It still will be named "_type", though, except in odd corner cases such as maximum-length type names.) Along the way, make tracking of owner and schema dependencies for types more uniform: a type directly created by the user has these dependencies, while a table rowtype or auto-generated array type does not have them, but depends on its parent object instead. David Fetter, Andrew Dunstan, Tom Lane
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/pg_dump.c64
-rw-r--r--src/bin/pg_dump/pg_dump.h4
2 files changed, 45 insertions, 23 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 6559506263..64c26c16fb 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.467 2007/04/16 18:42:10 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.468 2007/05/11 17:57:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -963,9 +963,8 @@ selectDumpableType(TypeInfo *tinfo)
else if (!tinfo->isDefined)
tinfo->dobj.dump = false;
- /* skip all array types that start w/ underscore */
- else if ((tinfo->dobj.name[0] == '_') &&
- OidIsValid(tinfo->typelem))
+ /* skip auto-generated array types */
+ else if (tinfo->isArray)
tinfo->dobj.dump = false;
else
@@ -1963,6 +1962,7 @@ getTypes(int *numTypes)
int i_typrelkind;
int i_typtype;
int i_typisdefined;
+ int i_isarray;
/*
* we include even the built-in types because those may be used as array
@@ -1970,13 +1970,20 @@ getTypes(int *numTypes)
*
* we filter out the built-in types when we dump out the types
*
- * same approach for undefined (shell) types
+ * same approach for undefined (shell) types and array types
+ *
+ * Note: as of 8.3 we can reliably detect whether a type is an
+ * auto-generated array type by checking the element type's typarray.
+ * (Before that the test is capable of generating false positives.)
+ * We still check for name beginning with '_', though, so as to avoid
+ * the cost of the subselect probe for all standard types. This would
+ * have to be revisited if the backend ever allows renaming of array types.
*/
/* Make sure we are in proper schema */
selectSourceSchema("pg_catalog");
- if (g_fout->remoteVersion >= 70300)
+ if (g_fout->remoteVersion >= 80300)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, "
@@ -1985,7 +1992,23 @@ getTypes(int *numTypes)
"typoutput::oid as typoutput, typelem, typrelid, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
- "typtype, typisdefined "
+ "typtype, typisdefined, "
+ "typname[0] = '_' AND typelem != 0 AND "
+ "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
+ "FROM pg_type",
+ username_subquery);
+ }
+ else if (g_fout->remoteVersion >= 70300)
+ {
+ appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
+ "typnamespace, "
+ "(%s typowner) as rolname, "
+ "typinput::oid as typinput, "
+ "typoutput::oid as typoutput, typelem, typrelid, "
+ "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
+ "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
+ "typtype, typisdefined, "
+ "typname[0] = '_' AND typelem != 0 AS isarray "
"FROM pg_type",
username_subquery);
}
@@ -1998,7 +2021,8 @@ getTypes(int *numTypes)
"typoutput::oid as typoutput, typelem, typrelid, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
- "typtype, typisdefined "
+ "typtype, typisdefined, "
+ "typname[0] = '_' AND typelem != 0 AS isarray "
"FROM pg_type",
username_subquery);
}
@@ -2013,7 +2037,8 @@ getTypes(int *numTypes)
"typoutput::oid as typoutput, typelem, typrelid, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END as typrelkind, "
- "typtype, typisdefined "
+ "typtype, typisdefined, "
+ "typname[0] = '_' AND typelem != 0 AS isarray "
"FROM pg_type",
username_subquery);
}
@@ -2037,6 +2062,7 @@ getTypes(int *numTypes)
i_typrelkind = PQfnumber(res, "typrelkind");
i_typtype = PQfnumber(res, "typtype");
i_typisdefined = PQfnumber(res, "typisdefined");
+ i_isarray = PQfnumber(res, "isarray");
for (i = 0; i < ntups; i++)
{
@@ -2064,20 +2090,16 @@ getTypes(int *numTypes)
tinfo[i].typrelkind != RELKIND_COMPOSITE_TYPE)
tinfo[i].dobj.objType = DO_TABLE_TYPE;
- /*
- * check for user-defined array types, omit system generated ones
- */
- if (OidIsValid(tinfo[i].typelem) &&
- tinfo[i].dobj.name[0] != '_')
- tinfo[i].isArray = true;
- else
- tinfo[i].isArray = false;
-
if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
tinfo[i].isDefined = true;
else
tinfo[i].isDefined = false;
+ if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
+ tinfo[i].isArray = true;
+ else
+ tinfo[i].isArray = false;
+
/* Decide whether we want to dump it */
selectDumpableType(&tinfo[i]);
@@ -3894,7 +3916,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
else if (g_fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
- "SELECT tgname, tgfoid::pg_catalog.regproc as tgfname, "
+ "SELECT tgname, tgfoid::regproc as tgfname, "
"tgtype, tgnargs, tgargs, tgenabled, "
"tgisconstraint, tgconstrname, tgdeferrable, "
"tgconstrrelid, tginitdeferred, tableoid, oid, "
@@ -3907,7 +3929,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
else
{
appendPQExpBuffer(query,
- "SELECT tgname, tgfoid::pg_catalog.regproc as tgfname, "
+ "SELECT tgname, tgfoid::regproc as tgfname, "
"tgtype, tgnargs, tgargs, tgenabled, "
"tgisconstraint, tgconstrname, tgdeferrable, "
"tgconstrrelid, tginitdeferred, "
@@ -5473,7 +5495,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
appendPQExpBufferStr(q, typdefault);
}
- if (tinfo->isArray)
+ if (OidIsValid(tinfo->typelem))
{
char *elemType;
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index 8694376b52..9575cd5b19 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.134 2007/03/19 23:38:30 wieck Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.135 2007/05/11 17:57:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -164,7 +164,7 @@ typedef struct _typeInfo
Oid typrelid;
char typrelkind; /* 'r', 'v', 'c', etc */
char typtype; /* 'b', 'c', etc */
- bool isArray; /* true if user-defined array type */
+ bool isArray; /* true if auto-generated array type */
bool isDefined; /* true if typisdefined */
/* If it's a dumpable base type, we create a "shell type" entry for it */
struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */