Skip to content

Commit 54baa48

Browse files
committed
Copy collencoding in CREATE COLLATION / FROM
This command used to compute the collencoding entry like when a completely new collation is created. But for example when copying the "C" collation, this would then result in a collation that has a collencoding entry for the current database encoding rather than -1, thus not making an exact copy. This has probably no practical impact, but making this change keeps the catalog contents neat. Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent 08aed66 commit 54baa48

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/commands/collationcmds.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
6464
char *collcollate = NULL;
6565
char *collctype = NULL;
6666
char *collproviderstr = NULL;
67-
int collencoding;
67+
int collencoding = 0;
6868
char collprovider = 0;
6969
char *collversion = NULL;
7070
Oid newoid;
@@ -126,6 +126,7 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
126126
collcollate = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collcollate));
127127
collctype = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collctype));
128128
collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider;
129+
collencoding = ((Form_pg_collation) GETSTRUCT(tp))->collencoding;
129130

130131
ReleaseSysCache(tp);
131132

@@ -185,12 +186,15 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
185186
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
186187
errmsg("parameter \"lc_ctype\" must be specified")));
187188

188-
if (collprovider == COLLPROVIDER_ICU)
189-
collencoding = -1;
190-
else
189+
if (!fromEl)
191190
{
192-
collencoding = GetDatabaseEncoding();
193-
check_encoding_locale_matches(collencoding, collcollate, collctype);
191+
if (collprovider == COLLPROVIDER_ICU)
192+
collencoding = -1;
193+
else
194+
{
195+
collencoding = GetDatabaseEncoding();
196+
check_encoding_locale_matches(collencoding, collcollate, collctype);
197+
}
194198
}
195199

196200
if (!collversion)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy