postgresqlplpgsqlpsql

PostgreSQL : when using RAISE NOTICE in psql, can I avoid the "NOTICE :" prefix from the output


I am trying to port some functionalities from Oracle PL/SQL to PostgreSQL PL/pgSQL.

As it seems to be the most common way of printing text to screen, I would like to use the RAISE NOTICE to display messages on the standard output, output that would go to a file using -o file.txt argument of psql.

Problem is that the message level (here RAISE NOTICE 'msg' => level : NOTICE) goes before the message in the output (prefix) and I don't like it.

E.g. this PL/pgSQL code when run in psql :

DO $$
BEGIN
  RAISE NOTICE 'my message';
END; $$;

will generate this output :

NOTICE:  my message

Is there any way to remove the message level before the message itself ? (here I would like to avoid "NOTICE :" prefix).

PS : I have seen this post where the same question is asked in the context of psycopg2, but here my context is the psql tool.

Also this other post is close to what I'm trying to do here but the answer is not satisfying to me.

NB: I'm using latest PostgreSQL and psql (version 12.1).


Solution

  • No, you cannot. This is the behaviour of libpq - Postgres driver, and psql uses this driver.