aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-08-24 20:13:52 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-08-24 20:13:52 +0200
commit396d348b046c6b7e5dc83158c4c1df1377a1d2ef (patch)
treec7b18798cb5af7f283fc28470c227ae948cc7661
parentf25bed3801e1e500850a9f3b29a003c644d4bd6d (diff)
downloadpostgresql-396d348b046c6b7e5dc83158c4c1df1377a1d2ef.tar.gz
postgresql-396d348b046c6b7e5dc83158c4c1df1377a1d2ef.zip
pg_dump: Dump colliculocale
This was forgotten when the new column was introduced. Author: Marina Polyakova <m.polyakova@postgrespro.ru> Reviewed-by: Julien Rouhaud <rjuju123@gmail.com> Discussion: https://www.postgresql.org/message-id/7ad26354e75259f59c4a6c6997b8ee32%40postgrespro.ru
-rw-r--r--src/bin/pg_dump/Makefile1
-rw-r--r--src/bin/pg_dump/pg_dump.c50
-rw-r--r--src/bin/pg_dump/t/002_pg_dump.pl28
3 files changed, 70 insertions, 9 deletions
diff --git a/src/bin/pg_dump/Makefile b/src/bin/pg_dump/Makefile
index 2f524b09bf5..9dc5a784dd2 100644
--- a/src/bin/pg_dump/Makefile
+++ b/src/bin/pg_dump/Makefile
@@ -17,6 +17,7 @@ top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
export GZIP_PROGRAM=$(GZIP)
+export with_icu
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index ca4ad070042..d25709ad5f3 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -13083,9 +13083,11 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
int i_collisdeterministic;
int i_collcollate;
int i_collctype;
+ int i_colliculocale;
const char *collprovider;
const char *collcollate;
const char *collctype;
+ const char *colliculocale;
/* Do nothing in data-only dump */
if (dopt->dataOnly)
@@ -13116,6 +13118,13 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
appendPQExpBufferStr(query,
"true AS collisdeterministic, ");
+ if (fout->remoteVersion >= 150000)
+ appendPQExpBufferStr(query,
+ "colliculocale, ");
+ else
+ appendPQExpBufferStr(query,
+ "NULL AS colliculocale, ");
+
appendPQExpBuffer(query,
"collcollate, "
"collctype "
@@ -13129,10 +13138,24 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
i_collisdeterministic = PQfnumber(res, "collisdeterministic");
i_collcollate = PQfnumber(res, "collcollate");
i_collctype = PQfnumber(res, "collctype");
+ i_colliculocale = PQfnumber(res, "colliculocale");
collprovider = PQgetvalue(res, 0, i_collprovider);
- collcollate = PQgetvalue(res, 0, i_collcollate);
- collctype = PQgetvalue(res, 0, i_collctype);
+
+ if (!PQgetisnull(res, 0, i_collcollate))
+ collcollate = PQgetvalue(res, 0, i_collcollate);
+ else
+ collcollate = NULL;
+
+ if (!PQgetisnull(res, 0, i_collctype))
+ collctype = PQgetvalue(res, 0, i_collctype);
+ else
+ collctype = NULL;
+
+ if (!PQgetisnull(res, 0, i_colliculocale))
+ colliculocale = PQgetvalue(res, 0, i_colliculocale);
+ else
+ colliculocale = NULL;
appendPQExpBuffer(delq, "DROP COLLATION %s;\n",
fmtQualifiedDumpable(collinfo));
@@ -13155,17 +13178,28 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
if (strcmp(PQgetvalue(res, 0, i_collisdeterministic), "f") == 0)
appendPQExpBufferStr(q, ", deterministic = false");
- if (strcmp(collcollate, collctype) == 0)
+ if (colliculocale != NULL)
{
appendPQExpBufferStr(q, ", locale = ");
- appendStringLiteralAH(q, collcollate, fout);
+ appendStringLiteralAH(q, colliculocale, fout);
}
else
{
- appendPQExpBufferStr(q, ", lc_collate = ");
- appendStringLiteralAH(q, collcollate, fout);
- appendPQExpBufferStr(q, ", lc_ctype = ");
- appendStringLiteralAH(q, collctype, fout);
+ Assert(collcollate != NULL);
+ Assert(collctype != NULL);
+
+ if (strcmp(collcollate, collctype) == 0)
+ {
+ appendPQExpBufferStr(q, ", locale = ");
+ appendStringLiteralAH(q, collcollate, fout);
+ }
+ else
+ {
+ appendPQExpBufferStr(q, ", lc_collate = ");
+ appendStringLiteralAH(q, collcollate, fout);
+ appendPQExpBufferStr(q, ", lc_ctype = ");
+ appendStringLiteralAH(q, collctype, fout);
+ }
}
/*
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index b10e1c4c0d4..383bb46b25e 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -1593,6 +1593,15 @@ my %tests = (
like => { %full_runs, section_pre_data => 1, },
},
+ 'CREATE COLLATION icu_collation' => {
+ create_order => 76,
+ create_sql => "CREATE COLLATION icu_collation (PROVIDER = icu, LOCALE = 'C');",
+ regexp =>
+ qr/CREATE COLLATION public.icu_collation \(provider = icu, locale = 'C'(, version = '[^']*')?\);/m,
+ icu => 1,
+ like => { %full_runs, section_pre_data => 1, },
+ },
+
'CREATE CAST FOR timestamptz' => {
create_order => 51,
create_sql =>
@@ -3890,7 +3899,7 @@ if ($collation_check_stderr !~ /ERROR: /)
$collation_support = 1;
}
-# Determine whether build supports LZ4 and gzip.
+my $supports_icu = ($ENV{with_icu} eq 'yes');
my $supports_lz4 = check_pg_config("#define USE_LZ4 1");
my $supports_gzip = check_pg_config("#define HAVE_LIBZ 1");
@@ -3931,6 +3940,11 @@ foreach my $test (
$test_db = $tests{$test}->{database};
}
+ if (defined($tests{$test}->{icu}))
+ {
+ $tests{$test}->{collation} = 1;
+ }
+
if ($tests{$test}->{create_sql})
{
@@ -3940,6 +3954,12 @@ foreach my $test (
next;
}
+ # Skip any icu-related collation commands if build was without icu
+ if (!$supports_icu && defined($tests{$test}->{icu}))
+ {
+ next;
+ }
+
# Skip tests specific to LZ4 if this build does not support
# this option.
if (!$supports_lz4 && defined($tests{$test}->{lz4}))
@@ -4141,6 +4161,12 @@ foreach my $run (sort keys %pgdump_runs)
next;
}
+ # Skip any icu-related collation commands if build was without icu
+ if (!$supports_icu && defined($tests{$test}->{icu}))
+ {
+ next;
+ }
+
# Skip tests specific to LZ4 if this build does not support
# this option.
if (!$supports_lz4 && defined($tests{$test}->{lz4}))