Error handling in PostgreSQL

PostgreSQL does error handling with the RAISE statement. Any errors will be caught in the RAISE statement when it's used. 

The following query will try to insert values into the allstarfull table and use RAISE to output the error:

DO $$ 
BEGIN
INSERT INTO allstarfull
(playerid, yearid, gamenum)
VALUES ('aaronha01', 1958, 0);

exception when others then
RAISE notice '% %', SQLERRM, SQLSTATE;

END $$;

You will receive an error with those variables set as-is because there is a primary key violation: 

duplicate key value violates unique constraint "allstarfull$index_2bd68208_c8b4_4347" 23505

To learn more about error handling in PostgreSQL, take a look at the Further reading section. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.39.142