diff options
| author | Tom Lane | 2010-10-25 03:04:37 +0000 |
|---|---|---|
| committer | Tom Lane | 2010-10-25 03:05:41 +0000 |
| commit | 84c123be1de8a9955741e20c9f945571e40c545e (patch) | |
| tree | 6ea497e47ec62ef8e1ee83b9acfe1fcd2b2419d6 /src/bin | |
| parent | 24b29ca8f9dc4a5e5f873f0fcb56438c526700f6 (diff) | |
Allow new values to be added to an existing enum type.
After much expenditure of effort, we've got this to the point where the
performance penalty is pretty minimal in typical cases.
Andrew Dunstan, reviewed by Brendan Jurd, Dean Rasheed, and Tom Lane
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 33 | ||||
| -rw-r--r-- | src/bin/psql/describe.c | 14 |
2 files changed, 33 insertions, 14 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 6a4557b4861..55ea6841a44 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -6657,14 +6657,21 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) Oid enum_oid; char *label; - /* Set proper schema search path so regproc references list correctly */ - selectSourceSchema(tyinfo->dobj.namespace->dobj.name); + /* Set proper schema search path */ + selectSourceSchema("pg_catalog"); - appendPQExpBuffer(query, "SELECT oid, enumlabel " - "FROM pg_catalog.pg_enum " - "WHERE enumtypid = '%u'" - "ORDER BY oid", - tyinfo->dobj.catId.oid); + if (fout->remoteVersion >= 90100) + appendPQExpBuffer(query, "SELECT oid, enumlabel " + "FROM pg_catalog.pg_enum " + "WHERE enumtypid = '%u'" + "ORDER BY enumsortorder", + tyinfo->dobj.catId.oid); + else + appendPQExpBuffer(query, "SELECT oid, enumlabel " + "FROM pg_catalog.pg_enum " + "WHERE enumtypid = '%u'" + "ORDER BY oid", + tyinfo->dobj.catId.oid); res = PQexec(g_conn, query->data); check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); @@ -6713,13 +6720,15 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) if (i == 0) appendPQExpBuffer(q, "\n-- For binary upgrade, must preserve pg_enum oids\n"); appendPQExpBuffer(q, - "SELECT binary_upgrade.add_pg_enum_label('%u'::pg_catalog.oid, " - "'%u'::pg_catalog.oid, ", - enum_oid, tyinfo->dobj.catId.oid); + "SELECT binary_upgrade.set_next_pg_enum_oid('%u'::pg_catalog.oid);\n", + enum_oid); + appendPQExpBuffer(q, "ALTER TYPE %s.", + fmtId(tyinfo->dobj.namespace->dobj.name)); + appendPQExpBuffer(q, "%s ADD ", + fmtId(tyinfo->dobj.name)); appendStringLiteralAH(q, label, fout); - appendPQExpBuffer(q, ");\n"); + appendPQExpBuffer(q, ";\n\n"); } - appendPQExpBuffer(q, "\n"); } ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 57d74e14d75..b705cb29dd4 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -473,17 +473,27 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) gettext_noop("Internal name"), gettext_noop("Size")); if (verbose && pset.sversion >= 80300) + { appendPQExpBuffer(&buf, " pg_catalog.array_to_string(\n" " ARRAY(\n" " SELECT e.enumlabel\n" " FROM pg_catalog.pg_enum e\n" - " WHERE e.enumtypid = t.oid\n" - " ORDER BY e.oid\n" + " WHERE e.enumtypid = t.oid\n"); + + if (pset.sversion >= 90100) + appendPQExpBuffer(&buf, + " ORDER BY e.enumsortorder\n"); + else + appendPQExpBuffer(&buf, + " ORDER BY e.oid\n"); + + appendPQExpBuffer(&buf, " ),\n" " E'\\n'\n" " ) AS \"%s\",\n", gettext_noop("Elements")); + } appendPQExpBuffer(&buf, " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n", |
