
{"id":4677,"date":"2023-11-22T05:31:54","date_gmt":"2023-11-22T05:31:54","guid":{"rendered":"https:\/\/test.opensource-db.in\/wp1\/?p=4677"},"modified":"2023-11-22T05:31:55","modified_gmt":"2023-11-22T05:31:55","slug":"mastering-postgresql-rollbacks-savepoints","status":"publish","type":"post","link":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/","title":{"rendered":"Mastering PostgreSQL: Rollback to Savepoints !!"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The word &#8220;Transaction&#8221; will ring so many bells and whistles, but in this topic&#8217;s context a &#8220;Transaction&#8221; is a call to a database function or procedure that can have one or multiple DML operations like Insert, Update, or Delete.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For database administrators tasked with managing PostgreSQL databases, ensuring data integrity and consistency during complex data manipulation operations is paramount. If you&#8217;re transitioning from Oracle or need to handle complex nested DML (Data Manipulation Language) operations, understanding how to achieve rollback to a savepoint in PostgreSQL is crucial.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rolling back to a savepoint in PostgreSQL allows you to revert the database to a specific point within a transaction, rather than rolling back the entire transaction. This is useful when you want to undo part of a transaction while preserving changes made before the savepoint.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Transitioning from Oracle: A Brief Overview<\/b><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SAVEPOINT and ROLLBACK TO are well-known concepts for those experienced with Oracle databases. These commands in Oracle enable the creation of savepoints within nested transactions and provide the ability to roll back to these savepoints when necessary.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how to achieve rollback to a savepoint in Oracle:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start a transaction block using `BEGIN`<\/li>\n\n\n\n<li>Set a Savepoint, use the SAVEPOINT command mentioned below:<br>`SAVEPOINT &lt;savepoint name&gt;;`<\/li>\n\n\n\n<li>Perform one or more Database Operations within the transaction, such as INSERT, UPDATE, or DELETE<\/li>\n\n\n\n<li>In between these multiple Database operations, if an error or on any restricted Business Logic occurs then Roll Back to the Savepoint.<\/li>\n\n\n\n<li>To roll back to the savepoint, use the below command<br>`ROLLBACK TO &lt;savepoint name&gt;;`<\/li>\n\n\n\n<li>At the end of the Business Logic, use a COMMIT or ROLLBACK, as per the need.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">However, the transition to PostgreSQL may raise questions about the relevance of SAVEPOINT and ROLLBACK TO. PostgreSQL adheres to SQL:2016 standards, ensuring compatibility and consistency with your SQL database knowledge. PostgreSQL supports these commands only in developer IDE\u2019s but not in a Database function or a procedure where we need to handle a Business Scenario.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It means, even though PostgreSQL has the rollback and savepoint keywords, they cannot be used inside a stored procedure or function. If we use them, we get below error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SQL Error [0A000]: ERROR: unsupported transaction command in PL\/pgSQL<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The good news is that we can achieve Rollback To Savepoint in PostgreSQL procedures and functions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ironically you never use the keywords savepoint or rollback as they are automatically invoked in a BEGIN-EXCEPTION-BLOCK. The below example explains how to do it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Understanding Rollback to Savepoint in PostgreSQL<\/b><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To grasp how to implement rollback to savepoint in PostgreSQL, let&#8217;s consider a practical example with our favorite two tables &#8220;<code>osdb_dept<\/code>&#8221; and &#8220;<code>osdb_emp<\/code>&#8220;, with &#8220;<code>osdb_dept<\/code>&#8221; serving as the parent table and linked to &#8220;<code>osdb_emp<\/code>&#8221; child table, through the &#8220;<code>dept_id<\/code>&#8221; column.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Scenario:<\/b><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Start Loop-1 through each department in the parent table &#8220;<code>osdb_dept\"<\/code>&nbsp;<\/li>\n\n\n\n<li>Start another Loop-2 (inside Loop-1) through each employee in the child table &#8220;<code>osdb_emp\"<\/code> for a given department from Loop-1.&nbsp;<\/li>\n\n\n\n<li>Start SAVEPOINT<\/li>\n\n\n\n<li>If the Department Location is:\n<ul class=\"wp-block-list\">\n<li>Hyderabad then set commission to 2000<\/li>\n\n\n\n<li>Bangalore then set commission to 2500<\/li>\n\n\n\n<li>Others then set commission to 1500<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>If Employee Role is:\n<ul class=\"wp-block-list\">\n<li>Manager then set salary to salary + 5%<\/li>\n\n\n\n<li>Accountant then set salary to salary + 8%<\/li>\n\n\n\n<li>Others then set salary to salary + 10%<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>If Employee Grade is:\n<ul class=\"wp-block-list\">\n<li>M1 and status = ACTIVE then set bonus to bonus + 1000<\/li>\n\n\n\n<li>A1 and status = ACTIVE then set bonus to bonus + 500<\/li>\n\n\n\n<li>NULL or status = NEW_HIRE then rollback all changes done so far, for that employee only.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Update all Employee bonus to bonus + 300<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Below is the script for creating the necessary tables and data:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drop table osdb_dept;\ndrop table osdb_emp;\n\n\ncreate table osdb_dept\n(dept_id       int2\n,dept_name     text\n,dept_location text);\n\n\ninsert into osdb_dept values(10,'ACCOUNTING','HYDERABAD');\ninsert into osdb_dept values(20,'HR','BANGALORE');\ninsert into osdb_dept values(30,'IT','HYDERABAD');\n\n\ncreate table osdb_emp\n(emp_id        int2\n,emp_name      text\n,dept_id       int2\n,role_name     text\n,grade_name    text\n,status        text\n,salary        int4\n,commission    int4\n,bonus         int4\n,comments      text);\n\n\ninsert into osdb_emp values(101,'Govind'  ,10,'Accountant','A1','ACTIVE'   ,10000,200,500  ,null);\ninsert into osdb_emp values(102,'Divya'   ,20,'HR'        ,'A1','ACTIVE'   ,12000,300,600  ,null);\ninsert into osdb_emp values(103,'Vinay'   ,30,'Manager'   ,'M1','ACTIVE'   ,32000,600,1000 ,null);\ninsert into osdb_emp values(104,'Krishna' ,30,'Manager'   ,'M1','NEW_HIRE' ,32000,600,1000 ,null);\ninsert into osdb_emp values(105,'Ramya'   ,30,'Associate' ,'C1','ACTIVE'   ,15000,300,600  ,null);\ninsert into osdb_emp values(106,'Sanjay'  ,30,'DBA'       ,'D1','ACTIVE'   ,18000,400,700  ,null);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">select * from osdb_dept;&nbsp;<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><b>DEPT_ID<\/b><\/td><td><b>DEPT_NAME<\/b><\/td><td><b>DEPT_LOCATION<\/b><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">10<\/span><\/td><td><span style=\"font-weight: 400;\">ACCOUNTING<\/span><\/td><td><span style=\"font-weight: 400;\">HYDERABAD<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">20<\/span><\/td><td><span style=\"font-weight: 400;\">HR<\/span><\/td><td><span style=\"font-weight: 400;\">BANGALORE<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">IT<\/span><\/td><td><span style=\"font-weight: 400;\">HYDERABAD<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">select<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> osdb_emp;<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><b>EMPID<\/b><\/td><td><b>EMP NAME<\/b><\/td><td><b>DEPT<\/b><b>ID<\/b><\/td><td><b>ROLE<\/b><b>NAME<\/b><\/td><td><b>GRADE<\/b><b>NAME<\/b><\/td><td><b>STATUS<\/b><\/td><td><b>SALARY<\/b><\/td><td><b>COMMISSION<\/b><\/td><td><b>BONUS<\/b><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">101<\/span><\/td><td><span style=\"font-weight: 400;\">Govind<\/span><\/td><td><span style=\"font-weight: 400;\">10<\/span><\/td><td><span style=\"font-weight: 400;\">Accountant<\/span><\/td><td><span style=\"font-weight: 400;\">A1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">10000<\/span><\/td><td><span style=\"font-weight: 400;\">200<\/span><\/td><td><span style=\"font-weight: 400;\">500<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">102<\/span><\/td><td><span style=\"font-weight: 400;\">Divya<\/span><\/td><td><span style=\"font-weight: 400;\">20<\/span><\/td><td><span style=\"font-weight: 400;\">HR<\/span><\/td><td><span style=\"font-weight: 400;\">A1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">12000<\/span><\/td><td><span style=\"font-weight: 400;\">300<\/span><\/td><td><span style=\"font-weight: 400;\">600<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">103<\/span><\/td><td><span style=\"font-weight: 400;\">Vinay<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Manager<\/span><\/td><td><span style=\"font-weight: 400;\">M1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">32000<\/span><\/td><td><span style=\"font-weight: 400;\">600<\/span><\/td><td><span style=\"font-weight: 400;\">1000<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">104<\/span><\/td><td><span style=\"font-weight: 400;\">Krishna<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Manager<\/span><\/td><td><span style=\"font-weight: 400;\">M1<\/span><\/td><td><span style=\"font-weight: 400;\">NEW_HIRE<\/span><\/td><td><span style=\"font-weight: 400;\">32000<\/span><\/td><td><span style=\"font-weight: 400;\">600<\/span><\/td><td><span style=\"font-weight: 400;\">1000<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">105<\/span><\/td><td><span style=\"font-weight: 400;\">Ramya<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Associate<\/span><\/td><td><span style=\"font-weight: 400;\">C1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">15000<\/span><\/td><td><span style=\"font-weight: 400;\">300<\/span><\/td><td><span style=\"font-weight: 400;\">600<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">106<\/span><\/td><td><span style=\"font-weight: 400;\">Sanjay<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">DBA<\/span><\/td><td><span style=\"font-weight: 400;\">D1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">18000<\/span><\/td><td><span style=\"font-weight: 400;\">400<\/span><\/td><td><span style=\"font-weight: 400;\">700<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Below is the actual script that shows the implementation of rollback to savepoint in PostgreSQL pl\/pgsql:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">DO $<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">DECLARE<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;l_return_msg &nbsp; <\/span><span style=\"font-weight: 400;\">text<\/span><span style=\"font-weight: 400;\">;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;l_dept_rec &nbsp; &nbsp; record;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;l_emp_rec&nbsp; &nbsp; &nbsp; record;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">BEGIN<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">FOR<\/span><span style=\"font-weight: 400;\"> l_dept_rec <\/span><span style=\"font-weight: 400;\">IN<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">SELECT<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">FROM<\/span><span style=\"font-weight: 400;\"> osdb_dept <\/span><span style=\"font-weight: 400;\">ORDER BY<\/span><span style=\"font-weight: 400;\"> dept_id)<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">LOOP<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--RAISE NOTICE 'l_dept_rec.dept_id = %', l_dept_rec.dept_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">FOR<\/span><span style=\"font-weight: 400;\"> l_emp_rec <\/span><span style=\"font-weight: 400;\">IN<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">SELECT<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">FROM<\/span><span style=\"font-weight: 400;\"> osdb_emp&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE<\/span><span style=\"font-weight: 400;\"> dept_id <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> l_dept_rec.dept_id <\/span><span style=\"font-weight: 400;\">ORDER BY<\/span><span style=\"font-weight: 400;\"> emp_id)<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">LOOP<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RAISE NOTICE <\/span><span style=\"font-weight: 400;\">'emp_id = %'<\/span><span style=\"font-weight: 400;\">, l_emp_rec.emp_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--BEGIN-EXCEPTION Block - START<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">BEGIN<\/span><span style=\"font-weight: 400;\">&nbsp; <\/span><span style=\"font-weight: 400;\">--&gt; This is equal to SAVEPOINT.&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u2013-&gt; So for each emp record this serves as a savepoint<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">update<\/span><span style=\"font-weight: 400;\"> osdb_emp<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">set<\/span><span style=\"font-weight: 400;\"> commission <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> l_dept_rec.dept_location <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'HYDERABAD'<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span> <span style=\"font-weight: 400;\">2000<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> l_dept_rec.dept_location <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'BANGALORE'<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span> <span style=\"font-weight: 400;\">2500<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">1500<\/span> <span style=\"font-weight: 400;\">end<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">where<\/span><span style=\"font-weight: 400;\"> emp_id &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">update<\/span><span style=\"font-weight: 400;\"> osdb_emp<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">set<\/span><span style=\"font-weight: 400;\"> salary &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> role_name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'Manager'<\/span><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span><span style=\"font-weight: 400;\"> salary <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> (salary<\/span><span style=\"font-weight: 400;\">*<\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">100<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> role_name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'Accountant'<\/span><span style=\"font-weight: 400;\">&nbsp;&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span><span style=\"font-weight: 400;\"> salary <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> (salary<\/span><span style=\"font-weight: 400;\">*<\/span><span style=\"font-weight: 400;\">8<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">100<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> salary <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> (salary<\/span><span style=\"font-weight: 400;\">*<\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">100<\/span><span style=\"font-weight: 400;\">)&nbsp; <\/span><span style=\"font-weight: 400;\">end<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">where<\/span><span style=\"font-weight: 400;\"> emp_id &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> l_emp_rec.grade_name <\/span><span style=\"font-weight: 400;\">is<\/span> <span style=\"font-weight: 400;\">null<\/span> <span style=\"font-weight: 400;\">or<\/span><span style=\"font-weight: 400;\"> l_emp_rec.status <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'NEW_HIRE'<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l_return_msg :<\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'Rollback for NEW_HIRE, '<\/span> <span style=\"font-weight: 400;\">||<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_name&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||<\/span> <span style=\"font-weight: 400;\">' (emp_id = '<\/span> <span style=\"font-weight: 400;\">||<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_id <\/span><span style=\"font-weight: 400;\">||<\/span> <span style=\"font-weight: 400;\">')'<\/span><span style=\"font-weight: 400;\">;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RAISE EXCEPTION <\/span><span style=\"font-weight: 400;\">USING<\/span><span style=\"font-weight: 400;\"> errcode <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'50001'<\/span><span style=\"font-weight: 400;\">;&nbsp;&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; The above raise statement is not rollback, but when this&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; raise gets caught in the exception block, Postgres executes<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; rollback to the DML's within that BEGIN-EXCEPTION Block.<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">else<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">update<\/span><span style=\"font-weight: 400;\"> osdb_emp<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">set<\/span><span style=\"font-weight: 400;\"> bonus&nbsp; &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> role_name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'Manager'<\/span><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span><span style=\"font-weight: 400;\"> bonus <\/span><span style=\"font-weight: 400;\">+<\/span> <span style=\"font-weight: 400;\">1000<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">when<\/span><span style=\"font-weight: 400;\"> role_name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'Accountant'<\/span><span style=\"font-weight: 400;\">&nbsp;&nbsp;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<\/span><span style=\"font-weight: 400;\"> bonus <\/span><span style=\"font-weight: 400;\">+<\/span> <span style=\"font-weight: 400;\">500<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> bonus <\/span><span style=\"font-weight: 400;\">end<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">where<\/span><span style=\"font-weight: 400;\"> emp_id &nbsp; &nbsp; <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">end<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\">;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXCEPTION<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">WHEN<\/span><span style=\"font-weight: 400;\"> SQLSTATE <\/span><span style=\"font-weight: 400;\">'50001'<\/span> <span style=\"font-weight: 400;\">THEN <\/span><span style=\"font-weight: 400;\">--&gt; This is where rollback happens<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RAISE NOTICE <\/span><span style=\"font-weight: 400;\">'%'<\/span><span style=\"font-weight: 400;\">, l_return_msg;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">WHEN<\/span><span style=\"font-weight: 400;\"> OTHERS <\/span><span style=\"font-weight: 400;\">THEN<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l_return_msg :<\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">'ERROR: '<\/span> <span style=\"font-weight: 400;\">||<\/span><span style=\"font-weight: 400;\"> SQLERRM;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RAISE NOTICE <\/span><span style=\"font-weight: 400;\">'%'<\/span><span style=\"font-weight: 400;\">, l_return_msg;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">END<\/span><span style=\"font-weight: 400;\">;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--BEGIN-EXCEPTION Block - END<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">update<\/span><span style=\"font-weight: 400;\"> osdb_emp <\/span><span style=\"font-weight: 400;\">set<\/span><span style=\"font-weight: 400;\"> bonus <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> bonus <\/span><span style=\"font-weight: 400;\">+<\/span> <span style=\"font-weight: 400;\">300<\/span> <span style=\"font-weight: 400;\">where<\/span><span style=\"font-weight: 400;\"> emp_id <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> l_emp_rec.emp_id;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">END<\/span> <span style=\"font-weight: 400;\">LOOP<\/span><span style=\"font-weight: 400;\">; <\/span><span style=\"font-weight: 400;\">-- For l_emp_rec<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">--<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">END<\/span> <span style=\"font-weight: 400;\">LOOP<\/span><span style=\"font-weight: 400;\">; <\/span><span style=\"font-weight: 400;\">-- For l_dept_rec<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">END<\/span><span style=\"font-weight: 400;\">;<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">$<\/span>$<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Script Output:<\/b><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">101<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">102<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">103<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">104<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">Rollback<\/span> <span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> NEW_HIRE, Krishna (emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">104<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">105<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">emp_id = 106<\/span><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Explanation in short:<\/b><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">For employee ID 104, as per the logic for status = NEW_HIRE, salary and commission will not be updated but the bonus will be updated by 300.&nbsp;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">So in the script, when we get an employee with status = NEW_HIRE, we raise an exception using errcode = 50001.&nbsp;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">This exception allows us to roll back to the last savepoint (i.e., BEGIN statement inside employee loop), preserving data consistency.&nbsp;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">We can see that all the other employees are updated as per the logic defined. Meaning, rollback only affected the one record that we wanted to, in the sample data. And that is rollback to savepoint for you !!<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"font-weight: 400;\"><b>Caveat:<\/b><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">This sample script is only for your understanding, please don&#8217;t take this as a standard of writing your code. It all boils down to your Business Requirements.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>After executing the script, the data in the &#8220;osdb_emp&#8221; table will look like this:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">select<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> osdb_emp;\n\n<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><b>EMPID<\/b><\/td><td><b>EMP NAME<\/b><\/td><td><b>DEPT<\/b><b>ID<\/b><\/td><td><b>ROLE<\/b><b>NAME<\/b><\/td><td><b>GRADE<\/b><b>NAME<\/b><\/td><td><b>STATUS<\/b><\/td><td><b>SALARY<\/b><\/td><td><b>COMMISSION<\/b><\/td><td><b>BONUS<\/b><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">101<\/span><\/td><td><span style=\"font-weight: 400;\">Govind<\/span><\/td><td><span style=\"font-weight: 400;\">10<\/span><\/td><td><span style=\"font-weight: 400;\">Accountant<\/span><\/td><td><span style=\"font-weight: 400;\">A1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">10800<\/span><\/td><td><span style=\"font-weight: 400;\">2000<\/span><\/td><td><span style=\"font-weight: 400;\">1300<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">102<\/span><\/td><td><span style=\"font-weight: 400;\">Divya<\/span><\/td><td><span style=\"font-weight: 400;\">20<\/span><\/td><td><span style=\"font-weight: 400;\">HR<\/span><\/td><td><span style=\"font-weight: 400;\">A1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">13200<\/span><\/td><td><span style=\"font-weight: 400;\">2500<\/span><\/td><td><span style=\"font-weight: 400;\">900<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">103<\/span><\/td><td><span style=\"font-weight: 400;\">Vinay<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Manager<\/span><\/td><td><span style=\"font-weight: 400;\">M1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><b>33600<\/b><\/td><td><b>2000<\/b><\/td><td><span style=\"font-weight: 400;\">2300<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">104<\/span><\/td><td><span style=\"font-weight: 400;\">Krishna<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Manager<\/span><\/td><td><span style=\"font-weight: 400;\">M1<\/span><\/td><td><span style=\"font-weight: 400;\">NEW_HIRE<\/span><\/td><td><b>32000<\/b><\/td><td><b>600<\/b><\/td><td><b>1300<\/b><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">105<\/span><\/td><td><span style=\"font-weight: 400;\">Ramya<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">Associate<\/span><\/td><td><span style=\"font-weight: 400;\">C1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">16500<\/span><\/td><td><span style=\"font-weight: 400;\">2000<\/span><\/td><td><span style=\"font-weight: 400;\">900<\/span><\/td><\/tr><tr><td><span style=\"font-weight: 400;\">106<\/span><\/td><td><span style=\"font-weight: 400;\">Sanjay<\/span><\/td><td><span style=\"font-weight: 400;\">30<\/span><\/td><td><span style=\"font-weight: 400;\">DBA<\/span><\/td><td><span style=\"font-weight: 400;\">D1<\/span><\/td><td><span style=\"font-weight: 400;\">ACTIVE<\/span><\/td><td><span style=\"font-weight: 400;\">19800<\/span><\/td><td><span style=\"font-weight: 400;\">2000<\/span><\/td><td><span style=\"font-weight: 400;\">1000<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Conclusion<\/b><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">As a proficient database administrator, mastering the PostgreSQL savepoint and rollback functionality is a crucial skill. This capability ensures data integrity, adheres to SQL:2016 standards, and guarantees the reliability of your PostgreSQL databases. If you have any inquiries or need additional assistance, please feel free to get in touch. Rest assured, we prioritize the security and consistency of your data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">&nbsp;<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: The word &#8220;Transaction&#8221; will ring so many bells and whistles, but in this topic&#8217;s context a &#8220;Transaction&#8221; is a [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":4886,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[23,42,89],"tags":[96,94,95],"class_list":["post-4677","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql-14","category-postgresql-15","category-postgresql-16","tag-nested-transactions","tag-rollback","tag-savepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB\" \/>\n<meta property=\"og:description\" content=\"Introduction: The word &#8220;Transaction&#8221; will ring so many bells and whistles, but in this topic&#8217;s context a &#8220;Transaction&#8221; is a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\" \/>\n<meta property=\"og:site_name\" content=\"OpenSource DB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-22T05:31:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-22T05:31:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"945\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Taraka Vuyyuru\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@opensource_db\" \/>\n<meta name=\"twitter:site\" content=\"@opensource_db\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Taraka Vuyyuru\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\"},\"author\":{\"name\":\"Taraka Vuyyuru\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/55546e9ca9552218b9376d4ecc8447a5\"},\"headline\":\"Mastering PostgreSQL: Rollback to Savepoints !!\",\"datePublished\":\"2023-11-22T05:31:54+00:00\",\"dateModified\":\"2023-11-22T05:31:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\"},\"wordCount\":904,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png\",\"keywords\":[\"nested transactions\",\"rollback\",\"savepoint\"],\"articleSection\":[\"PostgreSQL 14\",\"PostgreSQL 15\",\"PostgreSQL 16\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\",\"name\":\"Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png\",\"datePublished\":\"2023-11-22T05:31:54+00:00\",\"dateModified\":\"2023-11-22T05:31:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png\",\"contentUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png\",\"width\":1800,\"height\":945},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/test.opensource-db.in\/wp1\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering PostgreSQL: Rollback to Savepoints !!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#website\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/\",\"name\":\"OpenSource DB\",\"description\":\"Your Trusted OpenSource Databases partner\",\"publisher\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/test.opensource-db.in\/wp1\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\",\"name\":\"OPENSOURCE DB PRIVATE LIMITED\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png\",\"contentUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png\",\"width\":368,\"height\":120,\"caption\":\"OPENSOURCE DB PRIVATE LIMITED\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/\",\"https:\/\/x.com\/opensource_db\",\"https:\/\/www.youtube.com\/channel\/UCmTI5h\",\"https:\/\/www.linkedin.com\/company\/opensource-db\",\"https:\/\/www.instagram.com\/opensource_db\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/55546e9ca9552218b9376d4ecc8447a5\",\"name\":\"Taraka Vuyyuru\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/54256c344d6c1f7dbb87fa257d6e318d1ddcd0a29320b642116bfa20e693616b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/54256c344d6c1f7dbb87fa257d6e318d1ddcd0a29320b642116bfa20e693616b?s=96&d=mm&r=g\",\"caption\":\"Taraka Vuyyuru\"},\"url\":\"https:\/\/test.opensource-db.in\/wp1\/author\/taraka\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB","og_description":"Introduction: The word &#8220;Transaction&#8221; will ring so many bells and whistles, but in this topic&#8217;s context a &#8220;Transaction&#8221; is a [&hellip;]","og_url":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/","og_site_name":"OpenSource DB","article_publisher":"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/","article_published_time":"2023-11-22T05:31:54+00:00","article_modified_time":"2023-11-22T05:31:55+00:00","og_image":[{"width":1800,"height":945,"url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png","type":"image\/png"}],"author":"Taraka Vuyyuru","twitter_card":"summary_large_image","twitter_creator":"@opensource_db","twitter_site":"@opensource_db","twitter_misc":{"Written by":"Taraka Vuyyuru","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#article","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/"},"author":{"name":"Taraka Vuyyuru","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/55546e9ca9552218b9376d4ecc8447a5"},"headline":"Mastering PostgreSQL: Rollback to Savepoints !!","datePublished":"2023-11-22T05:31:54+00:00","dateModified":"2023-11-22T05:31:55+00:00","mainEntityOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/"},"wordCount":904,"commentCount":0,"publisher":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#organization"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png","keywords":["nested transactions","rollback","savepoint"],"articleSection":["PostgreSQL 14","PostgreSQL 15","PostgreSQL 16"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/","url":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/","name":"Mastering PostgreSQL: Rollback to Savepoints !! - OpenSource DB","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#website"},"primaryImageOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png","datePublished":"2023-11-22T05:31:54+00:00","dateModified":"2023-11-22T05:31:55+00:00","breadcrumb":{"@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#primaryimage","url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png","contentUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png","width":1800,"height":945},{"@type":"BreadcrumbList","@id":"https:\/\/test.opensource-db.in\/wp1\/mastering-postgresql-rollbacks-savepoints\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/test.opensource-db.in\/wp1\/"},{"@type":"ListItem","position":2,"name":"Mastering PostgreSQL: Rollback to Savepoints !!"}]},{"@type":"WebSite","@id":"https:\/\/test.opensource-db.in\/wp1\/#website","url":"https:\/\/test.opensource-db.in\/wp1\/","name":"OpenSource DB","description":"Your Trusted OpenSource Databases partner","publisher":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/test.opensource-db.in\/wp1\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/test.opensource-db.in\/wp1\/#organization","name":"OPENSOURCE DB PRIVATE LIMITED","url":"https:\/\/test.opensource-db.in\/wp1\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/","url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png","contentUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png","width":368,"height":120,"caption":"OPENSOURCE DB PRIVATE LIMITED"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/","https:\/\/x.com\/opensource_db","https:\/\/www.youtube.com\/channel\/UCmTI5h","https:\/\/www.linkedin.com\/company\/opensource-db","https:\/\/www.instagram.com\/opensource_db\/"]},{"@type":"Person","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/55546e9ca9552218b9376d4ecc8447a5","name":"Taraka Vuyyuru","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/54256c344d6c1f7dbb87fa257d6e318d1ddcd0a29320b642116bfa20e693616b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/54256c344d6c1f7dbb87fa257d6e318d1ddcd0a29320b642116bfa20e693616b?s=96&d=mm&r=g","caption":"Taraka Vuyyuru"},"url":"https:\/\/test.opensource-db.in\/wp1\/author\/taraka\/"}]}},"rttpg_featured_image_url":{"full":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",1800,945,false],"landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",1800,945,false],"portraits":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",1800,945,false],"thumbnail":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5-150x150.png",150,150,true],"medium":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5-300x158.png",300,158,true],"large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5-1024x538.png",1024,538,true],"1536x1536":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5-1536x806.png",1536,806,true],"2048x2048":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",1800,945,false],"ultp_layout_landscape_large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",1200,630,false],"ultp_layout_landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",870,457,false],"ultp_layout_portrait":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",600,315,false],"ultp_layout_square":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2023\/11\/image-5.png",600,315,false]},"rttpg_author":{"display_name":"Taraka Vuyyuru","author_link":"https:\/\/test.opensource-db.in\/wp1\/author\/taraka\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/test.opensource-db.in\/wp1\/category\/postgres\/postgresql-14\/\" rel=\"category tag\">PostgreSQL 14<\/a> <a href=\"https:\/\/test.opensource-db.in\/wp1\/category\/postgres\/postgresql-15\/\" rel=\"category tag\">PostgreSQL 15<\/a> <a href=\"https:\/\/test.opensource-db.in\/wp1\/category\/postgres\/postgresql-16\/\" rel=\"category tag\">PostgreSQL 16<\/a>","rttpg_excerpt":"Introduction: The word &#8220;Transaction&#8221; will ring so many bells and whistles, but in this topic&#8217;s context a &#8220;Transaction&#8221; is a [&hellip;]","_links":{"self":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/4677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/comments?post=4677"}],"version-history":[{"count":47,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/4677\/revisions"}],"predecessor-version":[{"id":4899,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/4677\/revisions\/4899"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media\/4886"}],"wp:attachment":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media?parent=4677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/categories?post=4677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/tags?post=4677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}