Skip to content

Commit 0473296

Browse files
committed
pg_dump: Reorganize dumpBaseType()
Along the same lines as ed2c7f6 and daa9fe8, 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.
1 parent 51c3889 commit 0473296

File tree

1 file changed

+39
-71
lines changed

1 file changed

+39
-71
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 39 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10810,79 +10810,47 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
1081010810
bool typdefault_is_literal = false;
1081110811

1081210812
/* Fetch type-specific details */
10813+
appendPQExpBufferStr(query, "SELECT typlen, "
10814+
"typinput, typoutput, typreceive, typsend, "
10815+
"typreceive::pg_catalog.oid AS typreceiveoid, "
10816+
"typsend::pg_catalog.oid AS typsendoid, "
10817+
"typanalyze, "
10818+
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
10819+
"typdelim, typbyval, typalign, typstorage, ");
10820+
10821+
if (fout->remoteVersion >= 80300)
10822+
appendPQExpBufferStr(query,
10823+
"typmodin, typmodout, "
10824+
"typmodin::pg_catalog.oid AS typmodinoid, "
10825+
"typmodout::pg_catalog.oid AS typmodoutoid, ");
10826+
else
10827+
appendPQExpBufferStr(query,
10828+
"'-' AS typmodin, '-' AS typmodout, "
10829+
"0 AS typmodinoid, 0 AS typmodoutoid, ");
10830+
10831+
if (fout->remoteVersion >= 80400)
10832+
appendPQExpBufferStr(query,
10833+
"typcategory, typispreferred, ");
10834+
else
10835+
appendPQExpBufferStr(query,
10836+
"'U' AS typcategory, false AS typispreferred, ");
10837+
1081310838
if (fout->remoteVersion >= 90100)
10814-
{
10815-
appendPQExpBuffer(query, "SELECT typlen, "
10816-
"typinput, typoutput, typreceive, typsend, "
10817-
"typmodin, typmodout, typanalyze, "
10818-
"typreceive::pg_catalog.oid AS typreceiveoid, "
10819-
"typsend::pg_catalog.oid AS typsendoid, "
10820-
"typmodin::pg_catalog.oid AS typmodinoid, "
10821-
"typmodout::pg_catalog.oid AS typmodoutoid, "
10822-
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
10823-
"typcategory, typispreferred, "
10824-
"typdelim, typbyval, typalign, typstorage, "
10825-
"(typcollation <> 0) AS typcollatable, "
10826-
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10827-
"FROM pg_catalog.pg_type "
10828-
"WHERE oid = '%u'::pg_catalog.oid",
10829-
tyinfo->dobj.catId.oid);
10830-
}
10831-
else if (fout->remoteVersion >= 80400)
10832-
{
10833-
appendPQExpBuffer(query, "SELECT typlen, "
10834-
"typinput, typoutput, typreceive, typsend, "
10835-
"typmodin, typmodout, typanalyze, "
10836-
"typreceive::pg_catalog.oid AS typreceiveoid, "
10837-
"typsend::pg_catalog.oid AS typsendoid, "
10838-
"typmodin::pg_catalog.oid AS typmodinoid, "
10839-
"typmodout::pg_catalog.oid AS typmodoutoid, "
10840-
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
10841-
"typcategory, typispreferred, "
10842-
"typdelim, typbyval, typalign, typstorage, "
10843-
"false AS typcollatable, "
10844-
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10845-
"FROM pg_catalog.pg_type "
10846-
"WHERE oid = '%u'::pg_catalog.oid",
10847-
tyinfo->dobj.catId.oid);
10848-
}
10849-
else if (fout->remoteVersion >= 80300)
10850-
{
10851-
/* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10852-
appendPQExpBuffer(query, "SELECT typlen, "
10853-
"typinput, typoutput, typreceive, typsend, "
10854-
"typmodin, typmodout, typanalyze, "
10855-
"typreceive::pg_catalog.oid AS typreceiveoid, "
10856-
"typsend::pg_catalog.oid AS typsendoid, "
10857-
"typmodin::pg_catalog.oid AS typmodinoid, "
10858-
"typmodout::pg_catalog.oid AS typmodoutoid, "
10859-
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
10860-
"'U' AS typcategory, false AS typispreferred, "
10861-
"typdelim, typbyval, typalign, typstorage, "
10862-
"false AS typcollatable, "
10863-
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10864-
"FROM pg_catalog.pg_type "
10865-
"WHERE oid = '%u'::pg_catalog.oid",
10866-
tyinfo->dobj.catId.oid);
10867-
}
10839+
appendPQExpBufferStr(query, "(typcollation <> 0) AS typcollatable, ");
1086810840
else
10869-
{
10870-
appendPQExpBuffer(query, "SELECT typlen, "
10871-
"typinput, typoutput, typreceive, typsend, "
10872-
"'-' AS typmodin, '-' AS typmodout, "
10873-
"typanalyze, "
10874-
"typreceive::pg_catalog.oid AS typreceiveoid, "
10875-
"typsend::pg_catalog.oid AS typsendoid, "
10876-
"0 AS typmodinoid, 0 AS typmodoutoid, "
10877-
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
10878-
"'U' AS typcategory, false AS typispreferred, "
10879-
"typdelim, typbyval, typalign, typstorage, "
10880-
"false AS typcollatable, "
10881-
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10882-
"FROM pg_catalog.pg_type "
10883-
"WHERE oid = '%u'::pg_catalog.oid",
10884-
tyinfo->dobj.catId.oid);
10885-
}
10841+
appendPQExpBufferStr(query, "false AS typcollatable, ");
10842+
10843+
/* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10844+
if (fout->remoteVersion >= 80400)
10845+
appendPQExpBufferStr(query,
10846+
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault ");
10847+
else
10848+
appendPQExpBufferStr(query,
10849+
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault ");
10850+
10851+
appendPQExpBuffer(query, "FROM pg_catalog.pg_type "
10852+
"WHERE oid = '%u'::pg_catalog.oid",
10853+
tyinfo->dobj.catId.oid);
1088610854

1088710855
res = ExecuteSqlQueryForSingleRow(fout, query->data);
1088810856

0 commit comments

Comments
 (0)