This tool can help you learn things like:
1. How many rows were affected by a command?
2. What's the unique ID of the last row that was added to a table?
3. If there was an error, what's the reason for it?
You can use this tool in a program or script to check these things.
For example, if you update some data in a table, you can use "GET DIAGNOSTICS" to see how many rows got changed and if there was any problem. This can be really handy for keeping track of what's going on when you're working with a database.
Example:
-- Let's say we update some data in a table.
UPDATE my_table SET column1 = 'new_value' WHERE id = 42;-- Now, we want to know how many rows got changed and if there's a unique ID for the last row.
GET DIAGNOSTICS rows_affected = ROW_COUNT, last_oid = RESULT_OID;-- We can print these values to see what happened.
RAISE NOTICE 'Rows affected: %, Last OID: %', rows_affected, last_oid;