Skip to content

Commit 9e6faeb

Browse files
committed
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
1 parent 75929b6 commit 9e6faeb

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/backend/commands/dbcommands.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,15 +1006,15 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10061006
char *strategy;
10071007

10081008
strategy = defGetString(dstrategy);
1009-
if (strcmp(strategy, "wal_log") == 0)
1009+
if (pg_strcasecmp(strategy, "wal_log") == 0)
10101010
dbstrategy = CREATEDB_WAL_LOG;
1011-
else if (strcmp(strategy, "file_copy") == 0)
1011+
else if (pg_strcasecmp(strategy, "file_copy") == 0)
10121012
dbstrategy = CREATEDB_FILE_COPY;
10131013
else
10141014
ereport(ERROR,
10151015
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
10161016
errmsg("invalid create database strategy \"%s\"", strategy),
1017-
errhint("Valid strategies are \"wal_log\", and \"file_copy\".")));
1017+
errhint("Valid strategies are \"wal_log\" and \"file_copy\".")));
10181018
}
10191019

10201020
/* If encoding or locales are defaulted, use source's setting */

src/bin/scripts/createdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ main(int argc, char *argv[])
227227
appendStringLiteralConn(&sql, lc_ctype, conn);
228228
}
229229
if (locale_provider)
230-
appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", locale_provider);
230+
appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", fmtId(locale_provider));
231231
if (icu_locale)
232232
{
233233
appendPQExpBufferStr(&sql, " ICU_LOCALE ");

src/bin/scripts/t/020_createdb.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,21 @@
175175
qr/statement: CREATE DATABASE foobar6 STRATEGY wal_log TEMPLATE foobar2/,
176176
'create database with WAL_LOG strategy');
177177

178+
$node->issues_sql_like(
179+
[ 'createdb', '-T', 'foobar2', '-S', 'WAL_LOG', 'foobar6s' ],
180+
qr/statement: CREATE DATABASE foobar6s STRATEGY "WAL_LOG" TEMPLATE foobar2/,
181+
'create database with WAL_LOG strategy');
182+
178183
$node->issues_sql_like(
179184
[ 'createdb', '-T', 'foobar2', '-S', 'file_copy', 'foobar7' ],
180185
qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/,
181186
'create database with FILE_COPY strategy');
182187

188+
$node->issues_sql_like(
189+
[ 'createdb', '-T', 'foobar2', '-S', 'FILE_COPY', 'foobar7s' ],
190+
qr/statement: CREATE DATABASE foobar7s STRATEGY "FILE_COPY" TEMPLATE foobar2/,
191+
'create database with FILE_COPY strategy');
192+
183193
# Create database owned by role_foobar.
184194
$node->issues_sql_like(
185195
[ 'createdb', '-T', 'foobar2', '-O', 'role_foobar', 'foobar8' ],

0 commit comments

Comments
 (0)