Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.
Дата
Msg-id 15696.1558448457@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.  (Andres Freund <andres@anarazel.de>)
Ответы Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.  (Andres Freund <andres@anarazel.de>)
Список pgsql-committers
Andres Freund <andres@anarazel.de> writes:
> On 2019-05-20 20:19:20 -0400, Tom Lane wrote:
>> The other thing I had to do below was to suppress "NOTICE: database
>> "regression" does not exist, skipping".  The added createdb is a
>> mighty expensive and grotty way to do that, but I didn't immediately
>> see a better one.

> Hm. Perhaps we ought to just have pg_regress set client_min_messages to
> something less noisy when running DROP DATABASE? I don't think any
> pg_regress caller benefits from having it.

The least invasive way to do that seems to be as attached, building a
little knowledge into pg_regress's psql_command() function.  Alternatively
we could add a "bool quiet" parameter to that function so that callers
had to say what to do, but I'm not sure that's an improvement.

            regards, tom lane

diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index a1a3d48..57a154c 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -1087,6 +1087,7 @@ psql_command(const char *database, const char *query,...)
     char        query_formatted[1024];
     char        query_escaped[2048];
     char        psql_cmd[MAXPGPATH + 2048];
+    const char *quiet;
     va_list        args;
     char       *s;
     char       *d;
@@ -1106,11 +1107,23 @@ psql_command(const char *database, const char *query,...)
     }
     *d = '\0';

+    /*
+     * If the query uses IF EXISTS or IF NOT EXISTS, suppress useless
+     * "skipping" notices.  We intentionally consider only the constant
+     * "query" string, not what was interpolated into it.
+     */
+    if (strstr(query, "IF EXISTS") != NULL ||
+        strstr(query, "IF NOT EXISTS") != NULL)
+        quiet = " -c \"SET client_min_messages = warning\"";
+    else
+        quiet = "";
+
     /* And now we can build and execute the shell command */
     snprintf(psql_cmd, sizeof(psql_cmd),
-             "\"%s%spsql\" -X -c \"%s\" \"%s\"",
+             "\"%s%spsql\" -X%s -c \"%s\" \"%s\"",
              bindir ? bindir : "",
              bindir ? "/" : "",
+             quiet,
              query_escaped,
              database);


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.
Следующее
От: Andres Freund
Дата:
Сообщение: Re: pgsql: Make VACUUM accept 1 and 0 as a boolean value.