Changing message output in PostgreSQL and pgAdminIII

This is a small thing, but it annoys me a little and it seems that there is probably a way to configure it. Say I have the following:

CREATE OR REPLACE FUNCTION baz() RETURNS void AS $BODY$ DECLARE BEGIN RAISE NOTICE 'I also did some work!'; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; CREATE OR REPLACE FUNCTION bar() RETURNS void AS $BODY$ DECLARE BEGIN RAISE NOTICE 'I did a bunch of work and want you to know about it'; PERFORM baz(); END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; CREATE OR REPLACE FUNCTION foo() RETURNS void AS $BODY$ DECLARE BEGIN PERFORM bar(); END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; select foo(); 

I get the following output messages:

 NOTICE: I did a bunch of work and want you to know about it CONTEXT: SQL statement "SELECT bar()" PL/pgSQL function "foo" line 4 at PERFORM NOTICE: I also did some work! CONTEXT: SQL statement "SELECT baz()" PL/pgSQL function "bar" line 5 at PERFORM SQL statement "SELECT bar()" PL/pgSQL function "foo" line 4 at PERFORM Total query runtime: 31 ms. 1 row retrieved. 

I want (usually) just to see something like:

 NOTICE: I did a bunch of work and want you to know about it NOTICE: I also did some work! Total query runtime: 31 ms. 1 row retrieved. 

Is there any way to control / change this? Again, this is a small thing and there is hardly a question about Stackoverflow, but if you have a lot of things going on, it starts to introduce a lot of noise into the result, and this forces me to overload the brain, trying to sift through it :)

I am using PostgreSQL 9.1.5 with pgAdminIII 1.16.0

+4
source share
2 answers

Try connecting to the -q option. Q stands for Quiet and may be what you need.

 psql -q -d foo_db 

you can also try:

  • \set verbosity terse
  • \set quiet on
+3
source

If you want more control over messaging and the interface, it might be worth switching to the real scripting language. Writing database scripts in tools like Python with psycopg2 or Perl with DBD::Pg and DBI is pretty simple.

Not only does using a real scripting language give you full control over messaging, but it also gives you control over error handling, gives you loops and other control structures, and usually offers a much nicer model than raw SQL for scripting tasks.

0
source

Source: https://habr.com/ru/post/1440814/


All Articles