Anonymous code block:
DO $$
BEGIN
raise notice 'hello world';
END; $$;
Anonymous block for error handling:
DO $$
BEGIN
begin
raise exception 'no bueno';
exception
when others then
raise notice 'something went wrong';
end;
begin
raise exception 'muy mal' using errcode = 'feature_not_supported';
exception
when feature_not_supported then
raise notice 'the feature is not supported';
end;
END; $$;
Function:
CREATE OR REPLACE FUNCTION say_hello(name text)
RETURNS text AS $$
BEGIN
raise notice 'saying hello to %', name;
return 'Hello ' || name;
END; $$ LANGUAGE plpgsql;
SELECT say_hello('dave');