I’m using pgAdmin, and I want to have a simple raise notice; referring to this, I entered RAISE NOTICE 'note';
and got this error:
ERROR: syntax error at or near "RAISE"
LINE 1: RAISE NOTICE 'note';
The only way I could manage to get an output was by using this (which I don’t understand well either):
DO $$
BEGIN
RAISE NOTICE 'note';
END;
$$ LANGUAGE plpgsql
And got this output:
NOTICE: note
DO
Could someone please explain this?
2
Answers
RAISE
is a PL/pgSQL command and can only be used inside PL/pgSQL. The DO command creates an anonymous PL/pgSQL block (something like a "temporary procedure") and therefor you can use RAISE inside that PL/pgSQL code.RAISE
can not be used in plain SQL, that’s why you get the errorWrap
RAISE
into a procedureand call it in SQL
For PG version before 11 create a function that
returns void
with the same body andselect
from it in SQL