newlines at end of generated SQL
Is there a reason why the programs in src/bin/scripts all put newlines
at the end of the SQL commands they generate? This produces useless
empty lines in the server log (and client output, if selected).
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jan 8, 2014 at 10:17 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
Is there a reason why the programs in src/bin/scripts all put newlines
at the end of the SQL commands they generate? This produces useless
empty lines in the server log (and client output, if selected).
If you're asking whether you can go ahead and fix that, +1 from me.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Jan 9, 2014 at 3:34 PM, Robert Haas <robertmhaas@gmail.com> wrote:
On Wed, Jan 8, 2014 at 10:17 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
Is there a reason why the programs in src/bin/scripts all put newlines
at the end of the SQL commands they generate? This produces useless
empty lines in the server log (and client output, if selected).If you're asking whether you can go ahead and fix that, +1 from me.
Well... I did that...
Regards,
--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
Show quoted text
Timbira: http://www.timbira.com.br
Blog sobre TI: http://fabriziomello.blogspot.com
Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
Twitter: http://twitter.com/fabriziomello
Attachments:
remove-new-line-at-end-of-scripts_v1.patchtext/x-diff; charset=US-ASCII; name=remove-new-line-at-end-of-scripts_v1.patchDownload
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c
index 504b337..5ad1d01 100644
--- a/src/bin/scripts/clusterdb.c
+++ b/src/bin/scripts/clusterdb.c
@@ -201,7 +201,7 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
appendPQExpBufferStr(&sql, " VERBOSE");
if (table)
appendPQExpBuffer(&sql, " %s", table);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c
index edd18f7..8a4e20d 100644
--- a/src/bin/scripts/createdb.c
+++ b/src/bin/scripts/createdb.c
@@ -195,7 +195,7 @@ main(int argc, char *argv[])
if (lc_ctype)
appendPQExpBuffer(&sql, " LC_CTYPE '%s'", lc_ctype);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
/* No point in trying to use postgres db when creating postgres db. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
@@ -222,7 +222,7 @@ main(int argc, char *argv[])
{
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
appendStringLiteralConn(&sql, comment, conn);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (echo)
printf("%s", sql.data);
diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c
index 7737cb8..047d2ae 100644
--- a/src/bin/scripts/createlang.c
+++ b/src/bin/scripts/createlang.c
@@ -207,9 +207,9 @@ main(int argc, char *argv[])
* older server, and it's easy enough to continue supporting the old way.
*/
if (PQserverVersion(conn) >= 90100)
- printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";", langname);
else
- printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";", langname);
if (echo)
printf("%s", sql.data);
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 6b1a007..3f0c265 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -320,7 +320,7 @@ main(int argc, char *argv[])
appendPQExpBuffer(&sql, "%s", fmtId(cell->val));
}
}
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (echo)
printf("%s", sql.data);
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index fa6ea3e..3db595f 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -121,7 +121,7 @@ main(int argc, char *argv[])
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP DATABASE %s%s;\n",
+ appendPQExpBuffer(&sql, "DROP DATABASE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dbname));
/* Avoid trying to drop postgres db while we are connected to it. */
diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c
index d1a3e73..b162513 100644
--- a/src/bin/scripts/droplang.c
+++ b/src/bin/scripts/droplang.c
@@ -211,7 +211,7 @@ main(int argc, char *argv[])
* Attempt to drop the language. We do not use CASCADE, so that the drop
* will fail if there are any functions in the language.
*/
- printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";", langname);
if (echo)
printf("%s", sql.data);
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index b4b153b..a63b236 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -125,7 +125,7 @@ main(int argc, char *argv[])
}
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
+ appendPQExpBuffer(&sql, "DROP ROLE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
conn = connectDatabase("postgres", host, port, username, prompt_password,
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index e627d82..561bbce 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -253,7 +253,7 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
appendPQExpBuffer(&sql, " INDEX %s", name);
else if (strcmp(type, "DATABASE") == 0)
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
@@ -320,7 +320,7 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
+ appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname);
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index f034032..07a60d0 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -298,7 +298,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
}
if (table)
appendPQExpBuffer(&sql, " %s", table);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
On Thu, 2014-01-09 at 15:52 -0200, Fabrízio de Royes Mello wrote:
On Thu, Jan 9, 2014 at 3:34 PM, Robert Haas <robertmhaas@gmail.com>
wrote:On Wed, Jan 8, 2014 at 10:17 PM, Peter Eisentraut <peter_e@gmx.net>
wrote:
Is there a reason why the programs in src/bin/scripts all put
newlines
at the end of the SQL commands they generate? This produces
useless
empty lines in the server log (and client output, if selected).
If you're asking whether you can go ahead and fix that, +1 from me.
Well... I did that...
But you also need to add the newlines back for the --echo output.
(Might as well use puts() then.)
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Sat, Jan 11, 2014 at 1:21 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
On Thu, 2014-01-09 at 15:52 -0200, Fabrízio de Royes Mello wrote:
On Thu, Jan 9, 2014 at 3:34 PM, Robert Haas <robertmhaas@gmail.com>
wrote:On Wed, Jan 8, 2014 at 10:17 PM, Peter Eisentraut <peter_e@gmx.net>
wrote:
Is there a reason why the programs in src/bin/scripts all put
newlines
at the end of the SQL commands they generate? This produces
useless
empty lines in the server log (and client output, if selected).
If you're asking whether you can go ahead and fix that, +1 from me.
Well... I did that...
But you also need to add the newlines back for the --echo output.
(Might as well use puts() then.)
Done!
--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
Show quoted text
Timbira: http://www.timbira.com.br
Blog sobre TI: http://fabriziomello.blogspot.com
Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
Twitter: http://twitter.com/fabriziomello
Attachments:
remove-new-line-at-end-of-scripts_v2.patchtext/x-diff; charset=US-ASCII; name=remove-new-line-at-end-of-scripts_v2.patchDownload
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c
index 504b337..5ad1d01 100644
--- a/src/bin/scripts/clusterdb.c
+++ b/src/bin/scripts/clusterdb.c
@@ -201,7 +201,7 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
appendPQExpBufferStr(&sql, " VERBOSE");
if (table)
appendPQExpBuffer(&sql, " %s", table);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index 7a7e8d9..8fe846e 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -171,7 +171,7 @@ executeQuery(PGconn *conn, const char *query, const char *progname, bool echo)
PGresult *res;
if (echo)
- printf("%s\n", query);
+ printf("%s\n\n", query);
res = PQexec(conn, query);
if (!res ||
@@ -229,7 +229,7 @@ executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
bool r;
if (echo)
- printf("%s\n", query);
+ printf("%s\n\n", query);
SetCancelConn(conn);
res = PQexec(conn, query);
diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c
index edd18f7..64badd6 100644
--- a/src/bin/scripts/createdb.c
+++ b/src/bin/scripts/createdb.c
@@ -195,7 +195,7 @@ main(int argc, char *argv[])
if (lc_ctype)
appendPQExpBuffer(&sql, " LC_CTYPE '%s'", lc_ctype);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
/* No point in trying to use postgres db when creating postgres db. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
@@ -205,7 +205,7 @@ main(int argc, char *argv[])
prompt_password, progname);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
@@ -222,10 +222,10 @@ main(int argc, char *argv[])
{
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
appendStringLiteralConn(&sql, comment, conn);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c
index 7737cb8..9bbd67d 100644
--- a/src/bin/scripts/createlang.c
+++ b/src/bin/scripts/createlang.c
@@ -207,12 +207,12 @@ main(int argc, char *argv[])
* older server, and it's easy enough to continue supporting the old way.
*/
if (PQserverVersion(conn) >= 90100)
- printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";", langname);
else
- printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";", langname);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 6b1a007..24c4beb 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -320,10 +320,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(&sql, "%s", fmtId(cell->val));
}
}
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index fa6ea3e..e750b44 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -121,7 +121,7 @@ main(int argc, char *argv[])
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP DATABASE %s%s;\n",
+ appendPQExpBuffer(&sql, "DROP DATABASE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dbname));
/* Avoid trying to drop postgres db while we are connected to it. */
@@ -132,7 +132,7 @@ main(int argc, char *argv[])
host, port, username, prompt_password, progname);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c
index d1a3e73..09f7b66 100644
--- a/src/bin/scripts/droplang.c
+++ b/src/bin/scripts/droplang.c
@@ -211,10 +211,10 @@ main(int argc, char *argv[])
* Attempt to drop the language. We do not use CASCADE, so that the drop
* will fail if there are any functions in the language.
*/
- printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";\n", langname);
+ printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";", langname);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index b4b153b..69a5a49 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -125,14 +125,14 @@ main(int argc, char *argv[])
}
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
+ appendPQExpBuffer(&sql, "DROP ROLE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
conn = connectDatabase("postgres", host, port, username, prompt_password,
progname, false);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index e627d82..561bbce 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -253,7 +253,7 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
appendPQExpBuffer(&sql, " INDEX %s", name);
else if (strcmp(type, "DATABASE") == 0)
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
@@ -320,7 +320,7 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
+ appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname);
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index f034032..07a60d0 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -298,7 +298,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
}
if (table)
appendPQExpBuffer(&sql, " %s", table);
- appendPQExpBufferStr(&sql, ";\n");
+ appendPQExpBufferStr(&sql, ";");
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
committed
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers