]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
createdb: compare strategy case-insensitive
authorTomas Vondra <tomas.vondra@postgresql.org>
Sun, 21 Apr 2024 19:22:11 +0000 (21:22 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Sun, 21 Apr 2024 19:22:11 +0000 (21:22 +0200)
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

src/backend/commands/dbcommands.c
src/bin/scripts/createdb.c
src/bin/scripts/t/020_createdb.pl

index 5ced6da20b6436dc80f4900632217c40cc0c94e7..40fd36d3c39617547738ca43947f6979b33e3803 100644 (file)
@@ -994,15 +994,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 */
index a1482df3d981a680dd3322052e7c03ddacc8dc26..cbeef4f54f0d217c682b4120daa98faedf02ded4 100644 (file)
@@ -225,7 +225,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 ");
index 2e712f4fe921a9463b5f92ddf73ed0a244568ff9..20984d761bb44d7adf318ffa360b9133f23d5b06 100644 (file)
@@ -153,9 +153,19 @@ $node->issues_sql_like(
        qr/statement: CREATE DATABASE foobar6 STRATEGY wal_log TEMPLATE foobar2/,
        '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');
+
 done_testing();