Commit 64f3524e authored by Tom Lane's avatar Tom Lane

Remove pg_dump/pg_dumpall support for dumping from pre-8.0 servers.

The need for dumping from such ancient servers has decreased to about nil
in the field, so let's remove all the code that catered to it.  Aside
from removing a lot of boilerplate variant queries, this allows us to not
have to cope with servers that don't have (a) schemas or (b) pg_depend.
That means we can get rid of assorted squishy code around that.  There
may be some nonobvious additional simplifications possible, but this patch
already removes about 1500 lines of code.

I did not remove the ability for pg_restore to read custom-format archives
generated by these old versions (and light testing says that that does
still work).  If you have an old server, you probably also have a pg_dump
that will work with it; but you have an old custom-format backup file,
that might be all you have.

It'd be possible at this point to remove fmtQualifiedId()'s version
argument, but I refrained since that would affect code outside pg_dump.

Discussion: <2661.1475849167@sss.pgh.pa.us>
parent bb55dd60
...@@ -758,10 +758,9 @@ PostgreSQL documentation ...@@ -758,10 +758,9 @@ PostgreSQL documentation
the dump. Instead fail if unable to lock a table within the specified the dump. Instead fail if unable to lock a table within the specified
<replaceable class="parameter">timeout</>. The timeout may be <replaceable class="parameter">timeout</>. The timeout may be
specified in any of the formats accepted by <command>SET specified in any of the formats accepted by <command>SET
statement_timeout</>. (Allowed values vary depending on the server statement_timeout</>. (Allowed formats vary depending on the server
version you are dumping from, but an integer number of milliseconds version you are dumping from, but an integer number of milliseconds
is accepted by all versions since 7.3. This option is ignored when is accepted by all versions.)
dumping from a pre-7.3 server.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1172,7 +1171,7 @@ CREATE DATABASE foo WITH TEMPLATE template0; ...@@ -1172,7 +1171,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
<productname>PostgreSQL</> server versions newer than <productname>PostgreSQL</> server versions newer than
<application>pg_dump</>'s version. <application>pg_dump</> can also <application>pg_dump</>'s version. <application>pg_dump</> can also
dump from <productname>PostgreSQL</> servers older than its own version. dump from <productname>PostgreSQL</> servers older than its own version.
(Currently, servers back to version 7.0 are supported.) (Currently, servers back to version 8.0 are supported.)
However, <application>pg_dump</> cannot dump from However, <application>pg_dump</> cannot dump from
<productname>PostgreSQL</> servers newer than its own major version; <productname>PostgreSQL</> servers newer than its own major version;
it will refuse to even try, rather than risk making an invalid dump. it will refuse to even try, rather than risk making an invalid dump.
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include "fe_utils/string_utils.h" #include "fe_utils/string_utils.h"
#define supports_grant_options(version) ((version) >= 70400)
static bool parseAclItem(const char *item, const char *type, static bool parseAclItem(const char *item, const char *type,
const char *name, const char *subname, int remoteVersion, const char *name, const char *subname, int remoteVersion,
PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer grantee, PQExpBuffer grantor,
...@@ -246,11 +244,9 @@ buildACLCommands(const char *name, const char *subname, ...@@ -246,11 +244,9 @@ buildACLCommands(const char *name, const char *subname,
/* /*
* For the owner, the default privilege level is ALL WITH * For the owner, the default privilege level is ALL WITH
* GRANT OPTION (only ALL prior to 7.4). * GRANT OPTION.
*/ */
if (supports_grant_options(remoteVersion) if (strcmp(privswgo->data, "ALL") != 0)
? strcmp(privswgo->data, "ALL") != 0
: strcmp(privs->data, "ALL") != 0)
{ {
appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix); appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix);
if (subname) if (subname)
...@@ -403,16 +399,19 @@ buildDefaultACLCommands(const char *type, const char *nspname, ...@@ -403,16 +399,19 @@ buildDefaultACLCommands(const char *type, const char *nspname,
* username=privilegecodes/grantor * username=privilegecodes/grantor
* or * or
* group groupname=privilegecodes/grantor * group groupname=privilegecodes/grantor
* (the /grantor part will not be present if pre-7.4 database). * (the "group" case occurs only with servers before 8.1).
*
* Returns true on success, false on parse error. On success, the components
* of the string are returned in the PQExpBuffer parameters.
* *
* The returned grantee string will be the dequoted username or groupname * The returned grantee string will be the dequoted username or groupname
* (preceded with "group " in the latter case). The returned grantor is * (preceded with "group " in the latter case). Note that a grant to PUBLIC
* the dequoted grantor name or empty. Privilege characters are decoded * is represented by an empty grantee string. The returned grantor is the
* and split between privileges with grant option (privswgo) and without * dequoted grantor name. Privilege characters are decoded and split between
* (privs). * privileges with grant option (privswgo) and without (privs).
* *
* Note: for cross-version compatibility, it's important to use ALL when * Note: for cross-version compatibility, it's important to use ALL to
* appropriate. * represent the privilege sets whenever appropriate.
*/ */
static bool static bool
parseAclItem(const char *item, const char *type, parseAclItem(const char *item, const char *type,
...@@ -439,7 +438,7 @@ parseAclItem(const char *item, const char *type, ...@@ -439,7 +438,7 @@ parseAclItem(const char *item, const char *type,
return false; return false;
} }
/* grantor may be listed after / */ /* grantor should appear after / */
slpos = strchr(eqpos + 1, '/'); slpos = strchr(eqpos + 1, '/');
if (slpos) if (slpos)
{ {
...@@ -452,7 +451,10 @@ parseAclItem(const char *item, const char *type, ...@@ -452,7 +451,10 @@ parseAclItem(const char *item, const char *type,
} }
} }
else else
resetPQExpBuffer(grantor); {
free(buf);
return false;
}
/* privilege codes */ /* privilege codes */
#define CONVERT_PRIV(code, keywd) \ #define CONVERT_PRIV(code, keywd) \
...@@ -490,29 +492,19 @@ do { \ ...@@ -490,29 +492,19 @@ do { \
{ {
/* table only */ /* table only */
CONVERT_PRIV('a', "INSERT"); CONVERT_PRIV('a', "INSERT");
if (remoteVersion >= 70200) CONVERT_PRIV('x', "REFERENCES");
CONVERT_PRIV('x', "REFERENCES");
/* rest are not applicable to columns */ /* rest are not applicable to columns */
if (subname == NULL) if (subname == NULL)
{ {
if (remoteVersion >= 70200) CONVERT_PRIV('d', "DELETE");
{ CONVERT_PRIV('t', "TRIGGER");
CONVERT_PRIV('d', "DELETE");
CONVERT_PRIV('t', "TRIGGER");
}
if (remoteVersion >= 80400) if (remoteVersion >= 80400)
CONVERT_PRIV('D', "TRUNCATE"); CONVERT_PRIV('D', "TRUNCATE");
} }
} }
/* UPDATE */ /* UPDATE */
if (remoteVersion >= 70200 || CONVERT_PRIV('w', "UPDATE");
strcmp(type, "SEQUENCE") == 0 ||
strcmp(type, "SEQUENCES") == 0)
CONVERT_PRIV('w', "UPDATE");
else
/* 7.0 and 7.1 have a simpler worldview */
CONVERT_PRIV('w', "UPDATE,DELETE");
} }
else if (strcmp(type, "FUNCTION") == 0 || else if (strcmp(type, "FUNCTION") == 0 ||
strcmp(type, "FUNCTIONS") == 0) strcmp(type, "FUNCTIONS") == 0)
......
...@@ -388,7 +388,7 @@ RestoreArchive(Archive *AHX) ...@@ -388,7 +388,7 @@ RestoreArchive(Archive *AHX)
* target. * target.
*/ */
AHX->minRemoteVersion = 0; AHX->minRemoteVersion = 0;
AHX->maxRemoteVersion = 999999; AHX->maxRemoteVersion = 9999999;
ConnectDatabase(AHX, ropt->dbname, ConnectDatabase(AHX, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username, ropt->pghost, ropt->pgport, ropt->username,
......
...@@ -96,9 +96,6 @@ bool g_verbose; /* User wants verbose narration of our ...@@ -96,9 +96,6 @@ bool g_verbose; /* User wants verbose narration of our
/* subquery used to convert user ID (eg, datdba) to user name */ /* subquery used to convert user ID (eg, datdba) to user name */
static const char *username_subquery; static const char *username_subquery;
/* obsolete as of 7.3: */
static Oid g_last_builtin_oid; /* value of the last builtin oid */
/* The specified names/patterns should to match at least one entity */ /* The specified names/patterns should to match at least one entity */
static int strict_names = 0; static int strict_names = 0;
...@@ -142,7 +139,7 @@ static void expand_table_name_patterns(Archive *fout, ...@@ -142,7 +139,7 @@ static void expand_table_name_patterns(Archive *fout,
SimpleStringList *patterns, SimpleStringList *patterns,
SimpleOidList *oids, SimpleOidList *oids,
bool strict_names); bool strict_names);
static NamespaceInfo *findNamespace(Archive *fout, Oid nsoid, Oid objoid); static NamespaceInfo *findNamespace(Archive *fout, Oid nsoid);
static void dumpTableData(Archive *fout, TableDataInfo *tdinfo); static void dumpTableData(Archive *fout, TableDataInfo *tdinfo);
static void refreshMatViewData(Archive *fout, TableDataInfo *tdinfo); static void refreshMatViewData(Archive *fout, TableDataInfo *tdinfo);
static void guessConstraintInheritance(TableInfo *tblinfo, int numTables); static void guessConstraintInheritance(TableInfo *tblinfo, int numTables);
...@@ -236,11 +233,8 @@ static char *convertRegProcReference(Archive *fout, ...@@ -236,11 +233,8 @@ static char *convertRegProcReference(Archive *fout,
const char *proc); const char *proc);
static char *convertOperatorReference(Archive *fout, const char *opr); static char *convertOperatorReference(Archive *fout, const char *opr);
static char *convertTSFunction(Archive *fout, Oid funcOid); static char *convertTSFunction(Archive *fout, Oid funcOid);
static Oid findLastBuiltinOid_V71(Archive *fout, const char *);
static Oid findLastBuiltinOid_V70(Archive *fout);
static void selectSourceSchema(Archive *fout, const char *schemaName); static void selectSourceSchema(Archive *fout, const char *schemaName);
static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts); static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
static char *myFormatType(const char *typname, int32 typmod);
static void getBlobs(Archive *fout); static void getBlobs(Archive *fout);
static void dumpBlob(Archive *fout, BlobInfo *binfo); static void dumpBlob(Archive *fout, BlobInfo *binfo);
static int dumpBlobs(Archive *fout, void *arg); static int dumpBlobs(Archive *fout, void *arg);
...@@ -633,10 +627,10 @@ main(int argc, char **argv) ...@@ -633,10 +627,10 @@ main(int argc, char **argv)
fout->verbose = g_verbose; fout->verbose = g_verbose;
/* /*
* We allow the server to be back to 7.0, and up to any minor release of * We allow the server to be back to 8.0, and up to any minor release of
* our own major version. (See also version check in pg_dumpall.c.) * our own major version. (See also version check in pg_dumpall.c.)
*/ */
fout->minRemoteVersion = 70000; fout->minRemoteVersion = 80000;
fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99; fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99;
fout->numWorkers = numWorkers; fout->numWorkers = numWorkers;
...@@ -665,10 +659,8 @@ main(int argc, char **argv) ...@@ -665,10 +659,8 @@ main(int argc, char **argv)
/* Select the appropriate subquery to convert user IDs to names */ /* Select the appropriate subquery to convert user IDs to names */
if (fout->remoteVersion >= 80100) if (fout->remoteVersion >= 80100)
username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid ="; username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid =";
else if (fout->remoteVersion >= 70300)
username_subquery = "SELECT usename FROM pg_catalog.pg_user WHERE usesysid =";
else else
username_subquery = "SELECT usename FROM pg_user WHERE usesysid ="; username_subquery = "SELECT usename FROM pg_catalog.pg_user WHERE usesysid =";
/* check the version for the synchronized snapshots feature */ /* check the version for the synchronized snapshots feature */
if (numWorkers > 1 && fout->remoteVersion < 90200 if (numWorkers > 1 && fout->remoteVersion < 90200
...@@ -683,18 +675,6 @@ main(int argc, char **argv) ...@@ -683,18 +675,6 @@ main(int argc, char **argv)
exit_horribly(NULL, exit_horribly(NULL,
"Exported snapshots are not supported by this server version.\n"); "Exported snapshots are not supported by this server version.\n");
/* Find the last built-in OID, if needed */
if (fout->remoteVersion < 70300)
{
if (fout->remoteVersion >= 70100)
g_last_builtin_oid = findLastBuiltinOid_V71(fout,
PQdb(GetConnection(fout)));
else
g_last_builtin_oid = findLastBuiltinOid_V70(fout);
if (g_verbose)
write_msg(NULL, "last built-in OID is %u\n", g_last_builtin_oid);
}
/* Expand schema selection patterns into OID lists */ /* Expand schema selection patterns into OID lists */
if (schema_include_patterns.head != NULL) if (schema_include_patterns.head != NULL)
{ {
...@@ -774,16 +754,11 @@ main(int argc, char **argv) ...@@ -774,16 +754,11 @@ main(int argc, char **argv)
/* /*
* Sort the objects into a safe dump order (no forward references). * Sort the objects into a safe dump order (no forward references).
* *
* In 7.3 or later, we can rely on dependency information to help us * We rely on dependency information to help us determine a safe order, so
* determine a safe order, so the initial sort is mostly for cosmetic * the initial sort is mostly for cosmetic purposes: we sort by name to
* purposes: we sort by name to ensure that logically identical schemas * ensure that logically identical schemas will dump identically.
* will dump identically. Before 7.3 we don't have dependencies and we
* use OID ordering as an (unreliable) guide to creation order.
*/ */
if (fout->remoteVersion >= 70300) sortDumpableObjectsByTypeName(dobjs, numObjs);
sortDumpableObjectsByTypeName(dobjs, numObjs);
else
sortDumpableObjectsByTypeOid(dobjs, numObjs);
/* If we do a parallel dump, we want the largest tables to go first */ /* If we do a parallel dump, we want the largest tables to go first */
if (archiveFormat == archDirectory && numWorkers > 1) if (archiveFormat == archDirectory && numWorkers > 1)
...@@ -1000,12 +975,12 @@ setup_connection(Archive *AH, const char *dumpencoding, ...@@ -1000,12 +975,12 @@ setup_connection(Archive *AH, const char *dumpencoding,
ExecuteSqlStatement(AH, "SET INTERVALSTYLE = POSTGRES"); ExecuteSqlStatement(AH, "SET INTERVALSTYLE = POSTGRES");
/* /*
* If supported, set extra_float_digits so that we can dump float data * Set extra_float_digits so that we can dump float data exactly (given
* exactly (given correctly implemented float I/O code, anyway) * correctly implemented float I/O code, anyway)
*/ */
if (AH->remoteVersion >= 90000) if (AH->remoteVersion >= 90000)
ExecuteSqlStatement(AH, "SET extra_float_digits TO 3"); ExecuteSqlStatement(AH, "SET extra_float_digits TO 3");
else if (AH->remoteVersion >= 70400) else
ExecuteSqlStatement(AH, "SET extra_float_digits TO 2"); ExecuteSqlStatement(AH, "SET extra_float_digits TO 2");
/* /*
...@@ -1018,8 +993,7 @@ setup_connection(Archive *AH, const char *dumpencoding, ...@@ -1018,8 +993,7 @@ setup_connection(Archive *AH, const char *dumpencoding,
/* /*
* Disable timeouts if supported. * Disable timeouts if supported.
*/ */
if (AH->remoteVersion >= 70300) ExecuteSqlStatement(AH, "SET statement_timeout = 0");
ExecuteSqlStatement(AH, "SET statement_timeout = 0");
if (AH->remoteVersion >= 90300) if (AH->remoteVersion >= 90300)
ExecuteSqlStatement(AH, "SET lock_timeout = 0"); ExecuteSqlStatement(AH, "SET lock_timeout = 0");
if (AH->remoteVersion >= 90600) if (AH->remoteVersion >= 90600)
...@@ -1065,16 +1039,12 @@ setup_connection(Archive *AH, const char *dumpencoding, ...@@ -1065,16 +1039,12 @@ setup_connection(Archive *AH, const char *dumpencoding,
"SET TRANSACTION ISOLATION LEVEL " "SET TRANSACTION ISOLATION LEVEL "
"REPEATABLE READ, READ ONLY"); "REPEATABLE READ, READ ONLY");
} }
else if (AH->remoteVersion >= 70400) else
{ {
/* note: comma was not accepted in SET TRANSACTION before 8.0 */
ExecuteSqlStatement(AH, ExecuteSqlStatement(AH,
"SET TRANSACTION ISOLATION LEVEL " "SET TRANSACTION ISOLATION LEVEL "
"SERIALIZABLE READ ONLY"); "SERIALIZABLE, READ ONLY");
} }
else
ExecuteSqlStatement(AH,
"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
/* /*
* If user specified a snapshot to use, select that. In a parallel dump * If user specified a snapshot to use, select that. In a parallel dump
...@@ -1190,9 +1160,6 @@ expand_schema_name_patterns(Archive *fout, ...@@ -1190,9 +1160,6 @@ expand_schema_name_patterns(Archive *fout,
if (patterns->head == NULL) if (patterns->head == NULL)
return; /* nothing to do */ return; /* nothing to do */
if (fout->remoteVersion < 70300)
exit_horribly(NULL, "server version must be at least 7.3 to use schema selection switches\n");
query = createPQExpBuffer(); query = createPQExpBuffer();
/* /*
...@@ -1661,15 +1628,12 @@ dumpTableData_copy(Archive *fout, void *dcontext) ...@@ -1661,15 +1628,12 @@ dumpTableData_copy(Archive *fout, void *dcontext)
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
/* /*
* If possible, specify the column list explicitly so that we have no * Specify the column list explicitly so that we have no possibility of
* possibility of retrieving data in the wrong column order. (The default * retrieving data in the wrong column order. (The default column
* column ordering of COPY will not be what we want in certain corner * ordering of COPY will not be what we want in certain corner cases
* cases involving ADD COLUMN and inheritance.) * involving ADD COLUMN and inheritance.)
*/ */
if (fout->remoteVersion >= 70300) column_list = fmtCopyColumnList(tbinfo, clistBuf);
column_list = fmtCopyColumnList(tbinfo, clistBuf);
else
column_list = ""; /* can't select columns in COPY */
if (oids && hasoids) if (oids && hasoids)
{ {
...@@ -1829,22 +1793,11 @@ dumpTableData_insert(Archive *fout, void *dcontext) ...@@ -1829,22 +1793,11 @@ dumpTableData_insert(Archive *fout, void *dcontext)
*/ */
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
if (fout->remoteVersion >= 70100) appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR "
{ "SELECT * FROM ONLY %s",
appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR " fmtQualifiedId(fout->remoteVersion,
"SELECT * FROM ONLY %s", tbinfo->dobj.namespace->dobj.name,
fmtQualifiedId(fout->remoteVersion, classname));
tbinfo->dobj.namespace->dobj.name,
classname));
}
else
{
appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR "
"SELECT * FROM %s",
fmtQualifiedId(fout->remoteVersion,
tbinfo->dobj.namespace->dobj.name,
classname));
}
if (tdinfo->filtercond) if (tdinfo->filtercond)
appendPQExpBuffer(q, " %s", tdinfo->filtercond); appendPQExpBuffer(q, " %s", tdinfo->filtercond);
...@@ -2480,7 +2433,7 @@ dumpDatabase(Archive *fout) ...@@ -2480,7 +2433,7 @@ dumpDatabase(Archive *fout)
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, fout); appendStringLiteralAH(dbQry, datname, fout);
} }
else if (fout->remoteVersion >= 80000) else
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
...@@ -2492,34 +2445,6 @@ dumpDatabase(Archive *fout) ...@@ -2492,34 +2445,6 @@ dumpDatabase(Archive *fout)
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, fout); appendStringLiteralAH(dbQry, datname, fout);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, "
"0 AS datfrozenxid, 0 AS datminmxid, "
"NULL AS tablespace "
"FROM pg_database "
"WHERE datname = ",
username_subquery);
appendStringLiteralAH(dbQry, datname, fout);
}
else
{
appendPQExpBuffer(dbQry, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_database') AS tableoid, "
"oid, "
"(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, "
"0 AS datfrozenxid, 0 AS datminmxid, "
"NULL AS tablespace "
"FROM pg_database "
"WHERE datname = ",
username_subquery);
appendStringLiteralAH(dbQry, datname, fout);
}
res = ExecuteSqlQueryForSingleRow(fout, dbQry->data); res = ExecuteSqlQueryForSingleRow(fout, dbQry->data);
...@@ -2879,19 +2804,13 @@ getBlobs(Archive *fout) ...@@ -2879,19 +2804,13 @@ getBlobs(Archive *fout)
"NULL AS initrlomacl " "NULL AS initrlomacl "
" FROM pg_largeobject_metadata", " FROM pg_largeobject_metadata",
username_subquery); username_subquery);
else if (fout->remoteVersion >= 70100) else
appendPQExpBufferStr(blobQry, appendPQExpBufferStr(blobQry,
"SELECT DISTINCT loid AS oid, " "SELECT DISTINCT loid AS oid, "
"NULL::name AS rolname, NULL::oid AS lomacl, " "NULL::name AS rolname, NULL::oid AS lomacl, "
"NULL::oid AS rlomacl, NULL::oid AS initlomacl, " "NULL::oid AS rlomacl, NULL::oid AS initlomacl, "
"NULL::oid AS initrlomacl " "NULL::oid AS initrlomacl "
" FROM pg_largeobject"); " FROM pg_largeobject");
else
appendPQExpBufferStr(blobQry,
"SELECT oid, NULL AS rolname, NULL AS lomacl, "
"NULL AS rlomacl, NULL AS initlomacl, "
"NULL AS initrlomacl "
" FROM pg_class WHERE relkind = 'l'");
res = ExecuteSqlQuery(fout, blobQry->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, blobQry->data, PGRES_TUPLES_OK);
...@@ -3031,10 +2950,8 @@ dumpBlobs(Archive *fout, void *arg) ...@@ -3031,10 +2950,8 @@ dumpBlobs(Archive *fout, void *arg)
*/ */
if (fout->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata"; blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata";
else if (fout->remoteVersion >= 70100)
blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
else else
blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_class WHERE relkind = 'l'"; blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
ExecuteSqlStatement(fout, blobQry); ExecuteSqlStatement(fout, blobQry);
...@@ -3536,45 +3453,6 @@ getNamespaces(Archive *fout, int *numNamespaces) ...@@ -3536,45 +3453,6 @@ getNamespaces(Archive *fout, int *numNamespaces)
int i_initnspacl; int i_initnspacl;
int i_initrnspacl; int i_initrnspacl;
/*
* Before 7.3, there are no real namespaces; create two dummy entries, one
* for user stuff and one for system stuff.
*/
if (fout->remoteVersion < 70300)
{
nsinfo = (NamespaceInfo *) pg_malloc(2 * sizeof(NamespaceInfo));
nsinfo[0].dobj.objType = DO_NAMESPACE;
nsinfo[0].dobj.catId.tableoid = 0;
nsinfo[0].dobj.catId.oid = 0;
AssignDumpId(&nsinfo[0].dobj);
nsinfo[0].dobj.name = pg_strdup("public");
nsinfo[0].rolname = pg_strdup("");
nsinfo[0].nspacl = pg_strdup("");
nsinfo[0].rnspacl = pg_strdup("");
nsinfo[0].initnspacl = pg_strdup("");
nsinfo[0].initrnspacl = pg_strdup("");
selectDumpableNamespace(&nsinfo[0], fout);
nsinfo[1].dobj.objType = DO_NAMESPACE;
nsinfo[1].dobj.catId.tableoid = 0;
nsinfo[1].dobj.catId.oid = 1;
AssignDumpId(&nsinfo[1].dobj);
nsinfo[1].dobj.name = pg_strdup("pg_catalog");
nsinfo[1].rolname = pg_strdup("");
nsinfo[1].nspacl = pg_strdup("");
nsinfo[1].rnspacl = pg_strdup("");
nsinfo[1].initnspacl = pg_strdup("");
nsinfo[1].initrnspacl = pg_strdup("");
selectDumpableNamespace(&nsinfo[1], fout);
*numNamespaces = 2;
return nsinfo;
}
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
...@@ -3684,37 +3562,16 @@ getNamespaces(Archive *fout, int *numNamespaces) ...@@ -3684,37 +3562,16 @@ getNamespaces(Archive *fout, int *numNamespaces)
/* /*
* findNamespace: * findNamespace:
* given a namespace OID and an object OID, look up the info read by * given a namespace OID, look up the info read by getNamespaces
* getNamespaces
*
* NB: for pre-7.3 source database, we use object OID to guess whether it's
* a system object or not. In 7.3 and later there is no guessing, and we
* don't use objoid at all.
*/ */
static NamespaceInfo * static NamespaceInfo *
findNamespace(Archive *fout, Oid nsoid, Oid objoid) findNamespace(Archive *fout, Oid nsoid)
{ {
NamespaceInfo *nsinfo; NamespaceInfo *nsinfo;
if (fout->remoteVersion >= 70300) nsinfo = findNamespaceByOid(nsoid);
{
nsinfo = findNamespaceByOid(nsoid);
}
else
{
/* This code depends on the dummy objects set up by getNamespaces. */
Oid i;
if (objoid > g_last_builtin_oid)
i = 0; /* user object */
else
i = 1; /* system object */
nsinfo = findNamespaceByOid(i);
}
if (nsinfo == NULL) if (nsinfo == NULL)
exit_horribly(NULL, "schema with OID %u does not exist\n", nsoid); exit_horribly(NULL, "schema with OID %u does not exist\n", nsoid);
return nsinfo; return nsinfo;
} }
...@@ -3932,7 +3789,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -3932,7 +3789,7 @@ getTypes(Archive *fout, int *numTypes)
"FROM pg_type", "FROM pg_type",
username_subquery); username_subquery);
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, NULL AS typacl, NULL as rtypacl, " "typnamespace, NULL AS typacl, NULL as rtypacl, "
...@@ -3947,38 +3804,6 @@ getTypes(Archive *fout, int *numTypes) ...@@ -3947,38 +3804,6 @@ getTypes(Archive *fout, int *numTypes)
"FROM pg_type", "FROM pg_type",
username_subquery); username_subquery);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"0::oid AS typnamespace, NULL AS typacl, NULL as rtypacl, "
"NULL AS inittypacl, NULL AS initrtypacl, "
"(%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);
}
else
{
appendPQExpBuffer(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_type') AS tableoid, "
"oid, typname, "
"0::oid AS typnamespace, NULL AS typacl, NULL as rtypacl, "
"NULL AS inittypacl, NULL AS initrtypacl, "
"(%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);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -4013,8 +3838,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -4013,8 +3838,7 @@ getTypes(Archive *fout, int *numTypes)
tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname)); tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
tyinfo[i].dobj.namespace = tyinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_typnamespace)), atooid(PQgetvalue(res, i, i_typnamespace)));
tyinfo[i].dobj.catId.oid);
tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tyinfo[i].typacl = pg_strdup(PQgetvalue(res, i, i_typacl)); tyinfo[i].typacl = pg_strdup(PQgetvalue(res, i, i_typacl));
tyinfo[i].rtypacl = pg_strdup(PQgetvalue(res, i, i_rtypacl)); tyinfo[i].rtypacl = pg_strdup(PQgetvalue(res, i, i_rtypacl));
...@@ -4083,48 +3907,6 @@ getTypes(Archive *fout, int *numTypes) ...@@ -4083,48 +3907,6 @@ getTypes(Archive *fout, int *numTypes)
* this is taken care of while sorting dependencies. * this is taken care of while sorting dependencies.
*/ */
stinfo->dobj.dump = DUMP_COMPONENT_NONE; stinfo->dobj.dump = DUMP_COMPONENT_NONE;
/*
* However, if dumping from pre-7.3, there will be no dependency
* info so we have to fake it here. We only need to worry about
* typinput and typoutput since the other functions only exist
* post-7.3.
*/
if (fout->remoteVersion < 70300)
{
Oid typinput;
Oid typoutput;
FuncInfo *funcInfo;
typinput = atooid(PQgetvalue(res, i, i_typinput));
typoutput = atooid(PQgetvalue(res, i, i_typoutput));
funcInfo = findFuncByOid(typinput);
if (funcInfo && funcInfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
{
/* base type depends on function */
addObjectDependency(&tyinfo[i].dobj,
funcInfo->dobj.dumpId);
/* function depends on shell type */
addObjectDependency(&funcInfo->dobj,
stinfo->dobj.dumpId);
/* mark shell type as to be dumped */
stinfo->dobj.dump = DUMP_COMPONENT_ALL;
}
funcInfo = findFuncByOid(typoutput);
if (funcInfo && funcInfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
{
/* base type depends on function */
addObjectDependency(&tyinfo[i].dobj,
funcInfo->dobj.dumpId);
/* function depends on shell type */
addObjectDependency(&funcInfo->dobj,
stinfo->dobj.dumpId);
/* mark shell type as to be dumped */
stinfo->dobj.dump = DUMP_COMPONENT_ALL;
}
}
} }
if (strlen(tyinfo[i].rolname) == 0) if (strlen(tyinfo[i].rolname) == 0)
...@@ -4172,38 +3954,13 @@ getOperators(Archive *fout, int *numOprs) ...@@ -4172,38 +3954,13 @@ getOperators(Archive *fout, int *numOprs)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
{ "oprnamespace, "
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " "(%s oprowner) AS rolname, "
"oprnamespace, " "oprkind, "
"(%s oprowner) AS rolname, " "oprcode::oid AS oprcode "
"oprkind, " "FROM pg_operator",
"oprcode::oid AS oprcode " username_subquery);
"FROM pg_operator",
username_subquery);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
"0::oid AS oprnamespace, "
"(%s oprowner) AS rolname, "
"oprkind, "
"oprcode::oid AS oprcode "
"FROM pg_operator",
username_subquery);
}
else
{
appendPQExpBuffer(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_operator') AS tableoid, "
"oid, oprname, "
"0::oid AS oprnamespace, "
"(%s oprowner) AS rolname, "
"oprkind, "
"oprcode::oid AS oprcode "
"FROM pg_operator",
username_subquery);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -4229,8 +3986,7 @@ getOperators(Archive *fout, int *numOprs) ...@@ -4229,8 +3986,7 @@ getOperators(Archive *fout, int *numOprs)
oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname)); oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
oprinfo[i].dobj.namespace = oprinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_oprnamespace)), atooid(PQgetvalue(res, i, i_oprnamespace)));
oprinfo[i].dobj.catId.oid);
oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0]; oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode)); oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
...@@ -4319,8 +4075,7 @@ getCollations(Archive *fout, int *numCollations) ...@@ -4319,8 +4075,7 @@ getCollations(Archive *fout, int *numCollations)
collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname)); collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
collinfo[i].dobj.namespace = collinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_collnamespace)), atooid(PQgetvalue(res, i, i_collnamespace)));
collinfo[i].dobj.catId.oid);
collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
...@@ -4358,13 +4113,6 @@ getConversions(Archive *fout, int *numConversions) ...@@ -4358,13 +4113,6 @@ getConversions(Archive *fout, int *numConversions)
int i_connamespace; int i_connamespace;
int i_rolname; int i_rolname;
/* Conversions didn't exist pre-7.3 */
if (fout->remoteVersion < 70300)
{
*numConversions = 0;
return NULL;
}
query = createPQExpBuffer(); query = createPQExpBuffer();
/* /*
...@@ -4403,8 +4151,7 @@ getConversions(Archive *fout, int *numConversions) ...@@ -4403,8 +4151,7 @@ getConversions(Archive *fout, int *numConversions)
convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname)); convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
convinfo[i].dobj.namespace = convinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_connamespace)), atooid(PQgetvalue(res, i, i_connamespace)));
convinfo[i].dobj.catId.oid);
convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
...@@ -4527,30 +4274,11 @@ getOpclasses(Archive *fout, int *numOpclasses) ...@@ -4527,30 +4274,11 @@ getOpclasses(Archive *fout, int *numOpclasses)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
{ "opcnamespace, "
appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " "(%s opcowner) AS rolname "
"opcnamespace, " "FROM pg_opclass",
"(%s opcowner) AS rolname " username_subquery);
"FROM pg_opclass",
username_subquery);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
"0::oid AS opcnamespace, "
"''::name AS rolname "
"FROM pg_opclass");
}
else
{
appendPQExpBufferStr(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_opclass') AS tableoid, "
"oid, opcname, "
"0::oid AS opcnamespace, "
"''::name AS rolname "
"FROM pg_opclass");
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -4574,8 +4302,7 @@ getOpclasses(Archive *fout, int *numOpclasses) ...@@ -4574,8 +4302,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname)); opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
opcinfo[i].dobj.namespace = opcinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_opcnamespace)), atooid(PQgetvalue(res, i, i_opcnamespace)));
opcinfo[i].dobj.catId.oid);
opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
...@@ -4584,12 +4311,9 @@ getOpclasses(Archive *fout, int *numOpclasses) ...@@ -4584,12 +4311,9 @@ getOpclasses(Archive *fout, int *numOpclasses)
/* Op Classes do not currently have ACLs. */ /* Op Classes do not currently have ACLs. */
opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL; opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
if (fout->remoteVersion >= 70300) if (strlen(opcinfo[i].rolname) == 0)
{ write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
if (strlen(opcinfo[i].rolname) == 0) opcinfo[i].dobj.name);
write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
opcinfo[i].dobj.name);
}
} }
PQclear(res); PQclear(res);
...@@ -4665,8 +4389,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies) ...@@ -4665,8 +4389,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname)); opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
opfinfo[i].dobj.namespace = opfinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_opfnamespace)), atooid(PQgetvalue(res, i, i_opfnamespace)));
opfinfo[i].dobj.catId.oid);
opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
...@@ -4675,12 +4398,9 @@ getOpfamilies(Archive *fout, int *numOpfamilies) ...@@ -4675,12 +4398,9 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
/* Extensions do not currently have ACLs. */ /* Extensions do not currently have ACLs. */
opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL; opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
if (fout->remoteVersion >= 70300) if (strlen(opfinfo[i].rolname) == 0)
{ write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n",
if (strlen(opfinfo[i].rolname) == 0) opfinfo[i].dobj.name);
write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n",
opfinfo[i].dobj.name);
}
} }
PQclear(res); PQclear(res);
...@@ -4798,7 +4518,7 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4798,7 +4518,7 @@ getAggregates(Archive *fout, int *numAggs)
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBufferChar(query, ')'); appendPQExpBufferChar(query, ')');
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
"pronamespace AS aggnamespace, " "pronamespace AS aggnamespace, "
...@@ -4814,38 +4534,6 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4814,38 +4534,6 @@ getAggregates(Archive *fout, int *numAggs)
"(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')", "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, aggname, "
"0::oid AS aggnamespace, "
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
"aggbasetype AS proargtypes, "
"(%s aggowner) AS rolname, "
"NULL AS aggacl, "
"NULL AS raggacl, "
"NULL AS initaggacl, NULL AS initraggacl "
"FROM pg_aggregate "
"where oid > '%u'::oid",
username_subquery,
g_last_builtin_oid);
}
else
{
appendPQExpBuffer(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_aggregate') AS tableoid, "
"oid, aggname, "
"0::oid AS aggnamespace, "
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
"aggbasetype AS proargtypes, "
"(%s aggowner) AS rolname, "
"NULL AS aggacl, "
"NULL AS raggacl, "
"NULL AS initaggacl, NULL AS initraggacl "
"FROM pg_aggregate "
"where oid > '%u'::oid",
username_subquery,
g_last_builtin_oid);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -4875,8 +4563,7 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4875,8 +4563,7 @@ getAggregates(Archive *fout, int *numAggs)
agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname)); agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
agginfo[i].aggfn.dobj.namespace = agginfo[i].aggfn.dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_aggnamespace)), atooid(PQgetvalue(res, i, i_aggnamespace)));
agginfo[i].aggfn.dobj.catId.oid);
agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
if (strlen(agginfo[i].aggfn.rolname) == 0) if (strlen(agginfo[i].aggfn.rolname) == 0)
write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n", write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n",
...@@ -4893,13 +4580,9 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4893,13 +4580,9 @@ getAggregates(Archive *fout, int *numAggs)
else else
{ {
agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid)); agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
if (fout->remoteVersion >= 70300) parseOidArray(PQgetvalue(res, i, i_proargtypes),
parseOidArray(PQgetvalue(res, i, i_proargtypes), agginfo[i].aggfn.argtypes,
agginfo[i].aggfn.argtypes, agginfo[i].aggfn.nargs);
agginfo[i].aggfn.nargs);
else
/* it's just aggbasetype */
agginfo[i].aggfn.argtypes[0] = atooid(PQgetvalue(res, i, i_proargtypes));
} }
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
...@@ -5025,7 +4708,7 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -5025,7 +4708,7 @@ getFuncs(Archive *fout, int *numFuncs)
destroyPQExpBuffer(initacl_subquery); destroyPQExpBuffer(initacl_subquery);
destroyPQExpBuffer(initracl_subquery); destroyPQExpBuffer(initracl_subquery);
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT tableoid, oid, proname, prolang, " "SELECT tableoid, oid, proname, prolang, "
...@@ -5056,39 +4739,6 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -5056,39 +4739,6 @@ getFuncs(Archive *fout, int *numFuncs)
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBufferChar(query, ')'); appendPQExpBufferChar(query, ')');
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
"SELECT tableoid, oid, proname, prolang, "
"pronargs, proargtypes, prorettype, "
"NULL AS proacl, "
"NULL AS rproacl, "
"NULL as initproacl, NULL AS initrproacl, "
"0::oid AS pronamespace, "
"(%s proowner) AS rolname "
"FROM pg_proc "
"WHERE pg_proc.oid > '%u'::oid",
username_subquery,
g_last_builtin_oid);
}
else
{
appendPQExpBuffer(query,
"SELECT "
"(SELECT oid FROM pg_class "
" WHERE relname = 'pg_proc') AS tableoid, "
"oid, proname, prolang, "
"pronargs, proargtypes, prorettype, "
"NULL AS proacl, "
"NULL AS rproacl, "
"NULL as initproacl, NULL AS initrproacl, "
"0::oid AS pronamespace, "
"(%s proowner) AS rolname "
"FROM pg_proc "
"where pg_proc.oid > '%u'::oid",
username_subquery,
g_last_builtin_oid);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -5121,8 +4771,7 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -5121,8 +4771,7 @@ getFuncs(Archive *fout, int *numFuncs)
finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname)); finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
finfo[i].dobj.namespace = finfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_pronamespace)), atooid(PQgetvalue(res, i, i_pronamespace)));
finfo[i].dobj.catId.oid);
finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang)); finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype)); finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
...@@ -5645,7 +5294,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5645,7 +5294,7 @@ getTables(Archive *fout, int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (fout->remoteVersion >= 80000) else
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -5686,153 +5335,6 @@ getTables(Archive *fout, int *numTables) ...@@ -5686,153 +5335,6 @@ getTables(Archive *fout, int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (fout->remoteVersion >= 70300)
{
/*
* Left join to pick up dependency info linking sequences to their
* owning column, if any
*/
appendPQExpBuffer(query,
"SELECT c.tableoid, c.oid, relname, "
"relacl, NULL as rrelacl, "
"NULL AS initrelacl, NULL AS initrrelacl, "
"relkind, relnamespace, "
"(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, relhasoids, "
"'f'::bool AS relrowsecurity, "
"'f'::bool AS relforcerowsecurity, "
"0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, "
"0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, "
"NULL AS reloftype, "
"d.refobjid AS owning_tab, "
"d.refobjsubid AS owning_col, "
"NULL AS reltablespace, "
"NULL AS reloptions, "
"NULL AS toast_reloptions, "
"NULL AS changed_acl "
"FROM pg_class c "
"LEFT JOIN pg_depend d ON "
"(c.relkind = '%c' AND "
"d.classid = c.tableoid AND d.objid = c.oid AND "
"d.objsubid = 0 AND "
"d.refclassid = c.tableoid AND d.deptype = 'i') "
"WHERE relkind IN ('%c', '%c', '%c', '%c') "
"ORDER BY c.oid",
username_subquery,
RELKIND_SEQUENCE,
RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
}
else if (fout->remoteVersion >= 70200)
{
appendPQExpBuffer(query,
"SELECT tableoid, oid, relname, relacl, "
"NULL as rrelacl, "
"NULL AS initrelacl, NULL AS initrrelacl, "
"relkind, "
"0::oid AS relnamespace, "
"(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, relhasoids, "
"'f'::bool AS relrowsecurity, "
"'f'::bool AS relforcerowsecurity, "
"0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, "
"0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, "
"NULL AS reloftype, "
"NULL::oid AS owning_tab, "
"NULL::int4 AS owning_col, "
"NULL AS reltablespace, "
"NULL AS reloptions, "
"NULL AS toast_reloptions, "
"NULL AS changed_acl "
"FROM pg_class "
"WHERE relkind IN ('%c', '%c', '%c') "
"ORDER BY oid",
username_subquery,
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
}
else if (fout->remoteVersion >= 70100)
{
/* all tables have oids in 7.1 */
appendPQExpBuffer(query,
"SELECT tableoid, oid, relname, relacl, "
"NULL as rrelacl, "
"NULL AS initrelacl, NULL AS initrrelacl, "
"relkind, "
"0::oid AS relnamespace, "
"(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, "
"'t'::bool AS relhasoids, "
"'f'::bool AS relrowsecurity, "
"'f'::bool AS relforcerowsecurity, "
"0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, "
"0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, "
"NULL AS reloftype, "
"NULL::oid AS owning_tab, "
"NULL::int4 AS owning_col, "
"NULL AS reltablespace, "
"NULL AS reloptions, "
"NULL AS toast_reloptions, "
"NULL AS changed_acl "
"FROM pg_class "
"WHERE relkind IN ('%c', '%c', '%c') "
"ORDER BY oid",
username_subquery,
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
}
else
{
/*
* Before 7.1, view relkind was not set to 'v', so we must check if we
* have a view by looking for a rule in pg_rewrite.
*/
appendPQExpBuffer(query,
"SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_class') AS tableoid, "
"oid, relname, relacl, NULL as rrelacl, "
"NULL AS initrelacl, NULL AS initrrelacl, "
"CASE WHEN relhasrules and relkind = 'r' "
" and EXISTS(SELECT rulename FROM pg_rewrite r WHERE "
" r.ev_class = c.oid AND r.ev_type = '1') "
"THEN '%c'::\"char\" "
"ELSE relkind END AS relkind,"
"0::oid AS relnamespace, "
"(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, "
"'t'::bool AS relhasoids, "
"'f'::bool AS relrowsecurity, "
"'f'::bool AS relforcerowsecurity, "
"0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, "
"0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, 0 AS relpages, "
"NULL AS reloftype, "
"NULL::oid AS owning_tab, "
"NULL::int4 AS owning_col, "
"NULL AS reltablespace, "
"NULL AS reloptions, "
"NULL AS toast_reloptions, "
"NULL AS changed_acl "
"FROM pg_class c "
"WHERE relkind IN ('%c', '%c') "
"ORDER BY oid",
RELKIND_VIEW,
username_subquery,
RELKIND_RELATION, RELKIND_SEQUENCE);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -5886,7 +5388,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5886,7 +5388,7 @@ getTables(Archive *fout, int *numTables)
i_reloftype = PQfnumber(res, "reloftype"); i_reloftype = PQfnumber(res, "reloftype");
i_changed_acl = PQfnumber(res, "changed_acl"); i_changed_acl = PQfnumber(res, "changed_acl");
if (dopt->lockWaitTimeout && fout->remoteVersion >= 70300) if (dopt->lockWaitTimeout)
{ {
/* /*
* Arrange to fail instead of waiting forever for a table lock. * Arrange to fail instead of waiting forever for a table lock.
...@@ -5910,8 +5412,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5910,8 +5412,7 @@ getTables(Archive *fout, int *numTables)
tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname)); tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
tblinfo[i].dobj.namespace = tblinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_relnamespace)), atooid(PQgetvalue(res, i, i_relnamespace)));
tblinfo[i].dobj.catId.oid);
tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl)); tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl));
tblinfo[i].rrelacl = pg_strdup(PQgetvalue(res, i, i_rrelacl)); tblinfo[i].rrelacl = pg_strdup(PQgetvalue(res, i, i_rrelacl));
...@@ -6017,7 +5518,7 @@ getTables(Archive *fout, int *numTables) ...@@ -6017,7 +5518,7 @@ getTables(Archive *fout, int *numTables)
tblinfo[i].dobj.name); tblinfo[i].dobj.name);
} }
if (dopt->lockWaitTimeout && fout->remoteVersion >= 70300) if (dopt->lockWaitTimeout)
{ {
ExecuteSqlStatement(fout, "SET statement_timeout = 0"); ExecuteSqlStatement(fout, "SET statement_timeout = 0");
} }
...@@ -6290,7 +5791,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6290,7 +5791,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 80000) else
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -6319,87 +5820,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6319,87 +5820,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300)
{
appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, "
"t.relname AS indexname, "
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
"t.relnatts AS indnkeys, "
"i.indkey, i.indisclustered, "
"false AS indisreplident, t.relpages, "
"c.contype, c.conname, "
"c.condeferrable, c.condeferred, "
"c.tableoid AS contableoid, "
"c.oid AS conoid, "
"null AS condef, "
"NULL AS tablespace, "
"null AS indreloptions "
"FROM pg_catalog.pg_index i "
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
"LEFT JOIN pg_catalog.pg_depend d "
"ON (d.classid = t.tableoid "
"AND d.objid = t.oid "
"AND d.deptype = 'i') "
"LEFT JOIN pg_catalog.pg_constraint c "
"ON (d.refclassid = c.tableoid "
"AND d.refobjid = c.oid) "
"WHERE i.indrelid = '%u'::pg_catalog.oid "
"ORDER BY indexname",
tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, "
"t.relname AS indexname, "
"pg_get_indexdef(i.indexrelid) AS indexdef, "
"t.relnatts AS indnkeys, "
"i.indkey, false AS indisclustered, "
"false AS indisreplident, t.relpages, "
"CASE WHEN i.indisprimary THEN 'p'::char "
"ELSE '0'::char END AS contype, "
"t.relname AS conname, "
"false AS condeferrable, "
"false AS condeferred, "
"0::oid AS contableoid, "
"t.oid AS conoid, "
"null AS condef, "
"NULL AS tablespace, "
"null AS indreloptions "
"FROM pg_index i, pg_class t "
"WHERE t.oid = i.indexrelid "
"AND i.indrelid = '%u'::oid "
"ORDER BY indexname",
tbinfo->dobj.catId.oid);
}
else
{
appendPQExpBuffer(query,
"SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_class') AS tableoid, "
"t.oid, "
"t.relname AS indexname, "
"pg_get_indexdef(i.indexrelid) AS indexdef, "
"t.relnatts AS indnkeys, "
"i.indkey, false AS indisclustered, "
"false AS indisreplident, t.relpages, "
"CASE WHEN i.indisprimary THEN 'p'::char "
"ELSE '0'::char END AS contype, "
"t.relname AS conname, "
"false AS condeferrable, "
"false AS condeferred, "
"0::oid AS contableoid, "
"t.oid AS conoid, "
"null AS condef, "
"NULL AS tablespace, "
"null AS indreloptions "
"FROM pg_index i, pg_class t "
"WHERE t.oid = i.indexrelid "
"AND i.indrelid = '%u'::oid "
"ORDER BY indexname",
tbinfo->dobj.catId.oid);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -6442,19 +5862,9 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6442,19 +5862,9 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys)); indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace)); indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions)); indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnkeys * sizeof(Oid));
/*
* In pre-7.4 releases, indkeys may contain more entries than
* indnkeys says (since indnkeys will be 1 for a functional
* index). We don't actually care about this case since we don't
* examine indkeys except for indexes associated with PRIMARY and
* UNIQUE constraints, which are never functional indexes. But we
* have to allocate enough space to keep parseOidArray from
* complaining.
*/
indxinfo[j].indkeys = (Oid *) pg_malloc(INDEX_MAX_KEYS * sizeof(Oid));
parseOidArray(PQgetvalue(res, j, i_indkey), parseOidArray(PQgetvalue(res, j, i_indkey),
indxinfo[j].indkeys, INDEX_MAX_KEYS); indxinfo[j].indkeys, indxinfo[j].indnkeys);
indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't'); indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't'); indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages)); indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages));
...@@ -6465,9 +5875,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6465,9 +5875,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
/* /*
* If we found a constraint matching the index, create an * If we found a constraint matching the index, create an
* entry for it. * entry for it.
*
* In a pre-7.3 database, we take this path iff the index was
* marked indisprimary.
*/ */
constrinfo[j].dobj.objType = DO_CONSTRAINT; constrinfo[j].dobj.objType = DO_CONSTRAINT;
constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid)); constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
...@@ -6490,10 +5897,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6490,10 +5897,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
constrinfo[j].separate = true; constrinfo[j].separate = true;
indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId; indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId;
/* If pre-7.3 DB, better make sure table comes first */
addObjectDependency(&constrinfo[j].dobj,
tbinfo->dobj.dumpId);
} }
else else
{ {
...@@ -6532,10 +5935,6 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6532,10 +5935,6 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
i_condef; i_condef;
int ntups; int ntups;
/* pg_constraint was created in 7.3, so nothing to do if older */
if (fout->remoteVersion < 70300)
return;
query = createPQExpBuffer(); query = createPQExpBuffer();
for (i = 0; i < numTables; i++) for (i = 0; i < numTables; i++)
...@@ -6621,10 +6020,6 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo) ...@@ -6621,10 +6020,6 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
i_consrc; i_consrc;
int ntups; int ntups;
/* pg_constraint was created in 7.3, so nothing to do if older */
if (fout->remoteVersion < 70300)
return;
/* /*
* select appropriate schema to ensure names in constraint are properly * select appropriate schema to ensure names in constraint are properly
* qualified * qualified
...@@ -6642,17 +6037,9 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo) ...@@ -6642,17 +6037,9 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
"ORDER BY conname", "ORDER BY conname",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
else if (fout->remoteVersion >= 70400)
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
"true as convalidated "
"FROM pg_catalog.pg_constraint "
"WHERE contypid = '%u'::pg_catalog.oid "
"ORDER BY conname",
tyinfo->dobj.catId.oid);
else else
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
"'CHECK (' || consrc || ')' AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
"true as convalidated " "true as convalidated "
"FROM pg_catalog.pg_constraint " "FROM pg_catalog.pg_constraint "
"WHERE contypid = '%u'::pg_catalog.oid " "WHERE contypid = '%u'::pg_catalog.oid "
...@@ -6745,20 +6132,10 @@ getRules(Archive *fout, int *numRules) ...@@ -6745,20 +6132,10 @@ getRules(Archive *fout, int *numRules)
"FROM pg_rewrite " "FROM pg_rewrite "
"ORDER BY oid"); "ORDER BY oid");
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBufferStr(query, "SELECT "
"tableoid, oid, rulename, "
"ev_class AS ruletable, ev_type, is_instead, "
"'O'::char AS ev_enabled "
"FROM pg_rewrite "
"ORDER BY oid");
}
else else
{ {
appendPQExpBufferStr(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_rewrite') AS tableoid, " "tableoid, oid, rulename, "
"oid, rulename, "
"ev_class AS ruletable, ev_type, is_instead, " "ev_class AS ruletable, ev_type, is_instead, "
"'O'::char AS ev_enabled " "'O'::char AS ev_enabled "
"FROM pg_rewrite " "FROM pg_rewrite "
...@@ -6931,7 +6308,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6931,7 +6308,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
"AND tgconstraint = 0", "AND tgconstraint = 0",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300) else
{ {
/* /*
* We ignore triggers that are tied to a foreign-key constraint, * We ignore triggers that are tied to a foreign-key constraint,
...@@ -6954,34 +6331,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -6954,34 +6331,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
" WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))", " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
"SELECT tgname, tgfoid::regproc AS tgfname, "
"tgtype, tgnargs, tgargs, tgenabled, "
"tgisconstraint, tgconstrname, tgdeferrable, "
"tgconstrrelid, tginitdeferred, tableoid, oid, "
"(SELECT relname FROM pg_class WHERE oid = tgconstrrelid) "
" AS tgconstrrelname "
"FROM pg_trigger "
"WHERE tgrelid = '%u'::oid",
tbinfo->dobj.catId.oid);
}
else
{
appendPQExpBuffer(query,
"SELECT tgname, tgfoid::regproc AS tgfname, "
"tgtype, tgnargs, tgargs, tgenabled, "
"tgisconstraint, tgconstrname, tgdeferrable, "
"tgconstrrelid, tginitdeferred, "
"(SELECT oid FROM pg_class WHERE relname = 'pg_trigger') AS tableoid, "
"oid, "
"(SELECT relname FROM pg_class WHERE oid = tgconstrrelid) "
" AS tgconstrrelname "
"FROM pg_trigger "
"WHERE tgrelid = '%u'::oid",
tbinfo->dobj.catId.oid);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
ntups = PQntuples(res); ntups = PQntuples(res);
...@@ -7278,7 +6628,7 @@ getProcLangs(Archive *fout, int *numProcLangs) ...@@ -7278,7 +6628,7 @@ getProcLangs(Archive *fout, int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (fout->remoteVersion >= 70400) else
{ {
/* Languages are owned by the bootstrap superuser, sysid 1 */ /* Languages are owned by the bootstrap superuser, sysid 1 */
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBuffer(query, "SELECT tableoid, oid, "
...@@ -7292,45 +6642,6 @@ getProcLangs(Archive *fout, int *numProcLangs) ...@@ -7292,45 +6642,6 @@ getProcLangs(Archive *fout, int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (fout->remoteVersion >= 70300)
{
/* No clear notion of an owner at all before 7.4 ... */
appendPQExpBuffer(query, "SELECT tableoid, oid, "
"lanname, lanpltrusted, lanplcallfoid, "
"0 AS laninline, lanvalidator, lanacl, "
"NULL AS rlanacl, "
"NULL AS initlanacl, NULL AS initrlanacl, "
"NULL AS lanowner "
"FROM pg_language "
"WHERE lanispl "
"ORDER BY oid");
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, "
"lanname, lanpltrusted, lanplcallfoid, "
"0 AS laninline, 0 AS lanvalidator, NULL AS lanacl, "
"NULL AS rlanacl, "
"NULL AS initlanacl, NULL AS initrlanacl, "
"NULL AS lanowner "
"FROM pg_language "
"WHERE lanispl "
"ORDER BY oid");
}
else
{
appendPQExpBuffer(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_language') AS tableoid, "
"oid, "
"lanname, lanpltrusted, lanplcallfoid, "
"0 AS laninline, 0 AS lanvalidator, NULL AS lanacl, "
"NULL AS rlanacl, "
"NULL AS initlanacl, NULL AS initrlanacl, "
"NULL AS lanowner "
"FROM pg_language "
"WHERE lanispl "
"ORDER BY oid");
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -7379,20 +6690,6 @@ getProcLangs(Archive *fout, int *numProcLangs) ...@@ -7379,20 +6690,6 @@ getProcLangs(Archive *fout, int *numProcLangs)
PQgetisnull(res, i, i_initlanacl) && PQgetisnull(res, i, i_initlanacl) &&
PQgetisnull(res, i, i_initrlanacl)) PQgetisnull(res, i, i_initrlanacl))
planginfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL; planginfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
if (fout->remoteVersion < 70300)
{
/*
* We need to make a dependency to ensure the function will be
* dumped first. (In 7.3 and later the regular dependency
* mechanism will handle this for us.)
*/
FuncInfo *funcInfo = findFuncByOid(planginfo[i].lanplcallfoid);
if (funcInfo)
addObjectDependency(&planginfo[i].dobj,
funcInfo->dobj.dumpId);
}
} }
PQclear(res); PQclear(res);
...@@ -7434,25 +6731,13 @@ getCasts(Archive *fout, int *numCasts) ...@@ -7434,25 +6731,13 @@ getCasts(Archive *fout, int *numCasts)
"castmethod " "castmethod "
"FROM pg_cast ORDER BY 3,4"); "FROM pg_cast ORDER BY 3,4");
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBufferStr(query, "SELECT tableoid, oid, " appendPQExpBufferStr(query, "SELECT tableoid, oid, "
"castsource, casttarget, castfunc, castcontext, " "castsource, casttarget, castfunc, castcontext, "
"CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod " "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
"FROM pg_cast ORDER BY 3,4"); "FROM pg_cast ORDER BY 3,4");
} }
else
{
appendPQExpBufferStr(query, "SELECT 0 AS tableoid, p.oid, "
"t1.oid AS castsource, t2.oid AS casttarget, "
"p.oid AS castfunc, 'e' AS castcontext, "
"'f' AS castmethod "
"FROM pg_type t1, pg_type t2, pg_proc p "
"WHERE p.pronargs = 1 AND "
"p.proargtypes[0] = t1.oid AND "
"p.prorettype = t2.oid AND p.proname = t2.typname "
"ORDER BY 3,4");
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -7499,22 +6784,6 @@ getCasts(Archive *fout, int *numCasts) ...@@ -7499,22 +6784,6 @@ getCasts(Archive *fout, int *numCasts)
sTypeInfo->dobj.name, tTypeInfo->dobj.name); sTypeInfo->dobj.name, tTypeInfo->dobj.name);
castinfo[i].dobj.name = namebuf.data; castinfo[i].dobj.name = namebuf.data;
if (fout->remoteVersion < 70300 &&
OidIsValid(castinfo[i].castfunc))
{
/*
* We need to make a dependency to ensure the function will be
* dumped first. (In 7.3 and later the regular dependency
* mechanism handles this for us.)
*/
FuncInfo *funcInfo;
funcInfo = findFuncByOid(castinfo[i].castfunc);
if (funcInfo)
addObjectDependency(&castinfo[i].dobj,
funcInfo->dobj.dumpId);
}
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
selectDumpableCast(&(castinfo[i]), fout); selectDumpableCast(&(castinfo[i]), fout);
...@@ -7701,10 +6970,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7701,10 +6970,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
/* /*
* we must read the attribute names in attribute number order! because * we must read the attribute names in attribute number order! because
* we will use the attnum to index into the attnames array later. We * we will use the attnum to index into the attnames array later.
* actually ask to order by "attrelid, attnum" because (at least up to
* 7.3) the planner is not smart enough to realize it needn't re-sort
* the output of an indexscan on pg_attribute_relid_attnum_index.
*/ */
if (g_verbose) if (g_verbose)
write_msg(NULL, "finding the columns and types of table \"%s.%s\"\n", write_msg(NULL, "finding the columns and types of table \"%s.%s\"\n",
...@@ -7736,7 +7002,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7736,7 +7002,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ON a.atttypid = t.oid " "ON a.atttypid = t.oid "
"WHERE a.attrelid = '%u'::pg_catalog.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid "
"AND a.attnum > 0::pg_catalog.int2 " "AND a.attnum > 0::pg_catalog.int2 "
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 90100) else if (fout->remoteVersion >= 90100)
...@@ -7760,7 +7026,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7760,7 +7026,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ON a.atttypid = t.oid " "ON a.atttypid = t.oid "
"WHERE a.attrelid = '%u'::pg_catalog.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid "
"AND a.attnum > 0::pg_catalog.int2 " "AND a.attnum > 0::pg_catalog.int2 "
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 90000) else if (fout->remoteVersion >= 90000)
...@@ -7778,10 +7044,10 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7778,10 +7044,10 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ON a.atttypid = t.oid " "ON a.atttypid = t.oid "
"WHERE a.attrelid = '%u'::pg_catalog.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid "
"AND a.attnum > 0::pg_catalog.int2 " "AND a.attnum > 0::pg_catalog.int2 "
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300) else
{ {
/* need left join here to not fail on dropped columns ... */ /* need left join here to not fail on dropped columns ... */
appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, "
...@@ -7795,50 +7061,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7795,50 +7061,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ON a.atttypid = t.oid " "ON a.atttypid = t.oid "
"WHERE a.attrelid = '%u'::pg_catalog.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid "
"AND a.attnum > 0::pg_catalog.int2 " "AND a.attnum > 0::pg_catalog.int2 "
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attnum",
tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
/*
* attstattarget doesn't exist in 7.1. It does exist in 7.2, but
* we don't dump it because we can't tell whether it's been
* explicitly set or was just a default.
*
* attislocal doesn't exist before 7.3, either; in older databases
* we assume it's TRUE, else we'd fail to dump non-inherited atts.
*/
appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, "
"-1 AS attstattarget, a.attstorage, "
"t.typstorage, a.attnotnull, a.atthasdef, "
"false AS attisdropped, a.attlen, "
"a.attalign, true AS attislocal, "
"format_type(t.oid,a.atttypmod) AS atttypname, "
"'' AS attoptions, 0 AS attcollation, "
"NULL AS attfdwoptions "
"FROM pg_attribute a LEFT JOIN pg_type t "
"ON a.atttypid = t.oid "
"WHERE a.attrelid = '%u'::oid "
"AND a.attnum > 0::int2 "
"ORDER BY a.attrelid, a.attnum",
tbinfo->dobj.catId.oid);
}
else
{
/* format_type not available before 7.1 */
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, "
"-1 AS attstattarget, "
"attstorage, attstorage AS typstorage, "
"attnotnull, atthasdef, false AS attisdropped, "
"attlen, attalign, "
"true AS attislocal, "
"(SELECT typname FROM pg_type WHERE oid = atttypid) AS atttypname, "
"'' AS attoptions, 0 AS attcollation, "
"NULL AS attfdwoptions "
"FROM pg_attribute a "
"WHERE attrelid = '%u'::oid "
"AND attnum > 0::int2 "
"ORDER BY attrelid, attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
...@@ -7924,42 +7147,12 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7924,42 +7147,12 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.namespace->dobj.name,
tbinfo->dobj.name); tbinfo->dobj.name);
resetPQExpBuffer(q); printfPQExpBuffer(q, "SELECT tableoid, oid, adnum, "
if (fout->remoteVersion >= 70300)
{
appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, "
"pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc "
"FROM pg_catalog.pg_attrdef " "FROM pg_catalog.pg_attrdef "
"WHERE adrelid = '%u'::pg_catalog.oid", "WHERE adrelid = '%u'::pg_catalog.oid",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70200)
{
/* 7.2 did not have OIDs in pg_attrdef */
appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, adnum, "
"pg_get_expr(adbin, adrelid) AS adsrc "
"FROM pg_attrdef "
"WHERE adrelid = '%u'::oid",
tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
/* no pg_get_expr, so must rely on adsrc */
appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, adsrc "
"FROM pg_attrdef "
"WHERE adrelid = '%u'::oid",
tbinfo->dobj.catId.oid);
}
else
{
/* no pg_get_expr, no tableoid either */
appendPQExpBuffer(q, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_attrdef') AS tableoid, "
"oid, adnum, adsrc "
"FROM pg_attrdef "
"WHERE adrelid = '%u'::oid",
tbinfo->dobj.catId.oid);
}
res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
numDefaults = PQntuples(res); numDefaults = PQntuples(res);
...@@ -8005,17 +7198,11 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -8005,17 +7198,11 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
if (tbinfo->relkind == RELKIND_VIEW) if (tbinfo->relkind == RELKIND_VIEW)
{ {
attrdefs[j].separate = true; attrdefs[j].separate = true;
/* needed in case pre-7.3 DB: */
addObjectDependency(&attrdefs[j].dobj,
tbinfo->dobj.dumpId);
} }
else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1)) else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
{ {
/* column will be suppressed, print default separately */ /* column will be suppressed, print default separately */
attrdefs[j].separate = true; attrdefs[j].separate = true;
/* needed in case pre-7.3 DB: */
addObjectDependency(&attrdefs[j].dobj,
tbinfo->dobj.dumpId);
} }
else else
{ {
...@@ -8077,7 +7264,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -8077,7 +7264,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70400) else
{ {
appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " appendPQExpBuffer(q, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
...@@ -8088,54 +7275,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -8088,54 +7275,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300)
{
/* no pg_get_constraintdef, must use consrc */
appendPQExpBuffer(q, "SELECT tableoid, oid, conname, "
"'CHECK (' || consrc || ')' AS consrc, "
"true AS conislocal, true AS convalidated "
"FROM pg_catalog.pg_constraint "
"WHERE conrelid = '%u'::pg_catalog.oid "
" AND contype = 'c' "
"ORDER BY conname",
tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70200)
{
/* 7.2 did not have OIDs in pg_relcheck */
appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, "
"rcname AS conname, "
"'CHECK (' || rcsrc || ')' AS consrc, "
"true AS conislocal, true AS convalidated "
"FROM pg_relcheck "
"WHERE rcrelid = '%u'::oid "
"ORDER BY rcname",
tbinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(q, "SELECT tableoid, oid, "
"rcname AS conname, "
"'CHECK (' || rcsrc || ')' AS consrc, "
"true AS conislocal, true AS convalidated "
"FROM pg_relcheck "
"WHERE rcrelid = '%u'::oid "
"ORDER BY rcname",
tbinfo->dobj.catId.oid);
}
else
{
/* no tableoid in 7.0 */
appendPQExpBuffer(q, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_relcheck') AS tableoid, "
"oid, rcname AS conname, "
"'CHECK (' || rcsrc || ')' AS consrc, "
"true AS conislocal, true AS convalidated "
"FROM pg_relcheck "
"WHERE rcrelid = '%u'::oid "
"ORDER BY rcname",
tbinfo->dobj.catId.oid);
}
res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
numConstrs = PQntuples(res); numConstrs = PQntuples(res);
...@@ -8303,8 +7443,7 @@ getTSParsers(Archive *fout, int *numTSParsers) ...@@ -8303,8 +7443,7 @@ getTSParsers(Archive *fout, int *numTSParsers)
prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname)); prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
prsinfo[i].dobj.namespace = prsinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_prsnamespace)), atooid(PQgetvalue(res, i, i_prsnamespace)));
prsinfo[i].dobj.catId.oid);
prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart)); prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken)); prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend)); prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
...@@ -8390,8 +7529,7 @@ getTSDictionaries(Archive *fout, int *numTSDicts) ...@@ -8390,8 +7529,7 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname)); dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
dictinfo[i].dobj.namespace = dictinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_dictnamespace)), atooid(PQgetvalue(res, i, i_dictnamespace)));
dictinfo[i].dobj.catId.oid);
dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate)); dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
if (PQgetisnull(res, i, i_dictinitoption)) if (PQgetisnull(res, i, i_dictinitoption))
...@@ -8474,8 +7612,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates) ...@@ -8474,8 +7612,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname)); tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
tmplinfo[i].dobj.namespace = tmplinfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_tmplnamespace)), atooid(PQgetvalue(res, i, i_tmplnamespace)));
tmplinfo[i].dobj.catId.oid);
tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit)); tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize)); tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
...@@ -8555,8 +7692,7 @@ getTSConfigurations(Archive *fout, int *numTSConfigs) ...@@ -8555,8 +7692,7 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname)); cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
cfginfo[i].dobj.namespace = cfginfo[i].dobj.namespace =
findNamespace(fout, findNamespace(fout,
atooid(PQgetvalue(res, i, i_cfgnamespace)), atooid(PQgetvalue(res, i, i_cfgnamespace)));
cfginfo[i].dobj.catId.oid);
cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser)); cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
...@@ -8964,8 +8100,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) ...@@ -8964,8 +8100,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype)); daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
if (nspid != InvalidOid) if (nspid != InvalidOid)
daclinfo[i].dobj.namespace = findNamespace(fout, nspid, daclinfo[i].dobj.namespace = findNamespace(fout, nspid);
daclinfo[i].dobj.catId.oid);
else else
daclinfo[i].dobj.namespace = NULL; daclinfo[i].dobj.namespace = NULL;
...@@ -9173,14 +8308,6 @@ findComments(Archive *fout, Oid classoid, Oid objoid, ...@@ -9173,14 +8308,6 @@ findComments(Archive *fout, Oid classoid, Oid objoid,
if (ncomments < 0) if (ncomments < 0)
ncomments = collectComments(fout, &comments); ncomments = collectComments(fout, &comments);
/*
* Pre-7.2, pg_description does not contain classoid, so collectComments
* just stores a zero. If there's a collision on object OID, well, you
* get duplicate comments.
*/
if (fout->remoteVersion < 70200)
classoid = 0;
/* /*
* Do binary search to find some item matching the object. * Do binary search to find some item matching the object.
*/ */
...@@ -9268,25 +8395,9 @@ collectComments(Archive *fout, CommentItem **items) ...@@ -9268,25 +8395,9 @@ collectComments(Archive *fout, CommentItem **items)
query = createPQExpBuffer(); query = createPQExpBuffer();
if (fout->remoteVersion >= 70300) appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
{ "FROM pg_catalog.pg_description "
appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid " "ORDER BY classoid, objoid, objsubid");
"FROM pg_catalog.pg_description "
"ORDER BY classoid, objoid, objsubid");
}
else if (fout->remoteVersion >= 70200)
{
appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
"FROM pg_description "
"ORDER BY classoid, objoid, objsubid");
}
else
{
/* Note: this will fail to find attribute comments in pre-7.2... */
appendPQExpBufferStr(query, "SELECT description, 0 AS classoid, objoid, 0 AS objsubid "
"FROM pg_description "
"ORDER BY objoid");
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -9468,10 +8579,6 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) ...@@ -9468,10 +8579,6 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
if (!nspinfo->dobj.dump || dopt->dataOnly) if (!nspinfo->dobj.dump || dopt->dataOnly)
return; return;
/* don't dump dummy namespace from pre-7.3 source */
if (strlen(nspinfo->dobj.name) == 0)
return;
q = createPQExpBuffer(); q = createPQExpBuffer();
delq = createPQExpBuffer(); delq = createPQExpBuffer();
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
...@@ -10089,71 +9196,35 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -10089,71 +9196,35 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 80400) else if (fout->remoteVersion >= 80400)
{
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, "
"typmodin, typmodout, typanalyze, "
"typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, "
"typmodin::pg_catalog.oid AS typmodinoid, "
"typmodout::pg_catalog.oid AS typmodoutoid, "
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
"typcategory, typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, "
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 80300)
{
/* Before 8.4, pg_get_expr does not allow 0 for its second arg */
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, "
"typmodin, typmodout, typanalyze, "
"typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, "
"typmodin::pg_catalog.oid AS typmodinoid, "
"typmodout::pg_catalog.oid AS typmodoutoid, "
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 80000)
{ {
appendPQExpBuffer(query, "SELECT typlen, " appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, " "typinput, typoutput, typreceive, typsend, "
"'-' AS typmodin, '-' AS typmodout, " "typmodin, typmodout, typanalyze, "
"typanalyze, "
"typreceive::pg_catalog.oid AS typreceiveoid, " "typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, " "typsend::pg_catalog.oid AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, " "typmodin::pg_catalog.oid AS typmodinoid, "
"typmodout::pg_catalog.oid AS typmodoutoid, "
"typanalyze::pg_catalog.oid AS typanalyzeoid, " "typanalyze::pg_catalog.oid AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, " "typcategory, typispreferred, "
"typdelim, typbyval, typalign, typstorage, " "typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, " "false AS typcollatable, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault " "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
"FROM pg_catalog.pg_type " "FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70400) else if (fout->remoteVersion >= 80300)
{ {
/* Before 8.4, pg_get_expr does not allow 0 for its second arg */
appendPQExpBuffer(query, "SELECT typlen, " appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, " "typinput, typoutput, typreceive, typsend, "
"'-' AS typmodin, '-' AS typmodout, " "typmodin, typmodout, typanalyze, "
"'-' AS typanalyze, "
"typreceive::pg_catalog.oid AS typreceiveoid, " "typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, " "typsend::pg_catalog.oid AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, " "typmodin::pg_catalog.oid AS typmodinoid, "
"0 AS typanalyzeoid, " "typmodout::pg_catalog.oid AS typmodoutoid, "
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, " "'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, typstorage, " "typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, " "false AS typcollatable, "
...@@ -10162,16 +9233,16 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -10162,16 +9233,16 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, "SELECT typlen, " appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, " "typinput, typoutput, typreceive, typsend, "
"'-' AS typreceive, '-' AS typsend, "
"'-' AS typmodin, '-' AS typmodout, " "'-' AS typmodin, '-' AS typmodout, "
"'-' AS typanalyze, " "typanalyze, "
"0 AS typreceiveoid, 0 AS typsendoid, " "typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, " "0 AS typmodinoid, 0 AS typmodoutoid, "
"0 AS typanalyzeoid, " "typanalyze::pg_catalog.oid AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, " "'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, typstorage, " "typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, " "false AS typcollatable, "
...@@ -10180,69 +9251,6 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -10180,69 +9251,6 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70200)
{
/*
* Note: although pre-7.3 catalogs contain typreceive and typsend,
* ignore them because they are not right.
*/
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, "
"'-' AS typreceive, '-' AS typsend, "
"'-' AS typmodin, '-' AS typmodout, "
"'-' AS typanalyze, "
"0 AS typreceiveoid, 0 AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, "
"0 AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, "
"NULL AS typdefaultbin, typdefault "
"FROM pg_type "
"WHERE oid = '%u'::oid",
tyinfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
/*
* Ignore pre-7.2 typdefault; the field exists but has an unusable
* representation.
*/
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, "
"'-' AS typreceive, '-' AS typsend, "
"'-' AS typmodin, '-' AS typmodout, "
"'-' AS typanalyze, "
"0 AS typreceiveoid, 0 AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, "
"0 AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, "
"NULL AS typdefaultbin, NULL AS typdefault "
"FROM pg_type "
"WHERE oid = '%u'::oid",
tyinfo->dobj.catId.oid);
}
else
{
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, "
"'-' AS typreceive, '-' AS typsend, "
"'-' AS typmodin, '-' AS typmodout, "
"'-' AS typanalyze, "
"0 AS typreceiveoid, 0 AS typsendoid, "
"0 AS typmodinoid, 0 AS typmodoutoid, "
"0 AS typanalyzeoid, "
"'U' AS typcategory, false AS typispreferred, "
"typdelim, typbyval, typalign, "
"'p'::char AS typstorage, "
"false AS typcollatable, "
"NULL AS typdefaultbin, NULL AS typdefault "
"FROM pg_type "
"WHERE oid = '%u'::oid",
tyinfo->dobj.catId.oid);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
...@@ -10300,30 +9308,19 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -10300,30 +9308,19 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
qtypname, qtypname,
(strcmp(typlen, "-1") == 0) ? "variable" : typlen); (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
if (fout->remoteVersion >= 70300) /* regproc result is sufficiently quoted already */
{ appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
/* regproc result is correctly quoted as of 7.3 */ appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
appendPQExpBuffer(q, ",\n INPUT = %s", typinput); if (OidIsValid(typreceiveoid))
appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput); appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
if (OidIsValid(typreceiveoid)) if (OidIsValid(typsendoid))
appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive); appendPQExpBuffer(q, ",\n SEND = %s", typsend);
if (OidIsValid(typsendoid)) if (OidIsValid(typmodinoid))
appendPQExpBuffer(q, ",\n SEND = %s", typsend); appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
if (OidIsValid(typmodinoid)) if (OidIsValid(typmodoutoid))
appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin); appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
if (OidIsValid(typmodoutoid)) if (OidIsValid(typanalyzeoid))
appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout); appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
if (OidIsValid(typanalyzeoid))
appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
}
else
{
/* regproc delivers an unquoted name before 7.3 */
/* cannot combine these because fmtId uses static result area */
appendPQExpBuffer(q, ",\n INPUT = %s", fmtId(typinput));
appendPQExpBuffer(q, ",\n OUTPUT = %s", fmtId(typoutput));
/* receive/send/typmodin/typmodout/analyze need not be printed */
}
if (strcmp(typcollatable, "t") == 0) if (strcmp(typcollatable, "t") == 0)
appendPQExpBufferStr(q, ",\n COLLATABLE = true"); appendPQExpBufferStr(q, ",\n COLLATABLE = true");
...@@ -10468,7 +9465,6 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -10468,7 +9465,6 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
} }
else else
{ {
/* We assume here that remoteVersion must be at least 70300 */
appendPQExpBuffer(query, "SELECT typnotnull, " appendPQExpBuffer(query, "SELECT typnotnull, "
"pg_catalog.format_type(typbasetype, typtypmod) AS typdefn, " "pg_catalog.format_type(typbasetype, typtypmod) AS typdefn, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, " "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
...@@ -10669,9 +9665,8 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -10669,9 +9665,8 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
else else
{ {
/* /*
* We assume here that remoteVersion must be at least 70300. Since * Since ALTER TYPE could not drop columns until 9.1, attisdropped
* ALTER TYPE could not drop columns until 9.1, attisdropped should * should always be false.
* always be false.
*/ */
appendPQExpBuffer(query, "SELECT a.attname, " appendPQExpBuffer(query, "SELECT a.attname, "
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, " "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
...@@ -10858,7 +9853,6 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo) ...@@ -10858,7 +9853,6 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* We assume here that remoteVersion must be at least 70300 */
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT c.tableoid, a.attname, a.attnum " "SELECT c.tableoid, a.attname, a.attnum "
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a " "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
...@@ -11442,7 +10436,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -11442,7 +10436,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
finfo->dobj.catId.oid); finfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 80000) else
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT proretset, prosrc, probin, " "SELECT proretset, prosrc, probin, "
...@@ -11458,58 +10452,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -11458,58 +10452,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
finfo->dobj.catId.oid); finfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300)
{
appendPQExpBuffer(query,
"SELECT proretset, prosrc, probin, "
"null AS proallargtypes, "
"null AS proargmodes, "
"null AS proargnames, "
"false AS proiswindow, "
"provolatile, proisstrict, prosecdef, "
"false AS proleakproof, "
"null AS proconfig, 0 AS procost, 0 AS prorows, "
"(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname "
"FROM pg_catalog.pg_proc "
"WHERE oid = '%u'::pg_catalog.oid",
finfo->dobj.catId.oid);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
"SELECT proretset, prosrc, probin, "
"null AS proallargtypes, "
"null AS proargmodes, "
"null AS proargnames, "
"false AS proiswindow, "
"case when proiscachable then 'i' else 'v' end AS provolatile, "
"proisstrict, "
"false AS prosecdef, "
"false AS proleakproof, "
"null AS proconfig, 0 AS procost, 0 AS prorows, "
"(SELECT lanname FROM pg_language WHERE oid = prolang) AS lanname "
"FROM pg_proc "
"WHERE oid = '%u'::oid",
finfo->dobj.catId.oid);
}
else
{
appendPQExpBuffer(query,
"SELECT proretset, prosrc, probin, "
"null AS proallargtypes, "
"null AS proargmodes, "
"null AS proargnames, "
"false AS proiswindow, "
"CASE WHEN proiscachable THEN 'i' ELSE 'v' END AS provolatile, "
"false AS proisstrict, "
"false AS prosecdef, "
"false AS proleakproof, "
"NULL AS proconfig, 0 AS procost, 0 AS prorows, "
"(SELECT lanname FROM pg_language WHERE oid = prolang) AS lanname "
"FROM pg_proc "
"WHERE oid = '%u'::oid",
finfo->dobj.catId.oid);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
...@@ -12082,7 +11024,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12082,7 +11024,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
PQExpBuffer labelq; PQExpBuffer labelq;
PQExpBuffer oprid; PQExpBuffer oprid;
PQExpBuffer details; PQExpBuffer details;
const char *name;
PGresult *res; PGresult *res;
int i_oprkind; int i_oprkind;
int i_oprcode; int i_oprcode;
...@@ -12143,7 +11084,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12143,7 +11084,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
oprinfo->dobj.catId.oid); oprinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, "SELECT oprkind, " appendPQExpBuffer(query, "SELECT oprkind, "
"oprcode::pg_catalog.regprocedure, " "oprcode::pg_catalog.regprocedure, "
...@@ -12159,34 +11100,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12159,34 +11100,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
oprinfo->dobj.catId.oid); oprinfo->dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT oprkind, oprcode, "
"CASE WHEN oprleft = 0 THEN '-' "
"ELSE format_type(oprleft, NULL) END AS oprleft, "
"CASE WHEN oprright = 0 THEN '-' "
"ELSE format_type(oprright, NULL) END AS oprright, "
"oprcom, oprnegate, oprrest, oprjoin, "
"(oprlsortop != 0) AS oprcanmerge, "
"oprcanhash "
"FROM pg_operator "
"WHERE oid = '%u'::oid",
oprinfo->dobj.catId.oid);
}
else
{
appendPQExpBuffer(query, "SELECT oprkind, oprcode, "
"CASE WHEN oprleft = 0 THEN '-'::name "
"ELSE (SELECT typname FROM pg_type WHERE oid = oprleft) END AS oprleft, "
"CASE WHEN oprright = 0 THEN '-'::name "
"ELSE (SELECT typname FROM pg_type WHERE oid = oprright) END AS oprright, "
"oprcom, oprnegate, oprrest, oprjoin, "
"(oprlsortop != 0) AS oprcanmerge, "
"oprcanhash "
"FROM pg_operator "
"WHERE oid = '%u'::oid",
oprinfo->dobj.catId.oid);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
...@@ -12229,12 +11142,8 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12229,12 +11142,8 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
if (strcmp(oprkind, "r") == 0 || if (strcmp(oprkind, "r") == 0 ||
strcmp(oprkind, "b") == 0) strcmp(oprkind, "b") == 0)
{ {
if (fout->remoteVersion >= 70100) appendPQExpBuffer(details, ",\n LEFTARG = %s", oprleft);
name = oprleft; appendPQExpBufferStr(oprid, oprleft);
else
name = fmtId(oprleft);
appendPQExpBuffer(details, ",\n LEFTARG = %s", name);
appendPQExpBufferStr(oprid, name);
} }
else else
appendPQExpBufferStr(oprid, "NONE"); appendPQExpBufferStr(oprid, "NONE");
...@@ -12242,12 +11151,8 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12242,12 +11151,8 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
if (strcmp(oprkind, "l") == 0 || if (strcmp(oprkind, "l") == 0 ||
strcmp(oprkind, "b") == 0) strcmp(oprkind, "b") == 0)
{ {
if (fout->remoteVersion >= 70100) appendPQExpBuffer(details, ",\n RIGHTARG = %s", oprright);
name = oprright; appendPQExpBuffer(oprid, ", %s)", oprright);
else
name = fmtId(oprright);
appendPQExpBuffer(details, ",\n RIGHTARG = %s", name);
appendPQExpBuffer(oprid, ", %s)", name);
} }
else else
appendPQExpBufferStr(oprid, ", NONE)"); appendPQExpBufferStr(oprid, ", NONE)");
...@@ -12334,40 +11239,34 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -12334,40 +11239,34 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
* Returns allocated string of what to print, or NULL if function references * Returns allocated string of what to print, or NULL if function references
* is InvalidOid. Returned string is expected to be free'd by the caller. * is InvalidOid. Returned string is expected to be free'd by the caller.
* *
* In 7.3 the input is a REGPROCEDURE display; we have to strip the * The input is a REGPROCEDURE display; we have to strip the argument-types
* argument-types part. In prior versions, the input is a REGPROC display. * part.
*/ */
static char * static char *
convertRegProcReference(Archive *fout, const char *proc) convertRegProcReference(Archive *fout, const char *proc)
{ {
char *name;
char *paren;
bool inquote;
/* In all cases "-" means a null reference */ /* In all cases "-" means a null reference */
if (strcmp(proc, "-") == 0) if (strcmp(proc, "-") == 0)
return NULL; return NULL;
if (fout->remoteVersion >= 70300) name = pg_strdup(proc);
/* find non-double-quoted left paren */
inquote = false;
for (paren = name; *paren; paren++)
{ {
char *name; if (*paren == '(' && !inquote)
char *paren;
bool inquote;
name = pg_strdup(proc);
/* find non-double-quoted left paren */
inquote = false;
for (paren = name; *paren; paren++)
{ {
if (*paren == '(' && !inquote) *paren = '\0';
{ break;
*paren = '\0';
break;
}
if (*paren == '"')
inquote = !inquote;
} }
return name; if (*paren == '"')
inquote = !inquote;
} }
return name;
/* REGPROC before 7.3 does not quote its result */
return pg_strdup(fmtId(proc));
} }
/* /*
...@@ -12376,60 +11275,44 @@ convertRegProcReference(Archive *fout, const char *proc) ...@@ -12376,60 +11275,44 @@ convertRegProcReference(Archive *fout, const char *proc)
* Returns an allocated string of what to print, or NULL to print nothing. * Returns an allocated string of what to print, or NULL to print nothing.
* Caller is responsible for free'ing result string. * Caller is responsible for free'ing result string.
* *
* In 7.3 and up the input is a REGOPERATOR display; we have to strip the * The input is a REGOPERATOR display; we have to strip the argument-types
* argument-types part, and add OPERATOR() decoration if the name is * part, and add OPERATOR() decoration if the name is schema-qualified.
* schema-qualified. In older versions, the input is just a numeric OID,
* which we search our operator list for.
*/ */
static char * static char *
convertOperatorReference(Archive *fout, const char *opr) convertOperatorReference(Archive *fout, const char *opr)
{ {
OprInfo *oprInfo; char *name;
char *oname;
char *ptr;
bool inquote;
bool sawdot;
/* In all cases "0" means a null reference */ /* In all cases "0" means a null reference */
if (strcmp(opr, "0") == 0) if (strcmp(opr, "0") == 0)
return NULL; return NULL;
if (fout->remoteVersion >= 70300) name = pg_strdup(opr);
{ /* find non-double-quoted left paren, and check for non-quoted dot */
char *name; inquote = false;
char *oname; sawdot = false;
char *ptr; for (ptr = name; *ptr; ptr++)
bool inquote; {
bool sawdot; if (*ptr == '"')
inquote = !inquote;
name = pg_strdup(opr); else if (*ptr == '.' && !inquote)
/* find non-double-quoted left paren, and check for non-quoted dot */ sawdot = true;
inquote = false; else if (*ptr == '(' && !inquote)
sawdot = false;
for (ptr = name; *ptr; ptr++)
{ {
if (*ptr == '"') *ptr = '\0';
inquote = !inquote; break;
else if (*ptr == '.' && !inquote)
sawdot = true;
else if (*ptr == '(' && !inquote)
{
*ptr = '\0';
break;
}
} }
/* If not schema-qualified, don't need to add OPERATOR() */
if (!sawdot)
return name;
oname = psprintf("OPERATOR(%s)", name);
free(name);
return oname;
}
oprInfo = findOprByOid(atooid(opr));
if (oprInfo == NULL)
{
write_msg(NULL, "WARNING: could not find operator with OID %s\n",
opr);
return NULL;
} }
return pg_strdup(oprInfo->dobj.name); /* If not schema-qualified, don't need to add OPERATOR() */
if (!sawdot)
return name;
oname = psprintf("OPERATOR(%s)", name);
free(name);
return oname;
} }
/* /*
...@@ -12586,14 +11469,6 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -12586,14 +11469,6 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
if (!opcinfo->dobj.dump || dopt->dataOnly) if (!opcinfo->dobj.dump || dopt->dataOnly)
return; return;
/*
* XXX currently we do not implement dumping of operator classes from
* pre-7.3 databases. This could be done but it seems not worth the
* trouble.
*/
if (fout->remoteVersion < 70300)
return;
query = createPQExpBuffer(); query = createPQExpBuffer();
q = createPQExpBuffer(); q = createPQExpBuffer();
delq = createPQExpBuffer(); delq = createPQExpBuffer();
...@@ -13343,7 +12218,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -13343,7 +12218,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
appendStringLiteralAH(q, conforencoding, fout); appendStringLiteralAH(q, conforencoding, fout);
appendPQExpBufferStr(q, " TO "); appendPQExpBufferStr(q, " TO ");
appendStringLiteralAH(q, contoencoding, fout); appendStringLiteralAH(q, contoencoding, fout);
/* regproc is automatically quoted in 7.3 and above */ /* regproc output is already sufficiently quoted */
appendPQExpBuffer(q, " FROM %s;\n", conproc); appendPQExpBuffer(q, " FROM %s;\n", conproc);
appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name)); appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
...@@ -13569,7 +12444,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -13569,7 +12444,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
"AND p.oid = '%u'::pg_catalog.oid", "AND p.oid = '%u'::pg_catalog.oid",
agginfo->aggfn.dobj.catId.oid); agginfo->aggfn.dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70300) else
{ {
appendPQExpBuffer(query, "SELECT aggtransfn, " appendPQExpBuffer(query, "SELECT aggtransfn, "
"aggfinalfn, aggtranstype::pg_catalog.regtype, " "aggfinalfn, aggtranstype::pg_catalog.regtype, "
...@@ -13587,41 +12462,6 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -13587,41 +12462,6 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
"AND p.oid = '%u'::pg_catalog.oid", "AND p.oid = '%u'::pg_catalog.oid",
agginfo->aggfn.dobj.catId.oid); agginfo->aggfn.dobj.catId.oid);
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT aggtransfn, aggfinalfn, "
"format_type(aggtranstype, NULL) AS aggtranstype, "
"'-' AS aggcombinefn, '-' AS aggserialfn, "
"'-' AS aggdeserialfn, '-' AS aggmtransfn, "
"'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
"0 AS aggmtranstype, false AS aggfinalextra, "
"false AS aggmfinalextra, 0 AS aggsortop, "
"false AS hypothetical, "
"0 AS aggtransspace, agginitval, "
"0 AS aggmtransspace, NULL AS aggminitval, "
"true AS convertok "
"FROM pg_aggregate "
"WHERE oid = '%u'::oid",
agginfo->aggfn.dobj.catId.oid);
}
else
{
appendPQExpBuffer(query, "SELECT aggtransfn1 AS aggtransfn, "
"aggfinalfn, "
"(SELECT typname FROM pg_type WHERE oid = aggtranstype1) AS aggtranstype, "
"'-' AS aggcombinefn, '-' AS aggserialfn, "
"'-' AS aggdeserialfn, '-' AS aggmtransfn, "
"'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
"0 AS aggmtranstype, false AS aggfinalextra, "
"false AS aggmfinalextra, 0 AS aggsortop, "
"false AS hypothetical, "
"0 AS aggtransspace, agginitval1 AS agginitval, "
"0 AS aggmtransspace, NULL AS aggminitval, "
"(aggtransfn2 = 0 and aggtranstype2 = 0 and agginitval2 is null) AS convertok "
"FROM pg_aggregate "
"WHERE oid = '%u'::oid",
agginfo->aggfn.dobj.catId.oid);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
...@@ -13701,28 +12541,9 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -13701,28 +12541,9 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
return; return;
} }
if (fout->remoteVersion >= 70300) /* regproc and regtype output is already sufficiently quoted */
{ appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
/* If using 7.3's regproc or regtype, data is already quoted */ aggtransfn, aggtranstype);
appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
aggtransfn,
aggtranstype);
}
else if (fout->remoteVersion >= 70100)
{
/* format_type quotes, regproc does not */
appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
fmtId(aggtransfn),
aggtranstype);
}
else
{
/* need quotes all around */
appendPQExpBuffer(details, " SFUNC = %s,\n",
fmtId(aggtransfn));
appendPQExpBuffer(details, " STYPE = %s",
fmtId(aggtranstype));
}
if (strcmp(aggtransspace, "0") != 0) if (strcmp(aggtransspace, "0") != 0)
{ {
...@@ -15121,19 +13942,9 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo) ...@@ -15121,19 +13942,9 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo)
int len; int len;
/* Fetch the view definition */ /* Fetch the view definition */
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query,
{
/* Beginning in 7.3, viewname is not unique; rely on OID */
appendPQExpBuffer(query,
"SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef", "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
}
else
{
appendPQExpBufferStr(query, "SELECT definition AS viewdef "
"FROM pg_views WHERE viewname = ");
appendStringLiteralAH(query, tbinfo->dobj.name, fout);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -15370,17 +14181,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -15370,17 +14181,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{ {
appendPQExpBufferStr(q, " WITH OPTIONS"); appendPQExpBufferStr(q, " WITH OPTIONS");
} }
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(q, " %s",
tbinfo->atttypnames[j]);
}
else else
{ {
/* If no format_type, fake it */
appendPQExpBuffer(q, " %s", appendPQExpBuffer(q, " %s",
myFormatType(tbinfo->atttypnames[j], tbinfo->atttypnames[j]);
tbinfo->atttypmod[j]));
} }
/* Add collation if not default for the type */ /* Add collation if not default for the type */
...@@ -16283,52 +15087,6 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) ...@@ -16283,52 +15087,6 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
destroyPQExpBuffer(labelq); destroyPQExpBuffer(labelq);
} }
/*
* findLastBuiltInOid -
* find the last built in oid
*
* For 7.1 and 7.2, we do this by retrieving datlastsysoid from the
* pg_database entry for the current database
*/
static Oid
findLastBuiltinOid_V71(Archive *fout, const char *dbname)
{
PGresult *res;
Oid last_oid;
PQExpBuffer query = createPQExpBuffer();
resetPQExpBuffer(query);
appendPQExpBufferStr(query, "SELECT datlastsysoid from pg_database where datname = ");
appendStringLiteralAH(query, dbname, fout);
res = ExecuteSqlQueryForSingleRow(fout, query->data);
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid")));
PQclear(res);
destroyPQExpBuffer(query);
return last_oid;
}
/*
* findLastBuiltInOid -
* find the last built in oid
*
* For 7.0, we do this by assuming that the last thing that initdb does is to
* create the pg_indexes view. This sucks in general, but seeing that 7.0.x
* initdb won't be changing anymore, it'll do.
*/
static Oid
findLastBuiltinOid_V70(Archive *fout)
{
PGresult *res;
int last_oid;
res = ExecuteSqlQueryForSingleRow(fout,
"SELECT oid FROM pg_class WHERE relname = 'pg_indexes'");
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
PQclear(res);
return last_oid;
}
/* /*
* dumpSequence * dumpSequence
* write the declaration (not data) of one user-defined sequence * write the declaration (not data) of one user-defined sequence
...@@ -16703,13 +15461,9 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -16703,13 +15461,9 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
{ {
if (OidIsValid(tginfo->tgconstrrelid)) if (OidIsValid(tginfo->tgconstrrelid))
{ {
/* If we are using regclass, name is already quoted */ /* regclass output is already quoted */
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query, " FROM %s\n ",
appendPQExpBuffer(query, " FROM %s\n ", tginfo->tgconstrrelname);
tginfo->tgconstrrelname);
else
appendPQExpBuffer(query, " FROM %s\n ",
fmtId(tginfo->tgconstrrelname));
} }
if (!tginfo->tgdeferrable) if (!tginfo->tgdeferrable)
appendPQExpBufferStr(query, "NOT "); appendPQExpBufferStr(query, "NOT ");
...@@ -16725,13 +15479,9 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -16725,13 +15479,9 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
else else
appendPQExpBufferStr(query, " FOR EACH STATEMENT\n "); appendPQExpBufferStr(query, " FOR EACH STATEMENT\n ");
/* In 7.3, result of regproc is already quoted */ /* regproc output is already sufficiently quoted */
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(",
appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(", tginfo->tgfname);
tginfo->tgfname);
else
appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(",
fmtId(tginfo->tgfname));
tgargs = (char *) PQunescapeBytea((unsigned char *) tginfo->tgargs, tgargs = (char *) PQunescapeBytea((unsigned char *) tginfo->tgargs,
&lentgargs); &lentgargs);
...@@ -16923,19 +15673,9 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -16923,19 +15673,9 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
delcmd = createPQExpBuffer(); delcmd = createPQExpBuffer();
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query,
{ "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid) AS definition",
appendPQExpBuffer(query, rinfo->dobj.catId.oid);
"SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid) AS definition",
rinfo->dobj.catId.oid);
}
else
{
/* Rule name was unique before 7.3 ... */
appendPQExpBuffer(query,
"SELECT pg_get_ruledef('%s') AS definition",
rinfo->dobj.name);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -17325,10 +16065,6 @@ getDependencies(Archive *fout) ...@@ -17325,10 +16065,6 @@ getDependencies(Archive *fout)
DumpableObject *dobj, DumpableObject *dobj,
*refdobj; *refdobj;
/* No dependency info available before 7.3 */
if (fout->remoteVersion < 70300)
return;
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading dependency data\n"); write_msg(NULL, "reading dependency data\n");
...@@ -17680,10 +16416,6 @@ selectSourceSchema(Archive *fout, const char *schemaName) ...@@ -17680,10 +16416,6 @@ selectSourceSchema(Archive *fout, const char *schemaName)
/* This is checked by the callers already */ /* This is checked by the callers already */
Assert(schemaName != NULL && *schemaName != '\0'); Assert(schemaName != NULL && *schemaName != '\0');
/* Not relevant if fetching from pre-7.3 DB */
if (fout->remoteVersion < 70300)
return;
query = createPQExpBuffer(); query = createPQExpBuffer();
appendPQExpBuffer(query, "SET search_path = %s", appendPQExpBuffer(query, "SET search_path = %s",
fmtId(schemaName)); fmtId(schemaName));
...@@ -17699,8 +16431,8 @@ selectSourceSchema(Archive *fout, const char *schemaName) ...@@ -17699,8 +16431,8 @@ selectSourceSchema(Archive *fout, const char *schemaName)
* getFormattedTypeName - retrieve a nicely-formatted type name for the * getFormattedTypeName - retrieve a nicely-formatted type name for the
* given type name. * given type name.
* *
* NB: in 7.3 and up the result may depend on the currently-selected * NB: the result may depend on the currently-selected search_path; this is
* schema; this is why we don't try to cache the names. * why we don't try to cache the names.
*/ */
static char * static char *
getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts) getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
...@@ -17722,36 +16454,13 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts) ...@@ -17722,36 +16454,13 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
} }
query = createPQExpBuffer(); query = createPQExpBuffer();
if (fout->remoteVersion >= 70300) appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
{ oid);
appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
oid);
}
else if (fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query, "SELECT format_type('%u'::oid, NULL)",
oid);
}
else
{
appendPQExpBuffer(query, "SELECT typname "
"FROM pg_type "
"WHERE oid = '%u'::oid",
oid);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
if (fout->remoteVersion >= 70100) /* result of format_type is already quoted */
{ result = pg_strdup(PQgetvalue(res, 0, 0));
/* already quoted */
result = pg_strdup(PQgetvalue(res, 0, 0));
}
else
{
/* may need to quote it */
result = pg_strdup(fmtId(PQgetvalue(res, 0, 0)));
}
PQclear(res); PQclear(res);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
...@@ -17759,76 +16468,6 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts) ...@@ -17759,76 +16468,6 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
return result; return result;
} }
/*
* myFormatType --- local implementation of format_type for use with 7.0.
*/
static char *
myFormatType(const char *typname, int32 typmod)
{
char *result;
bool isarray = false;
PQExpBuffer buf = createPQExpBuffer();
/* Handle array types */
if (typname[0] == '_')
{
isarray = true;
typname++;
}
/* Show lengths on bpchar and varchar */
if (strcmp(typname, "bpchar") == 0)
{
int len = (typmod - VARHDRSZ);
appendPQExpBufferStr(buf, "character");
if (len > 1)
appendPQExpBuffer(buf, "(%d)",
typmod - VARHDRSZ);
}
else if (strcmp(typname, "varchar") == 0)
{
appendPQExpBufferStr(buf, "character varying");
if (typmod != -1)
appendPQExpBuffer(buf, "(%d)",
typmod - VARHDRSZ);
}
else if (strcmp(typname, "numeric") == 0)
{
appendPQExpBufferStr(buf, "numeric");
if (typmod != -1)
{
int32 tmp_typmod;
int precision;
int scale;
tmp_typmod = typmod - VARHDRSZ;
precision = (tmp_typmod >> 16) & 0xffff;
scale = tmp_typmod & 0xffff;
appendPQExpBuffer(buf, "(%d,%d)",
precision, scale);
}
}
/*
* char is an internal single-byte data type; Let's make sure we force it
* through with quotes. - thomas 1998-12-13
*/
else if (strcmp(typname, "char") == 0)
appendPQExpBufferStr(buf, "\"char\"");
else
appendPQExpBufferStr(buf, fmtId(typname));
/* Append array qualifier for array types */
if (isarray)
appendPQExpBufferStr(buf, "[]");
result = pg_strdup(buf->data);
destroyPQExpBuffer(buf);
return result;
}
/* /*
* Return a column list clause for the given relation. * Return a column list clause for the given relation.
* *
......
...@@ -605,7 +605,6 @@ extern void parseOidArray(const char *str, Oid *array, int arraysize); ...@@ -605,7 +605,6 @@ extern void parseOidArray(const char *str, Oid *array, int arraysize);
extern void sortDumpableObjects(DumpableObject **objs, int numObjs, extern void sortDumpableObjects(DumpableObject **objs, int numObjs,
DumpId preBoundaryId, DumpId postBoundaryId); DumpId preBoundaryId, DumpId postBoundaryId);
extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs); extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs); extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
/* /*
......
...@@ -23,63 +23,7 @@ ...@@ -23,63 +23,7 @@
static const char *modulename = gettext_noop("sorter"); static const char *modulename = gettext_noop("sorter");
/* /*
* Sort priority for object types when dumping a pre-7.3 database. * Sort priority for database object types.
* Objects are sorted by priority levels, and within an equal priority level
* by OID. (This is a relatively crude hack to provide semi-reasonable
* behavior for old databases without full dependency info.) Note: collations,
* extensions, text search, foreign-data, materialized view, event trigger,
* policies, transforms, access methods and default ACL objects can't really
* happen here, so the rather bogus priorities for them don't matter.
*
* NOTE: object-type priorities must match the section assignments made in
* pg_dump.c; that is, PRE_DATA objects must sort before DO_PRE_DATA_BOUNDARY,
* POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
* must sort between them.
*/
static const int oldObjectTypePriority[] =
{
1, /* DO_NAMESPACE */
1, /* DO_EXTENSION */
2, /* DO_TYPE */
2, /* DO_SHELL_TYPE */
2, /* DO_FUNC */
3, /* DO_AGG */
3, /* DO_OPERATOR */
3, /* DO_ACCESS_METHOD */
4, /* DO_OPCLASS */
4, /* DO_OPFAMILY */
4, /* DO_COLLATION */
5, /* DO_CONVERSION */
6, /* DO_TABLE */
8, /* DO_ATTRDEF */
15, /* DO_INDEX */
16, /* DO_RULE */
17, /* DO_TRIGGER */
14, /* DO_CONSTRAINT */
18, /* DO_FK_CONSTRAINT */
2, /* DO_PROCLANG */
2, /* DO_CAST */
11, /* DO_TABLE_DATA */
7, /* DO_DUMMY_TYPE */
4, /* DO_TSPARSER */
4, /* DO_TSDICT */
4, /* DO_TSTEMPLATE */
4, /* DO_TSCONFIG */
4, /* DO_FDW */
4, /* DO_FOREIGN_SERVER */
19, /* DO_DEFAULT_ACL */
4, /* DO_TRANSFORM */
9, /* DO_BLOB */
12, /* DO_BLOB_DATA */
10, /* DO_PRE_DATA_BOUNDARY */
13, /* DO_POST_DATA_BOUNDARY */
20, /* DO_EVENT_TRIGGER */
15, /* DO_REFRESH_MATVIEW */
21 /* DO_POLICY */
};
/*
* Sort priority for object types when dumping newer databases.
* Objects are sorted by type, and within a type by name. * Objects are sorted by type, and within a type by name.
* *
* NOTE: object-type priorities must match the section assignments made in * NOTE: object-type priorities must match the section assignments made in
...@@ -87,7 +31,7 @@ static const int oldObjectTypePriority[] = ...@@ -87,7 +31,7 @@ static const int oldObjectTypePriority[] =
* POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects * POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
* must sort between them. * must sort between them.
*/ */
static const int newObjectTypePriority[] = static const int dbObjectTypePriority[] =
{ {
1, /* DO_NAMESPACE */ 1, /* DO_NAMESPACE */
4, /* DO_EXTENSION */ 4, /* DO_EXTENSION */
...@@ -134,7 +78,6 @@ static DumpId postDataBoundId; ...@@ -134,7 +78,6 @@ static DumpId postDataBoundId;
static int DOTypeNameCompare(const void *p1, const void *p2); static int DOTypeNameCompare(const void *p1, const void *p2);
static int DOTypeOidCompare(const void *p1, const void *p2);
static bool TopoSort(DumpableObject **objs, static bool TopoSort(DumpableObject **objs,
int numObjs, int numObjs,
DumpableObject **ordering, DumpableObject **ordering,
...@@ -266,8 +209,8 @@ DOTypeNameCompare(const void *p1, const void *p2) ...@@ -266,8 +209,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
int cmpval; int cmpval;
/* Sort by type */ /* Sort by type */
cmpval = newObjectTypePriority[obj1->objType] - cmpval = dbObjectTypePriority[obj1->objType] -
newObjectTypePriority[obj2->objType]; dbObjectTypePriority[obj2->objType];
if (cmpval != 0) if (cmpval != 0)
return cmpval; return cmpval;
...@@ -345,37 +288,6 @@ DOTypeNameCompare(const void *p1, const void *p2) ...@@ -345,37 +288,6 @@ DOTypeNameCompare(const void *p1, const void *p2)
} }
/*
* Sort the given objects into a type/OID-based ordering
*
* This is used with pre-7.3 source databases as a crude substitute for the
* lack of dependency information.
*/
void
sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs)
{
if (numObjs > 1)
qsort((void *) objs, numObjs, sizeof(DumpableObject *),
DOTypeOidCompare);
}
static int
DOTypeOidCompare(const void *p1, const void *p2)
{
DumpableObject *obj1 = *(DumpableObject *const *) p1;
DumpableObject *obj2 = *(DumpableObject *const *) p2;
int cmpval;
cmpval = oldObjectTypePriority[obj1->objType] -
oldObjectTypePriority[obj2->objType];
if (cmpval != 0)
return cmpval;
return oidcmp(obj1->catId.oid, obj2->catId.oid);
}
/* /*
* Sort the given objects into a safe dump order using dependency * Sort the given objects into a safe dump order using dependency
* information (to the extent we have it available). * information (to the extent we have it available).
......
...@@ -480,10 +480,7 @@ main(int argc, char *argv[]) ...@@ -480,10 +480,7 @@ main(int argc, char *argv[])
dropDBs(conn); dropDBs(conn);
if (!roles_only && !no_tablespaces) if (!roles_only && !no_tablespaces)
{ dropTablespaces(conn);
if (server_version >= 80000)
dropTablespaces(conn);
}
if (!tablespaces_only) if (!tablespaces_only)
dropRoles(conn); dropRoles(conn);
...@@ -505,12 +502,9 @@ main(int argc, char *argv[]) ...@@ -505,12 +502,9 @@ main(int argc, char *argv[])
dumpGroups(conn); dumpGroups(conn);
} }
/* Dump tablespaces */
if (!roles_only && !no_tablespaces) if (!roles_only && !no_tablespaces)
{ dumpTablespaces(conn);
/* Dump tablespaces */
if (server_version >= 80000)
dumpTablespaces(conn);
}
/* Dump CREATE DATABASE commands */ /* Dump CREATE DATABASE commands */
if (binary_upgrade || (!globals_only && !roles_only && !tablespaces_only)) if (binary_upgrade || (!globals_only && !roles_only && !tablespaces_only))
...@@ -886,9 +880,8 @@ dumpRoles(PGconn *conn) ...@@ -886,9 +880,8 @@ dumpRoles(PGconn *conn)
* We do it this way because config settings for roles could mention the * We do it this way because config settings for roles could mention the
* names of other roles. * names of other roles.
*/ */
if (server_version >= 70300) for (i = 0; i < PQntuples(res); i++)
for (i = 0; i < PQntuples(res); i++) dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
PQclear(res); PQclear(res);
...@@ -1204,16 +1197,10 @@ dropDBs(PGconn *conn) ...@@ -1204,16 +1197,10 @@ dropDBs(PGconn *conn)
PGresult *res; PGresult *res;
int i; int i;
if (server_version >= 70100) res = executeQuery(conn,
res = executeQuery(conn, "SELECT datname "
"SELECT datname " "FROM pg_database d "
"FROM pg_database d " "WHERE datallowconn ORDER BY 1");
"WHERE datallowconn ORDER BY 1");
else
res = executeQuery(conn,
"SELECT datname "
"FROM pg_database d "
"ORDER BY 1");
if (PQntuples(res) > 0) if (PQntuples(res) > 0)
fprintf(OPF, "--\n-- Drop databases\n--\n\n"); fprintf(OPF, "--\n-- Drop databases\n--\n\n");
...@@ -1269,12 +1256,10 @@ dumpCreateDB(PGconn *conn) ...@@ -1269,12 +1256,10 @@ dumpCreateDB(PGconn *conn)
* We will dump encoding and locale specifications in the CREATE DATABASE * We will dump encoding and locale specifications in the CREATE DATABASE
* commands for just those databases with values different from defaults. * commands for just those databases with values different from defaults.
* *
* We consider template0's encoding and locale (or, pre-7.1, template1's) * We consider template0's encoding and locale to define the installation
* to define the installation default. Pre-8.4 installations do not have * default. Pre-8.4 installations do not have per-database locale
* per-database locale settings; for them, every database must necessarily * settings; for them, every database must necessarily be using the
* be using the installation default, so there's no need to do anything * installation default, so there's no need to do anything.
* (which is good, since in very old versions there is no good way to find
* out what the installation locale is anyway...)
*/ */
if (server_version >= 80400) if (server_version >= 80400)
res = executeQuery(conn, res = executeQuery(conn,
...@@ -1282,18 +1267,12 @@ dumpCreateDB(PGconn *conn) ...@@ -1282,18 +1267,12 @@ dumpCreateDB(PGconn *conn)
"datcollate, datctype " "datcollate, datctype "
"FROM pg_database " "FROM pg_database "
"WHERE datname = 'template0'"); "WHERE datname = 'template0'");
else if (server_version >= 70100)
res = executeQuery(conn,
"SELECT pg_encoding_to_char(encoding), "
"null::text AS datcollate, null::text AS datctype "
"FROM pg_database "
"WHERE datname = 'template0'");
else else
res = executeQuery(conn, res = executeQuery(conn,
"SELECT pg_encoding_to_char(encoding), " "SELECT pg_encoding_to_char(encoding), "
"null::text AS datcollate, null::text AS datctype " "null::text AS datcollate, null::text AS datctype "
"FROM pg_database " "FROM pg_database "
"WHERE datname = 'template1'"); "WHERE datname = 'template0'");
/* If for some reason the template DB isn't there, treat as unknown */ /* If for some reason the template DB isn't there, treat as unknown */
if (PQntuples(res) > 0) if (PQntuples(res) > 0)
...@@ -1371,7 +1350,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1371,7 +1350,7 @@ dumpCreateDB(PGconn *conn)
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) " "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
"WHERE datallowconn ORDER BY 1"); "WHERE datallowconn ORDER BY 1");
else if (server_version >= 80000) else
res = executeQuery(conn, res = executeQuery(conn,
"SELECT datname, " "SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), " "coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
...@@ -1382,47 +1361,6 @@ dumpCreateDB(PGconn *conn) ...@@ -1382,47 +1361,6 @@ dumpCreateDB(PGconn *conn)
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) " "FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
"WHERE datallowconn ORDER BY 1"); "WHERE datallowconn ORDER BY 1");
else if (server_version >= 70300)
res = executeQuery(conn,
"SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, '' as rdatacl, "
"-1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
"WHERE datallowconn ORDER BY 1");
else if (server_version >= 70100)
res = executeQuery(conn,
"SELECT datname, "
"coalesce("
"(select usename from pg_shadow where usesysid=datdba), "
"(select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"datistemplate, '' as datacl, '' as rdatacl, "
"-1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d "
"WHERE datallowconn ORDER BY 1");
else
{
/*
* Note: 7.0 fails to cope with sub-select in COALESCE, so just deal
* with getting a NULL by not printing any OWNER clause.
*/
res = executeQuery(conn,
"SELECT datname, "
"(select usename from pg_shadow where usesysid=datdba), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"'f' as datistemplate, "
"'' as datacl, '' as rdatacl, -1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d "
"ORDER BY 1");
}
for (i = 0; i < PQntuples(res); i++) for (i = 0; i < PQntuples(res); i++)
{ {
...@@ -1541,8 +1479,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1541,8 +1479,7 @@ dumpCreateDB(PGconn *conn)
fprintf(OPF, "%s", buf->data); fprintf(OPF, "%s", buf->data);
if (server_version >= 70300) dumpDatabaseConfig(conn, dbname);
dumpDatabaseConfig(conn, dbname);
free(fdbname); free(fdbname);
} }
...@@ -1738,10 +1675,7 @@ dumpDatabases(PGconn *conn) ...@@ -1738,10 +1675,7 @@ dumpDatabases(PGconn *conn)
PGresult *res; PGresult *res;
int i; int i;
if (server_version >= 70100) res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1");
res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1");
else
res = executeQuery(conn, "SELECT datname FROM pg_database ORDER BY 1");
for (i = 0; i < PQntuples(res); i++) for (i = 0; i < PQntuples(res); i++)
{ {
...@@ -2062,11 +1996,11 @@ connectDatabase(const char *dbname, const char *connection_string, ...@@ -2062,11 +1996,11 @@ connectDatabase(const char *dbname, const char *connection_string,
my_version = PG_VERSION_NUM; my_version = PG_VERSION_NUM;
/* /*
* We allow the server to be back to 7.0, and up to any minor release of * We allow the server to be back to 8.0, and up to any minor release of
* our own major version. (See also version check in pg_dump.c.) * our own major version. (See also version check in pg_dump.c.)
*/ */
if (my_version != server_version if (my_version != server_version
&& (server_version < 70000 || && (server_version < 80000 ||
(server_version / 100) > (my_version / 100))) (server_version / 100) > (my_version / 100)))
{ {
fprintf(stderr, _("server version: %s; %s version: %s\n"), fprintf(stderr, _("server version: %s; %s version: %s\n"),
...@@ -2076,11 +2010,9 @@ connectDatabase(const char *dbname, const char *connection_string, ...@@ -2076,11 +2010,9 @@ connectDatabase(const char *dbname, const char *connection_string,
} }
/* /*
* On 7.3 and later, make sure we are not fooled by non-system schemas in * Make sure we are not fooled by non-system schemas in the search path.
* the search path.
*/ */
if (server_version >= 70300) executeCommand(conn, "SET search_path = pg_catalog");
executeCommand(conn, "SET search_path = pg_catalog");
return conn; return conn;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment