Now some of the output generated by test_extdepend gets a bit
confusing:
+-- QUERY:
+
+
+-- QUERY:

That's not entirely this patch's fault.  Still that's not really
intuitive to see the output of a query that's just a blank spot..

Hmmm.

What about adding an explicit \echo before these empty outputs to mitigate the possible induced confusion?

\echo is not possible.

Attached an attempt to improve the situation by replacing empty lines with comments in this test.

--
Fabien.
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 7672ed9e9d..16873aff62 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -5284,18 +5284,9 @@ echo_hidden_command(const char *query)
 {
 	if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
 	{
-		printf(_("********* QUERY **********\n"
-				 "%s\n"
-				 "**************************\n\n"), query);
-		fflush(stdout);
+		echoQuery(stdout, true, query);
 		if (pset.logfile)
-		{
-			fprintf(pset.logfile,
-					_("********* QUERY **********\n"
-					  "%s\n"
-					  "**************************\n\n"), query);
-			fflush(pset.logfile);
-		}
+			echoQuery(pset.logfile, true, query);
 
 		if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC)
 			return false;
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index b989d792aa..30fd5bcda1 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -543,6 +543,18 @@ PrintTiming(double elapsed_msec)
 		   elapsed_msec, days, (int) hours, (int) minutes, seconds);
 }
 
+/*
+ * Echo user query
+ */
+void
+echoQuery(FILE *out, bool is_internal, const char *query)
+{
+	if (is_internal)
+		fprintf(out, _("-- INTERNAL QUERY:\n%s\n\n"), query);
+	else
+		fprintf(out, _("-- QUERY:\n%s\n\n"), query);
+	fflush(out);
+}
 
 /*
  * PSQLexec
@@ -569,18 +581,9 @@ PSQLexec(const char *query)
 
 	if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
 	{
-		printf(_("********* QUERY **********\n"
-				 "%s\n"
-				 "**************************\n\n"), query);
-		fflush(stdout);
+		echoQuery(stdout, true, query);
 		if (pset.logfile)
-		{
-			fprintf(pset.logfile,
-					_("********* QUERY **********\n"
-					  "%s\n"
-					  "**************************\n\n"), query);
-			fflush(pset.logfile);
-		}
+			echoQuery(pset.logfile, true, query);
 
 		if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC)
 			return NULL;
@@ -796,10 +799,7 @@ ExecQueryTuples(const PGresult *result)
 				 * assumes that MainLoop did that, so we have to do it here.
 				 */
 				if (pset.echo == PSQL_ECHO_ALL && !pset.singlestep)
-				{
-					puts(query);
-					fflush(stdout);
-				}
+					echoQuery(stdout, false, query);
 
 				if (!SendQuery(query))
 				{
@@ -1058,13 +1058,7 @@ SendQuery(const char *query)
 	}
 
 	if (pset.logfile)
-	{
-		fprintf(pset.logfile,
-				_("********* QUERY **********\n"
-				  "%s\n"
-				  "**************************\n\n"), query);
-		fflush(pset.logfile);
-	}
+		echoQuery(pset.logfile, false, query);
 
 	SetCancelConn(pset.db);
 
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index f0820dd7d5..359c48143e 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -32,6 +32,7 @@ extern void psql_setup_cancel_handler(void);
 extern PGresult *PSQLexec(const char *query);
 extern int	PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout);
 
+extern void echoQuery(FILE *out, bool is_internal, const char *query);
 extern bool SendQuery(const char *query);
 
 extern bool is_superuser(void);
diff --git a/src/test/modules/test_extensions/expected/test_extdepend.out b/src/test/modules/test_extensions/expected/test_extdepend.out
index 0b62015d18..a08ef8d19d 100644
--- a/src/test/modules/test_extensions/expected/test_extdepend.out
+++ b/src/test/modules/test_extensions/expected/test_extdepend.out
@@ -11,17 +11,17 @@ SELECT * FROM test_extdep_commands;
   CREATE EXTENSION test_ext5 SCHEMA test_ext
   SET search_path TO test_ext
   CREATE TABLE a (a1 int)
- 
+  -- function b
   CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS               +
     $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
   ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
- 
+  -- trigger c
   CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
   ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
- 
+  -- materialized view d
   CREATE MATERIALIZED VIEW d AS SELECT * FROM a
   ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
- 
+  -- index e
   CREATE INDEX e ON a (a1)
   ALTER INDEX e DEPENDS ON EXTENSION test_ext5
   RESET search_path
@@ -29,24 +29,58 @@ SELECT * FROM test_extdep_commands;
 
 -- First, test that dependent objects go away when the extension is dropped.
 SELECT * FROM test_extdep_commands \gexec
+-- QUERY:
  CREATE SCHEMA test_ext
+
+-- QUERY:
  CREATE EXTENSION test_ext5 SCHEMA test_ext
+
+-- QUERY:
  SET search_path TO test_ext
+
+-- QUERY:
  CREATE TABLE a (a1 int)
 
+-- QUERY:
+ -- function b
+
+-- QUERY:
  CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS
    $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
+
+-- QUERY:
  ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- trigger c
+
+-- QUERY:
  CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
+
+-- QUERY:
  ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- materialized view d
+
+-- QUERY:
  CREATE MATERIALIZED VIEW d AS SELECT * FROM a
+
+-- QUERY:
  ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- index e
+
+-- QUERY:
  CREATE INDEX e ON a (a1)
+
+-- QUERY:
  ALTER INDEX e DEPENDS ON EXTENSION test_ext5
+
+-- QUERY:
  RESET search_path
+
 -- A dependent object made dependent again has no effect
 ALTER FUNCTION test_ext.b() DEPENDS ON EXTENSION test_ext5;
 -- make sure we have the right dependencies on the extension
@@ -78,24 +112,58 @@ NOTICE:  drop cascades to table test_ext.a
 -- Second test: If we drop the table, the objects are dropped too and no
 -- vestige remains in pg_depend.
 SELECT * FROM test_extdep_commands \gexec
+-- QUERY:
  CREATE SCHEMA test_ext
+
+-- QUERY:
  CREATE EXTENSION test_ext5 SCHEMA test_ext
+
+-- QUERY:
  SET search_path TO test_ext
+
+-- QUERY:
  CREATE TABLE a (a1 int)
 
+-- QUERY:
+ -- function b
+
+-- QUERY:
  CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS
    $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
+
+-- QUERY:
  ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- trigger c
+
+-- QUERY:
  CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
+
+-- QUERY:
  ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- materialized view d
+
+-- QUERY:
  CREATE MATERIALIZED VIEW d AS SELECT * FROM a
+
+-- QUERY:
  ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- index e
+
+-- QUERY:
  CREATE INDEX e ON a (a1)
+
+-- QUERY:
  ALTER INDEX e DEPENDS ON EXTENSION test_ext5
+
+-- QUERY:
  RESET search_path
+
 DROP TABLE test_ext.a;		-- should fail, require cascade
 ERROR:  cannot drop table test_ext.a because other objects depend on it
 DETAIL:  materialized view test_ext.d depends on table test_ext.a
@@ -116,24 +184,58 @@ DROP EXTENSION test_ext5;
 DROP SCHEMA test_ext CASCADE;
 -- Third test: we can drop the objects individually
 SELECT * FROM test_extdep_commands \gexec
+-- QUERY:
  CREATE SCHEMA test_ext
+
+-- QUERY:
  CREATE EXTENSION test_ext5 SCHEMA test_ext
+
+-- QUERY:
  SET search_path TO test_ext
+
+-- QUERY:
  CREATE TABLE a (a1 int)
 
+-- QUERY:
+ -- function b
+
+-- QUERY:
  CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS
    $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
+
+-- QUERY:
  ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- trigger c
+
+-- QUERY:
  CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
+
+-- QUERY:
  ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- materialized view d
+
+-- QUERY:
  CREATE MATERIALIZED VIEW d AS SELECT * FROM a
+
+-- QUERY:
  ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- index e
+
+-- QUERY:
  CREATE INDEX e ON a (a1)
+
+-- QUERY:
  ALTER INDEX e DEPENDS ON EXTENSION test_ext5
+
+-- QUERY:
  RESET search_path
+
 SET search_path TO test_ext;
 DROP TRIGGER c ON a;
 DROP FUNCTION b();
@@ -156,24 +258,58 @@ NOTICE:  drop cascades to extension test_ext5
 -- Fourth test: we can mark the objects as dependent, then unmark; then the
 -- drop of the extension does nothing
 SELECT * FROM test_extdep_commands \gexec
+-- QUERY:
  CREATE SCHEMA test_ext
+
+-- QUERY:
  CREATE EXTENSION test_ext5 SCHEMA test_ext
+
+-- QUERY:
  SET search_path TO test_ext
+
+-- QUERY:
  CREATE TABLE a (a1 int)
 
+-- QUERY:
+ -- function b
+
+-- QUERY:
  CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS
    $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
+
+-- QUERY:
  ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- trigger c
+
+-- QUERY:
  CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
+
+-- QUERY:
  ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- materialized view d
+
+-- QUERY:
  CREATE MATERIALIZED VIEW d AS SELECT * FROM a
+
+-- QUERY:
  ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
 
+-- QUERY:
+ -- index e
+
+-- QUERY:
  CREATE INDEX e ON a (a1)
+
+-- QUERY:
  ALTER INDEX e DEPENDS ON EXTENSION test_ext5
+
+-- QUERY:
  RESET search_path
+
 SET search_path TO test_ext;
 ALTER FUNCTION b() NO DEPENDS ON EXTENSION test_ext5;
 ALTER TRIGGER c ON a NO DEPENDS ON EXTENSION test_ext5;
diff --git a/src/test/modules/test_extensions/sql/test_extdepend.sql b/src/test/modules/test_extensions/sql/test_extdepend.sql
index 63240a1af5..7a23c18bf8 100644
--- a/src/test/modules/test_extensions/sql/test_extdepend.sql
+++ b/src/test/modules/test_extensions/sql/test_extdepend.sql
@@ -9,16 +9,16 @@ COPY test_extdep_commands FROM stdin;
  CREATE EXTENSION test_ext5 SCHEMA test_ext
  SET search_path TO test_ext
  CREATE TABLE a (a1 int)
-
+ -- function b
  CREATE FUNCTION b() RETURNS TRIGGER LANGUAGE plpgsql AS\n   $$ BEGIN NEW.a1 := NEW.a1 + 42; RETURN NEW; END; $$
  ALTER FUNCTION b() DEPENDS ON EXTENSION test_ext5
-
+ -- trigger c
  CREATE TRIGGER c BEFORE INSERT ON a FOR EACH ROW EXECUTE PROCEDURE b()
  ALTER TRIGGER c ON a DEPENDS ON EXTENSION test_ext5
-
+ -- materialized view d
  CREATE MATERIALIZED VIEW d AS SELECT * FROM a
  ALTER MATERIALIZED VIEW d DEPENDS ON EXTENSION test_ext5
-
+ -- index e
  CREATE INDEX e ON a (a1)
  ALTER INDEX e DEPENDS ON EXTENSION test_ext5
  RESET search_path
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 1047399ef8..591149dee9 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -275,10 +275,18 @@ from pg_attribute
 where attrelid = 'gexec_test'::regclass and attnum > 0
 order by attnum
 \gexec
+-- QUERY:
 create index on gexec_test(a)
+
+-- QUERY:
 create index on gexec_test(b)
+
+-- QUERY:
 create index on gexec_test(c)
+
+-- QUERY:
 create index on gexec_test(d)
+
 -- \gexec should work in FETCH_COUNT mode too
 -- (though the fetch limit applies to the executed queries not the meta query)
 \set FETCH_COUNT 1
@@ -288,13 +296,17 @@ select 'drop table gexec_test', NULL
 union all
 select 'drop table gexec_test', 'select ''2000-01-01''::date as party_over'
 \gexec
+-- QUERY:
 select 1 as ones
+
  ones 
 ------
     1
 (1 row)
 
+-- QUERY:
 select x.y, x.y*2 as double from generate_series(1,4) as x(y)
+
  y | double 
 ---+--------
  1 |      2
@@ -303,10 +315,16 @@ select x.y, x.y*2 as double from generate_series(1,4) as x(y)
  4 |      8
 (4 rows)
 
+-- QUERY:
 drop table gexec_test
+
+-- QUERY:
 drop table gexec_test
+
 ERROR:  table "gexec_test" does not exist
+-- QUERY:
 select '2000-01-01'::date as party_over
+
  party_over 
 ------------
  01-01-2000

Reply via email to