Can we use RAISE NOTICE
in postgres as equivalent of RAISERROR
'message to display' WITH NOWAIT
in SQL Server, or is there a better way to print intermediate messages while postgres queries are running? Please suggest if there is better way to print run time messages in postgres.
INSERT INTO tbl1 (col1) values (val1); DO $$ begin raise notice 'insert tbl1 done!'; end; $$; UPDATE tbl2 set col2='val2' where ...; DO $$ begin raise notice 'update tbl2 done!'; end; $$;
I apologize if this code is too bad to comment, pls do suggest a better way to do it, Thanks
Postgresql now() The NOW() function in Postgresql is used to get the current date and time. The return type of the NOW() function is the timestamp with the time zone. We can fetch the current date and time by using the PostgreSQL NOW() function. This function has a return type i.e. the timestamp with the time zone.
You can use \timing only with the command line client psql , since this is a psql command. It is a switch that turns execution time reporting on and off: test=> \timing Timing is on.
RAISE is used to raise errors and report messages, PostgreSQL provides various parameters to report an error, warning, and information at a detailed level.
you can use very simple statement in function everywhere.
DO $$ begin raise notice '%',now(); end; $$;
function for reference:
create or replace function test() RETURNS bool AS ' begin raise notice ''%'',now(); for i IN 0..50000000 loop end loop raise notice ''%'',now(); return true; end;
LANGUAGE 'plpgsql';
Yes, you can use RAISE NOTICE
like below. It's correct the way you are doing.
RAISE NOTICE 'i want to print % and %', var1,var2;
See here for more information https://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html
EDIT:
begin INSERT INTO tbl1 (col1) values (val1); raise notice 'insert tbl1 done!'; end;
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