How to raise notice in postgresql?

Member

by lew , in category: MySQL , a month ago

How to raise notice in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , a month ago

@lew 

To raise a notice in PostgreSQL, you can use the RAISE NOTICE command. Here's an example of how you can use it:

1
2
3
4
5
DO $$
BEGIN
    RAISE NOTICE 'This is a notice message';
END;
$$;


In this example, the RAISE NOTICE command is used inside a DO block. When the block is executed, it will display the notice message 'This is a notice message' in the PostgreSQL log.


You can also include variables in the notice message like this:

1
2
3
4
5
6
7
DO $$
DECLARE
    var1 INT := 10;
BEGIN
    RAISE NOTICE 'The value of var1 is %', var1;
END;
$$;


In this example, the value of the variable var1 will be included in the notice message.


Notices are only visible in the PostgreSQL log and are mainly used for debugging and monitoring purposes. They do not stop the execution of the current transaction.