From 4978ce750dae30c01d4e8d1eac7836ed8aefbffc Mon Sep 17 00:00:00 2001 From: teooooozhang Date: Mon, 27 Mar 2023 10:44:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?enum=E7=B1=BB=E5=9E=8B=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81gs=5Fdump=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.cpp b/src/bin/pg_dump/pg_dump.cpp index b14219ea37..15ceadfe91 100644 --- a/src/bin/pg_dump/pg_dump.cpp +++ b/src/bin/pg_dump/pg_dump.cpp @@ -9287,7 +9287,9 @@ void getTableAttrs(Archive* fout, TableInfo* tblinfo, int numTables) "a.attstattarget, a.attstorage, t.typstorage, " "a.attnotnull, a.atthasdef, a.attisdropped, " "a.attlen, a.attalign, a.attislocal, a.attkvtype, t.oid AS typid, " - "CASE WHEN t.typtype <> 's' THEN pg_catalog.format_type(t.oid,a.atttypmod) ELSE 'set(' || (select pg_catalog.string_agg(''''||setlabel||'''', ',' order by setsortorder) from pg_catalog.pg_set group by settypid having settypid = t.oid) || ')' END AS atttypname, " + "CASE WHEN t.typtype = 's' THEN 'set(' || (select pg_catalog.string_agg(''''||setlabel||'''', ',' order by setsortorder) from pg_catalog.pg_set group by settypid having settypid = t.oid) || ')' " + "WHEN t.typtype = 'e' THEN 'enum(' || (select pg_catalog.string_agg(''''||enumlabel||'''', ',' order by enumsortorder) from pg_catalog.pg_enum group by enumtypid having enumtypid = t.oid) || ')' ELSE pg_catalog.format_type(t.oid,a.atttypmod) END " + "AS atttypname, " "pg_catalog.array_to_string(a.attoptions, ', ') AS attoptions, " "CASE WHEN a.attcollation <> t.typcollation " "THEN a.attcollation ELSE 0::Oid END AS attcollation, " @@ -11362,7 +11364,7 @@ static void dumpType(Archive* fout, TypeInfo* tyinfo) else if (tyinfo->typtype == TYPTYPE_COMPOSITE) dumpCompositeType(fout, tyinfo); else if (tyinfo->typtype == TYPTYPE_ENUM) - dumpEnumType(fout, tyinfo); + return; else if (tyinfo->typtype == TYPTYPE_RANGE) dumpRangeType(fout, tyinfo); else if (tyinfo->typtype == TYPTYPE_TABLEOF) -- Gitee From 61a44e44ba8be764d392c69ba9b5318ba720a2ca Mon Sep 17 00:00:00 2001 From: teooooozhang Date: Tue, 4 Apr 2023 11:32:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?enum=E7=B1=BB=E5=9E=8B=E5=9C=A8gs=5Fdump?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=BC=E5=AE=B9=E6=80=A7=E4=B8=8Edolphin?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump.cpp | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.cpp b/src/bin/pg_dump/pg_dump.cpp index 15ceadfe91..3b72022a2f 100644 --- a/src/bin/pg_dump/pg_dump.cpp +++ b/src/bin/pg_dump/pg_dump.cpp @@ -54,6 +54,7 @@ #include "catalog/pg_cast.h" #include "catalog/pg_class.h" #include "catalog/pg_database.h" +#include "catalog/pg_extension.h" #include "catalog/pg_default_acl.h" #include "catalog/pg_event_trigger.h" #include "catalog/pg_largeobject.h" @@ -507,6 +508,7 @@ inline bool isDB4AIschema(const NamespaceInfo *nspinfo); #ifdef DUMPSYSLOG static void ReceiveSyslog(PGconn* conn, const char* current_path); #endif +static bool hasSpecificExtension(Archive* fout, const char* databasename); #ifdef GSDUMP_LLT bool lltRunning = true; @@ -11363,8 +11365,12 @@ static void dumpType(Archive* fout, TypeInfo* tyinfo) dumpDomain(fout, tyinfo); else if (tyinfo->typtype == TYPTYPE_COMPOSITE) dumpCompositeType(fout, tyinfo); - else if (tyinfo->typtype == TYPTYPE_ENUM) - return; + else if (tyinfo->typtype == TYPTYPE_ENUM) { + if (findDBCompatibility(fout, PQdb(GetConnection(fout))) && hasSpecificExtension(fout, "dolphin")) { + return; + } + dumpEnumType(fout, tyinfo); + } else if (tyinfo->typtype == TYPTYPE_RANGE) dumpRangeType(fout, tyinfo); else if (tyinfo->typtype == TYPTYPE_TABLEOF) @@ -23486,3 +23492,31 @@ static bool needIgnoreSequence(TableInfo* tbinfo) } return false; } + +/* + * check if current database has specific extension whose name is provided by parameter + */ +static bool hasSpecificExtension(Archive* fout, const char* extensionName) +{ + PGresult *res = NULL; + int ntups = 0; + bool hasExtnameColumn = true; + ArchiveHandle *AH = (ArchiveHandle *)fout; + + hasExtnameColumn = is_column_exists(AH->connection, ExtensionRelationId, "extname"); + if (!hasExtnameColumn) { + return false; + } + + PQExpBuffer query = createPQExpBuffer(); + + resetPQExpBuffer(query); + appendPQExpBuffer(query, "SELECT extname from pg_catalog.pg_extension where extname = "); + appendStringLiteralAH(query, extensionName, fout); + + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + ntups = PQntuples(res); + PQclear(res); + destroyPQExpBuffer(query); + return ntups != 0; +} \ No newline at end of file -- Gitee