0

For a migration I have automatically built scripts containing anonymous blocks for every entity to update and keep a log table for the results.

DO $$
DECLARE productId varchar;
BEGIN
  productId := getProductId('9783980493017');
  update product set ...;
  ...
EXCEPTION
  WHEN OTHERS THEN
  insert into mig_messages(createddate,identifier,message)
  values(now(), '9783980493017', SQLERRM);
END $$;

This works fine so far. But when I run these scripts with psql every DO is printed on the prompt. This sounds a bit silly, but there are lots of scripts with lots of product update blocks in it (about 5 millions or more). How can I suppress this output without redirecting it completely to /dev/null or switching psql to silent? At last there MAY be some output I want to see (errors, warnings etc.).

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
  • 1
    Does the `--quiet` parameter do what you want? –  Jan 13 '15 at 08:34
  • @a_horse_with_no_name Does --quiet still print error messages? I would especially be interested in lost connections or other "hard" errors not generated by my script itself. – Uwe Allner Jan 13 '15 at 08:45
  • OK, it does; I have tried it out and it printed a syntax error. Thanks :) – Uwe Allner Jan 13 '15 at 09:24

1 Answers1

1

I would prepend the script with this line:

SET client_min_messages=WARNING

Or start psql with that setting in the environment (I am using this in bash).

env PGOPTIONS='-c client_min_messages=WARNING' psql ...

This way you still get messages with severity WARNING or higher.
Related:

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228