Hello again,
If you want to implement real non-ambiguous-prefix code (i.e. have "se"
for "select-only", but reject "s" as ambiguous) be my guest.
I'm fine with filtering out ambiguous cases (i.e. just the "s" case).
Attached a small patch for that.
--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 42d0667..124e70d 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -269,6 +269,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
Add the specified builtin script to the list of executed scripts.
Available builtin scripts are: <literal>tpcb-like</>,
<literal>simple-update</> and <literal>select-only</>.
+ The provided <replaceable>scriptname</> needs only be an unambiguous
+ prefix of the builtin name, hence <literal>si</> would be enough to
+ select <literal>simple-update</>.
With special name <literal>list</>, show the list of builtin scripts
and exit immediately.
</para>
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index d5f242c..6350948 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2649,22 +2649,32 @@ listAvailableScripts(void)
fprintf(stderr, "\n");
}
+/* return commands for selected builtin script, if unambiguous */
static char *
findBuiltin(const char *name, char **desc)
{
- int i;
+ int i, found = 0, len = strlen(name);
+ char *commands = NULL;
for (i = 0; i < N_BUILTIN; i++)
{
- if (strncmp(builtin_script[i].name, name,
- strlen(builtin_script[i].name)) == 0)
+ if (strncmp(builtin_script[i].name, name, len) == 0)
{
*desc = builtin_script[i].desc;
- return builtin_script[i].commands;
+ commands = builtin_script[i].commands;
+ found++;
}
}
- fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
+ if (found == 1)
+ return commands;
+
+ /* error cases */
+ if (found == 0)
+ fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
+ else /* found > 1 */
+ fprintf(stderr,
+ "%d builtin scripts found for prefix \"%s\"\n", found, name);
listAvailableScripts();
exit(1);
}
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers