I'm trying to run this in PostgreSQL 9.2:
RAISE NOTICE 'hello, world!';
And the server says:
Error : ERROR: syntax error at or near "RAISE" LINE 1: RAISE NOTICE 'hello, world!' ^
Why?
“lang_name” is simply the name of the procedural language. If the language is not mentioned, PostgreSQL will use the default procedural language, PL/pgSQL. $$ (double quoting) is a PostgreSQL substitute for single quotes to avoid quoting issues inside the BEGIN block.
To execute a block from pgAdmin, you click the Execute button as shown in the following picture: Notice that the DO statement does not belong to the block. It is used to execute an anonymous block. PostgreSQL introduced the DO statement since version 9.0.
PL/pgSQL's BEGIN / END are only for grouping; they do not start or end a transaction. See Section 43.8 for information on managing transactions in PL/pgSQL. Also, a block containing an EXCEPTION clause effectively forms a subtransaction that can be rolled back without affecting the outer transaction.
Use an anonymous code block:
DO language plpgsql $$ BEGIN RAISE NOTICE 'hello, world!'; END $$;
Variables are referenced using %
:
RAISE NOTICE '%', variable_name;
raise
is PL/pgSQL
only.
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html
create or replace function r(error_message text) returns void as $$ begin raise notice '%', error_message; end; $$ language plpgsql; select r('an error message'); NOTICE: an error message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With