Здесь показаны различия между двумя версиями данной страницы.
| Следующая версия | Предыдущая версия | ||
|
postgres:raise_exception [2021/11/02 14:40] werwolf создано |
postgres:raise_exception [2023/01/12 12:18] (текущий) |
||
|---|---|---|---|
| Строка 51: | Строка 51: | ||
| If we need to raise an error, we need to use the exception level after using the raise statement in it. | If we need to raise an error, we need to use the exception level after using the raise statement in it. | ||
| - | .othr-cour a{color:#4a4a4a!important;border-bottom:none}.othr-cour a:hover{border-bottom:1px solid!important}.box-div .fa-book:before{content:"\f14e"}.box-div .fa-book{background-image:linear-gradient(to top,#0ba360 0,#3cba92 100%);padding:15px;border-radius:5px;color:#f0f8ff;font-size:50px}.box-div .fa-flash:before,.fa-bolt:before{content:"\f1fa"}.box-div .box-btn{width:max-content;cursor:pointer;transition:all .2s ease;padding:10px 30px;line-height:1.33;border-radius:4px;color:#fff;background:#ff8c00;border:thin solid #ff8c00;margin-bottom:0;font-weight:700;text-align:center;vertical-align:middle;font-size:15px;display:block;letter-spacing:1px;background-image:linear-gradient(to top,#e93f33,#ea4b32,#eb5632,#ec6032,#ec6a33);}.box-div{border:1px #bfbfbf solid;margin:10px 0 25px 0;padding:24px;width:100%;-webkit-box-shadow:-8px 9px 5px -8px rgba(0,0,0,.75);-moz-box-shadow:-8px 9px 5px -8px rgba(0,0,0,.75);box-shadow:-8px 9px 5px -8px rgba(0,0,0,.75)}.box-div .course-title{font-weight:600;font-size:1em;letter-spacing:1px;display:block}.box-div .fa-star{font-size:15px;color:#f5af12;margin-right:4px}.box-div .price-box{text-align:-webkit-center}@media (min-device-width :320px) and (max-device-width :520px){.box-div .banr-image{display:none}.box-div .price-box{text-align:-webkit-left}}@media (min-device-width :320px) and (max-device-width :767px){.sale-bf{position:absolute;width:80px;margin-top:-5.4em;right:0em}}.box-div .othr-cour{border-radius:4px;border:solid 1px #4a4a4a;margin-right:12px;padding:5px 10px;font-size:14px;font-weight:400;display:inline-block;margin-bottom:5px;cursor:pointer;line-height:1.4}.box-div .rel-cour{font-size:16px;padding-bottom:5px}@media (min-device-width :768px){.centertext{text-align:center}.sale-bf{position:absolute;width:120px;margin-top:-6.1em;right:2.5em}}.blg-price{font-size:1.5em}.blg-str-price strike{font-size:1.2em;color:grey}.box-div hr{margin:0 0 .5em;padding:.5em 0 0}.box-div .course-title{line-height:25px}.box-div .banr-image{text-align:center;margin-top:20px}.box-div .bundle_link{text-decoration:none;color:#000;border:0}.box-div .bullets{font-weight:400;font-size:.8em}#banner_1 .three-sixths{margin-top:15px}#banner_1 .five-sixths{width:100%;margin:0}#banner_1 .course-price{font-size:1em} | ||
| We can also add more detailed information about the error by using the following clause with the raise exception statement in it. | We can also add more detailed information about the error by using the following clause with the raise exception statement in it. | ||
| Строка 76: | Строка 75: | ||
| ''DO $$\\ BEGIN\\ RAISE INFO 'Print the message of information %', now() ;\\ RAISE LOG 'Print the message of log %', now();\\ RAISE DEBUG 'Print the message of debug %', now();\\ RAISE WARNING 'Print the message of warning %', now();\\ RAISE NOTICE 'Print the message of notice %', now();\\ RAISE EXCEPTION 'Print the message of exception %', now();\\ END $$;'' | ''DO $$\\ BEGIN\\ RAISE INFO 'Print the message of information %', now() ;\\ RAISE LOG 'Print the message of log %', now();\\ RAISE DEBUG 'Print the message of debug %', now();\\ RAISE WARNING 'Print the message of warning %', now();\\ RAISE NOTICE 'Print the message of notice %', now();\\ RAISE EXCEPTION 'Print the message of exception %', now();\\ END $$;'' | ||
| - | **Output:** | ||
| - | {{https://cdn.educba.com/academy/wp-content/uploads/2020/06/PostgreSQL-RAISE-EXCRPTION-1.jpg.webp?801x299|PostgreSQL RAISE EXCEPTION 1}} {{https://cdn.educba.com/academy/wp-content/uploads/2020/06/PostgreSQL-RAISE-EXCRPTION-1.jpg.webp?801x299|PostgreSQL RAISE EXCEPTION 1}} In the above example, only info, warning, notice and exception will display the information. But debug and log will not display the output information. | + | In the above example, only info, warning, notice and exception will display the information. But debug and log will not display the output information. |
| === Example #2 === | === Example #2 === | ||
| Строка 91: | Строка 89: | ||
| ''DO $$\\ DECLARE\\ personal_email varchar(100) := 'raise@exceptions.com';\\ BEGIN\\ -- First check the user email id is correct as well as duplicate or not.\\ -- If user email id is duplicate then report mail as duplicate.\\ RAISE EXCEPTION 'Enter email is duplicate: %', personal_email\\ USING HINT = 'Check email and enter correct email ID of user';\\ END $$;'' | ''DO $$\\ DECLARE\\ personal_email varchar(100) := 'raise@exceptions.com';\\ BEGIN\\ -- First check the user email id is correct as well as duplicate or not.\\ -- If user email id is duplicate then report mail as duplicate.\\ RAISE EXCEPTION 'Enter email is duplicate: %', personal_email\\ USING HINT = 'Check email and enter correct email ID of user';\\ END $$;'' | ||
| - | **Output:** | ||
| - | {{data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20797%20304'%3E%3C/svg%3E?797x304|PostgreSQL RAISE EXCEPTION 2}} {{https://cdn.educba.com/academy/wp-content/uploads/2020/06/PostgreSQL-RAISE-EXCRPTION-2.jpg.webp?797x304|PostgreSQL RAISE EXCEPTION 2}} === Example #3 === | + | |
| + | === Example #3 === | ||
| Raise exception by creating function. | Raise exception by creating function. | ||
| Строка 100: | Строка 98: | ||
| **Code:** | **Code:** | ||
| + | <code sql> | ||
| + | create or replace function test_exp() returns void as\\ $$\\ begin\\ raise exception using message = 'S 167', detail = 'D 167', hint = 'H 167', errcode = 'P3333';\\ end;\\ $$ language plpgsql\\ ; | ||
| + | </code> | ||
| - | ''create or replace function test_exp() returns void as\\ $$\\ begin\\ raise exception using message = 'S 167', detail = 'D 167', hint = 'H 167', errcode = 'P3333';\\ end;\\ $$ language plpgsql\\ ;'' | + | ==== Advantages of PostgreSQL RAISE EXCEPTION ==== |
| - | + | ||
| - | **Output:** | + | |
| - | + | ||
| - | {{data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20794%20257'%3E%3C/svg%3E?794x257|creating function}} {{https://cdn.educba.com/academy/wp-content/uploads/2020/06/PostgreSQL-RAISE-EXCEPTION-3.jpg.webp?794x257|creating function}} ==== Advantages of PostgreSQL RAISE EXCEPTION ==== | + | |
| Below are the advantages: | Below are the advantages: | ||