May 2020
Beginner
564 pages
14h 9m
English
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.
Read now
Unlock full access