Skip to content

Commit 17082a8

Browse files
committed
Prevent copying default collation
This will not have the desired effect and might lead to crashes when the copied collation is used. Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent 78a030a commit 17082a8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/commands/collationcmds.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
120120
collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider;
121121

122122
ReleaseSysCache(tp);
123+
124+
/*
125+
* Copying the "default" collation is not allowed because most code
126+
* checks for DEFAULT_COLLATION_OID instead of COLLPROVIDER_DEFAULT,
127+
* and so having a second collation with COLLPROVIDER_DEFAULT would
128+
* not work and potentially confuse or crash some code. This could be
129+
* fixed with some legwork.
130+
*/
131+
if (collprovider == COLLPROVIDER_DEFAULT)
132+
ereport(ERROR,
133+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
134+
errmsg("collation \"default\" cannot be copied")));
123135
}
124136

125137
if (localeEl)

0 commit comments

Comments
 (0)