Hi,
Currently, it's not an error for CREATE COLLATION to be invoked
with options repeated several times. The last (rightmost) value is kept
and the others are lost.
For instance CREATE COLLATION x (lc_ctype='en_US.UTF8',
lc_collate='en_US.UTF8', lc_ctype='C')
silently ignores lc_ctype='en_US.UTF8'. But that kind of invocation
isn't likely to be legit. It's more plausible that it's the result of
some mistake or confusion.
The same goes for the other options:
CREATE COLLATION [ IF NOT EXISTS ] name (
[ LOCALE = locale, ]
[ LC_COLLATE = lc_collate, ]
[ LC_CTYPE = lc_ctype, ]
[ PROVIDER = provider, ]
[ DETERMINISTIC = boolean, ]
[ VERSION = version ]
)
I suggest the attached simple patch to raise an error when any of
these options is specified multiple times.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite
diff --git a/src/backend/commands/collationcmds.c
b/src/backend/commands/collationcmds.c
index 9f6582c530..7dfd544396 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -108,6 +108,19 @@ DefineCollation(ParseState *pstate, List *names, List
*parameters, bool if_not_e
break;
}
+ if (*defelp != NULL)
+ {
+ /*
+ * If the option was previously set, it means that it
occurs
+ * several times in the list, which is not allowed.
+ */
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant
options",
+ defel->defname),
+ parser_errposition(pstate,
defel->location)));
+ break;
+ }
*defelp = defel;
}