Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8c239ee

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 a3021aa commit 8c239ee

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/backend/commands/dbcommands.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1018,15 +1018,15 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10181018
char *strategy;
10191019

10201020
strategy = defGetString(dstrategy);
1021-
if (strcmp(strategy, "wal_log") == 0)
1021+
if (pg_strcasecmp(strategy, "wal_log") == 0)
10221022
dbstrategy = CREATEDB_WAL_LOG;
1023-
else if (strcmp(strategy, "file_copy") == 0)
1023+
else if (pg_strcasecmp(strategy, "file_copy") == 0)
10241024
dbstrategy = CREATEDB_FILE_COPY;
10251025
else
10261026
ereport(ERROR,
10271027
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
10281028
errmsg("invalid create database strategy \"%s\"", strategy),
1029-
errhint("Valid strategies are \"wal_log\", and \"file_copy\".")));
1029+
errhint("Valid strategies are \"wal_log\" and \"file_copy\".")));
10301030
}
10311031

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

src/bin/scripts/createdb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ main(int argc, char *argv[])
237237
appendStringLiteralConn(&sql, lc_ctype, conn);
238238
}
239239
if (locale_provider)
240-
appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", locale_provider);
240+
appendPQExpBuffer(&sql, " LOCALE_PROVIDER %s", fmtId(locale_provider));
241241
if (icu_locale)
242242
{
243243
appendPQExpBufferStr(&sql, " ICU_LOCALE ");

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

+10
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,21 @@
255255
qr/statement: CREATE DATABASE foobar6 STRATEGY wal_log TEMPLATE foobar2/,
256256
'create database with WAL_LOG strategy');
257257

258+
$node->issues_sql_like(
259+
[ 'createdb', '-T', 'foobar2', '-S', 'WAL_LOG', 'foobar6s' ],
260+
qr/statement: CREATE DATABASE foobar6s STRATEGY "WAL_LOG" TEMPLATE foobar2/,
261+
'create database with WAL_LOG strategy');
262+
258263
$node->issues_sql_like(
259264
[ 'createdb', '-T', 'foobar2', '-S', 'file_copy', 'foobar7' ],
260265
qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/,
261266
'create database with FILE_COPY strategy');
262267

268+
$node->issues_sql_like(
269+
[ 'createdb', '-T', 'foobar2', '-S', 'FILE_COPY', 'foobar7s' ],
270+
qr/statement: CREATE DATABASE foobar7s STRATEGY "FILE_COPY" TEMPLATE foobar2/,
271+
'create database with FILE_COPY strategy');
272+
263273
# Create database owned by role_foobar.
264274
$node->issues_sql_like(
265275
[ 'createdb', '-T', 'foobar2', '-O', 'role_foobar', 'foobar8' ],

0 commit comments

Comments
 (0)