Commit 04732962 authored by Tom Lane's avatar Tom Lane

pg_dump: Reorganize dumpBaseType()

Along the same lines as ed2c7f65 and daa9fe8a, reduce code duplication
by having just one copy of the parts of the query that are the same
across all server versions; and make the conditionals control the
smallest possible amount of code.  This is in preparation for adding
another dumpable field to pg_type.
parent 51c38898
...@@ -10810,79 +10810,47 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -10810,79 +10810,47 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
bool typdefault_is_literal = false; bool typdefault_is_literal = false;
/* Fetch type-specific details */ /* Fetch type-specific details */
if (fout->remoteVersion >= 90100) appendPQExpBufferStr(query, "SELECT typlen, "
{
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, " "typinput, typoutput, typreceive, typsend, "
"typmodin, typmodout, 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, "
"typmodin::pg_catalog.oid AS typmodinoid, " "typanalyze, "
"typmodout::pg_catalog.oid AS typmodoutoid, "
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
"typcategory, typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"(typcollation <> 0) 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 >= 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, " "typanalyze::pg_catalog.oid AS typanalyzeoid, "
"typcategory, typispreferred, " "typdelim, typbyval, typalign, typstorage, ");
"typdelim, typbyval, typalign, typstorage, "
"false AS typcollatable, " if (fout->remoteVersion >= 80300)
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault " appendPQExpBufferStr(query,
"FROM pg_catalog.pg_type " "typmodin, typmodout, "
"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, " "typmodin::pg_catalog.oid AS typmodinoid, "
"typmodout::pg_catalog.oid AS typmodoutoid, " "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 else
{ appendPQExpBufferStr(query,
appendPQExpBuffer(query, "SELECT typlen, "
"typinput, typoutput, typreceive, typsend, "
"'-' AS typmodin, '-' AS typmodout, " "'-' AS typmodin, '-' AS typmodout, "
"typanalyze, " "0 AS typmodinoid, 0 AS typmodoutoid, ");
"typreceive::pg_catalog.oid AS typreceiveoid, "
"typsend::pg_catalog.oid AS typsendoid, " if (fout->remoteVersion >= 80400)
"0 AS typmodinoid, 0 AS typmodoutoid, " appendPQExpBufferStr(query,
"typanalyze::pg_catalog.oid AS typanalyzeoid, " "typcategory, typispreferred, ");
"'U' AS typcategory, false AS typispreferred, " else
"typdelim, typbyval, typalign, typstorage, " appendPQExpBufferStr(query,
"false AS typcollatable, " "'U' AS typcategory, false AS typispreferred, ");
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
"FROM pg_catalog.pg_type " if (fout->remoteVersion >= 90100)
appendPQExpBufferStr(query, "(typcollation <> 0) AS typcollatable, ");
else
appendPQExpBufferStr(query, "false AS typcollatable, ");
/* Before 8.4, pg_get_expr does not allow 0 for its second arg */
if (fout->remoteVersion >= 80400)
appendPQExpBufferStr(query,
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault ");
else
appendPQExpBufferStr(query,
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault ");
appendPQExpBuffer(query, "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);
}
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
......
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