Print to console as SQL executes When executing multiple SQL commands, such as in the pgAdmin SQL Editor, how can I print some strings to the console (output pane in pgAdmin). I want to monitor execution.

UPDATE x
SET a = b 
WHERE a IS NULL
;

Print to console --&gt; Finished x.

UPDATE y
SET a = b 
WHERE a IS NULL
;

Print to console --&gt; Finished y.


My question is the same as this StackOverflow Question. Or, as Craig Ringer interpreted that Question:


  Do you wish to observe SQL queries that are run by PgAdmin-III by printing them to standard error, viewed by launching PgAdmin-III on a cmd.exe interactive console? 




I have seen remarks about \echo 'some_text'. But that gives me the error:

ERROR: syntax error at or near "\"
SQL state: 42601
The only way I have found is through a stored procedure

CREATE OR REPLACE FUNCTION print_notice(msg text) 
  RETURNS integer AS 
$$ 
DECLARE 
BEGIN 
    RAISE NOTICE USING MESSAGE = msg;
    RETURN null;
END; 
$$ 
LANGUAGE 'plpgsql' IMMUTABLE; 


So, executing SELECT print_notice('Foo ' || someText || ' !');

Will produce (for example) :

NOTICE:  Foo whatever !
query result with 1 row discarded.


I'm not sure if this can be done without the SELECT and the query ... row discarded message. But it works.