mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
pg_dump: Reorganize dumpBaseType()
Along the same lines ased2c7f65b
anddaa9fe8a5
, 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.
This commit is contained in:
@ -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, "
|
|
||||||
"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, "
|
|
||||||
"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
|
|
||||||
{
|
|
||||||
appendPQExpBuffer(query, "SELECT typlen, "
|
|
||||||
"typinput, typoutput, typreceive, typsend, "
|
|
||||||
"'-' AS typmodin, '-' AS typmodout, "
|
|
||||||
"typanalyze, "
|
"typanalyze, "
|
||||||
"typreceive::pg_catalog.oid AS typreceiveoid, "
|
|
||||||
"typsend::pg_catalog.oid AS typsendoid, "
|
|
||||||
"0 AS typmodinoid, 0 AS typmodoutoid, "
|
|
||||||
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
|
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
|
||||||
"'U' AS typcategory, false AS typispreferred, "
|
"typdelim, typbyval, typalign, typstorage, ");
|
||||||
"typdelim, typbyval, typalign, typstorage, "
|
|
||||||
"false AS typcollatable, "
|
if (fout->remoteVersion >= 80300)
|
||||||
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
|
appendPQExpBufferStr(query,
|
||||||
"FROM pg_catalog.pg_type "
|
"typmodin, typmodout, "
|
||||||
|
"typmodin::pg_catalog.oid AS typmodinoid, "
|
||||||
|
"typmodout::pg_catalog.oid AS typmodoutoid, ");
|
||||||
|
else
|
||||||
|
appendPQExpBufferStr(query,
|
||||||
|
"'-' AS typmodin, '-' AS typmodout, "
|
||||||
|
"0 AS typmodinoid, 0 AS typmodoutoid, ");
|
||||||
|
|
||||||
|
if (fout->remoteVersion >= 80400)
|
||||||
|
appendPQExpBufferStr(query,
|
||||||
|
"typcategory, typispreferred, ");
|
||||||
|
else
|
||||||
|
appendPQExpBufferStr(query,
|
||||||
|
"'U' AS typcategory, false AS typispreferred, ");
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user