diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2024-04-21 21:21:55 +0200 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2024-04-21 21:21:55 +0200 |
commit | 9e6faeb3249d420a22ad8a5fbcf093b272c02cb8 (patch) | |
tree | 0dad7726871c9aa04283cdf260c056e68f324104 | |
parent | 75929b6cfaff143c28b3ba6bb8801dc67aab4a9b (diff) | |
download | postgresql-9e6faeb3249d420a22ad8a5fbcf093b272c02cb8.tar.gz postgresql-9e6faeb3249d420a22ad8a5fbcf093b272c02cb8.zip |
createdb: compare strategy case-insensitive
When specifying the createdb strategy, the documentation suggests valid
options are FILE_COPY and WAL_LOG, but the code does case-sensitive
comparison and accepts only "file_copy" and "wal_log" as valid.
Fixed by doing a case-insensitive comparison using pg_strcasecmp(), same
as for other string parameters nearby.
While at it, apply fmtId() to a nearby "locale_provider". This already
did the comparison in case-insensitive way, but the value would not be
double-quoted, confusing the parser and the error message.
Backpatch to 15, where the strategy was introduced.
Backpatch-through: 15
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/90c6913a-1dd2-42b4-8365-ce3b09c39b17@enterprisedb.com
-rw-r--r-- | src/backend/commands/dbcommands.c | 6 | ||||
-rw-r--r-- | src/bin/scripts/createdb.c | 2 | ||||
-rw-r--r-- | src/bin/scripts/t/020_createdb.pl | 10 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index aa48fdf8d21..7295800a7d8 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -1006,15 +1006,15 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt) char *strategy; strategy = defGetString(dstrategy); - if (strcmp(strategy, "wal_log") == 0) + if (pg_strcasecmp(strategy, "wal_log") == 0) dbstrategy = CREATEDB_WAL_LOG; - else if (strcmp(strategy, "file_copy") == 0) + else if (pg_strcasecmp(strategy, "file_copy") == 0) dbstrategy = CREATEDB_FILE_COPY; else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid create database strategy \"%s\"", strategy), - errhint("Valid strategies are \"wal_log\", and \"file_copy\"."))); + errhint("Valid strategies are \"wal_log\" and \"file_copy\"."))); } /* If encoding or locales are defaulted, use source's setting */ diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index 9ca86a3e53d..ef34b24890c 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -227,7 +227,7 @@ main(int argc, char *argv[]) appendStringLiteralConn(&sql, lc_ctype, conn); } if (locale_provider) - appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", locale_provider); + appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", fmtId(locale_provider)); if (icu_locale) { appendPQExpBufferStr(&sql, " ICU_LOCALE "); diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl index 40291924e5d..f44775df44e 100644 --- a/src/bin/scripts/t/020_createdb.pl +++ b/src/bin/scripts/t/020_createdb.pl @@ -176,10 +176,20 @@ $node->issues_sql_like( 'create database with WAL_LOG strategy'); $node->issues_sql_like( + [ 'createdb', '-T', 'foobar2', '-S', 'WAL_LOG', 'foobar6s' ], + qr/statement: CREATE DATABASE foobar6s STRATEGY "WAL_LOG" TEMPLATE foobar2/, + 'create database with WAL_LOG strategy'); + +$node->issues_sql_like( [ 'createdb', '-T', 'foobar2', '-S', 'file_copy', 'foobar7' ], qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/, 'create database with FILE_COPY strategy'); +$node->issues_sql_like( + [ 'createdb', '-T', 'foobar2', '-S', 'FILE_COPY', 'foobar7s' ], + qr/statement: CREATE DATABASE foobar7s STRATEGY "FILE_COPY" TEMPLATE foobar2/, + 'create database with FILE_COPY strategy'); + # Create database owned by role_foobar. $node->issues_sql_like( [ 'createdb', '-T', 'foobar2', '-O', 'role_foobar', 'foobar8' ], |