
{"id":7204,"date":"2025-02-26T10:30:52","date_gmt":"2025-02-26T10:30:52","guid":{"rendered":"https:\/\/test.opensource-db.in\/wp1\/?p=7204"},"modified":"2025-02-26T11:10:33","modified_gmt":"2025-02-26T11:10:33","slug":"how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i","status":"publish","type":"post","link":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/","title":{"rendered":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>TRIGGERS<\/strong> in PostgreSQL are a special user-defined function that is automatically executed when a specific event occurs in a table. Unlike regular functions, which the user must explicitly call, triggers are event-driven and activate in response to <strong>INSERT<\/strong>, <strong>UPDATE<\/strong>, <strong>DELETE<\/strong>, or <strong>TRUNCATE<\/strong> operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL has supported triggers for many years, but newer enhancements, especially since PostgreSQL 10, have made them more powerful. Triggers can be defined at the row level (executing once per row) or the statement level (executing once per query). These capabilities make PostgreSQL a flexible and robust choice for data-driven applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers are commonly used to enforce business rules, maintain data integrity, log changes, or automate complex workflows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types of Triggers in PostgreSQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers in PostgreSQL can be categorized based on their execution level:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Row-Level Triggers:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Executed once <strong>for each row<\/strong> affected by the triggering event.<\/li>\n\n\n\n<li>Useful when individual row processing is required.<\/li>\n\n\n\n<li>Example: If an UPDATE query modifies 10 rows, the trigger function executes <strong>10 times<\/strong>, once for each updated row.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Statement-Level Triggers:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Executed <strong>once per SQL statement<\/strong>, regardless of how many rows are affected.<\/li>\n\n\n\n<li>It is ideal for auditing or enforcing constraints at a <strong>higher level<\/strong> than individual rows.<\/li>\n\n\n\n<li>Example: If an UPDATE query modifies 10 rows, the trigger function executes <strong>only once<\/strong> for the entire statement.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Create Triggers in PostgreSQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To create a new trigger in PostgreSQL, you follow these steps:<br>First, create a trigger function using the CREATE FUNCTION statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Second, bind the trigger function to a table using the CREATE TRIGGER statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A trigger function is similar to an ordinary function. However, a trigger function does not take any argument and has a return value with the trigger type.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating a Function in PostgreSQL<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax for creating a function to be used as a trigger is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE FUNCTION trigger_function()\nRETURNS TRIGGER\nLANGUAGE plpgsql\nAS $$\nBEGIN\n    -- Trigger logic goes here\nEND;\n$$;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Creating a Trigger in PostgreSQL:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax for creating a trigger is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TRIGGER trigger_name  \n{ BEFORE | AFTER } { INSERT | DELETE | UPDATE | TRUNCATE }  \nON table_name  \nFOR { EACH ROW | EACH STATEMENT }  \nEXECUTE PROCEDURE trigger_function();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Trigger Name: Specify the name of the trigger after the CREATE TRIGGER statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Trigger Timing: Define when the trigger should be fired\u2014BEFORE or AFTER the event occurs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Trigger Event: Specify the event that invokes the trigger. Possible events include INSERT, DELETE, UPDATE, or TRUNCATE.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Target Table: Mention the table on which the trigger is defined using the ON table_name clause.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Types of Triggers :<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Row-Level Trigger: Use FOR EACH ROW to execute the trigger once per affected row.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Statement-Level Trigger: Use FOR EACH STATEMENT to execute the trigger once per statement.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Data Auditing with Triggers<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s create a trigger that logs changes when a player&#8217;s name is updated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Creating the player Table<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# CREATE TABLE player (\nPlayer_id serial primary key,\nName varchar(100)\n);\nCREATE TABLE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Creating the player_audit Table<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# CREATE TABLE player_audit (Player_audit_id serial primary key,\nPlayer_id int not null, Name varchar(100) not null, Edit_date timestamp not null);\nCREATE TABLE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Creating a Trigger Function<br>We first create a function and then bind that function to our trigger.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE OR REPLACE FUNCTION fn_player_name_change_log()\nRETURNS TRIGGER \nLANGUAGE plpgsql \nAS $$\nBEGIN  \n    -- Compare the new value with the old value  \n    -- 'NEW' refers to the updated row, 'OLD' refers to the existing row  \n    IF NEW.name &lt;&gt; OLD.name THEN  \n        -- Insert the old data into the audit table before updating the main table  \n        INSERT INTO player_audit (player_id, name, edit_date)\n        VALUES (OLD.player_id, OLD.name, NOW());\n    END IF;  \n\n    -- Return the new row to complete the update process  \n    RETURN NEW;  \nEND;\n$$;\nCREATE FUNCTION<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The old represents the row before the update while the new represents the new row that will be updated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Binding the Function to a Trigger<br>Bind the newly created function to our \u2018player\u2019 table via the create trigger statement.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# CREATE TRIGGER trg_player_name_change\nBEFORE UPDATE \nON players\nFOR EACH ROW\nEXECUTE PROCEDURE fn_player_name_change_log();\nCREATE TRIGGER<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I have created a trigger function.<br>If you want the trigger to execute <strong>after<\/strong> the update instead of <strong>before<\/strong>, replace <code>BEFORE<\/code> with <code>AFTER<\/code> as needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Insert Sample Data<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# INSERT INTO player VALUES                             \n(1, 'Virat Kohli'), \n(2, 'M.S. Dhoni'), \n(3, 'Shikhar Dhawan');                    \nINSERT 0 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>View the Data<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# select * from player;\n player_id |      name      \n-----------+----------------\n         1 | Virat Kohli\n         2 | M.S. Dhoni\n         3 | Shikhar Dhawan\n(3 rows)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Update a Player&#8217;s Name<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s update some data<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# UPDATE player \nSET name = 'KLrahul' \nWHERE player_id = 3;\nUPDATE 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>View the Audit Log<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test=# select * from player_audit;\n player_audit_id | player_id |      name      |         edit_date          \n-----------------+-----------+----------------+----------------------------\n               1 |         3 | Shikhar Dhawan | 2025-02-26 12:31:01.435768\n(1 row)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers in PostgreSQL provide a powerful mechanism for automating database operations, maintaining data integrity, and enforcing business rules. By understanding the difference between <strong>row-level<\/strong> and <strong>statement-level triggers<\/strong>, developers can optimize database performance and ensure consistency in data changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we demonstrated how to create a trigger function, bind it to a table, and use it to audit changes efficiently. Implementing triggers correctly can help in logging modifications, preventing unwanted changes, and streamlining database workflows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next section (<strong>Part 2<\/strong>), we will focus on <strong>Statement-Level Triggers<\/strong>, exploring their use cases, implementation, and best practices for handling large-scale database operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: TRIGGERS in PostgreSQL are a special user-defined function that is automatically executed when a specific event occurs in a [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":7215,"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":[26,61],"class_list":["post-7204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql-14","category-postgresql-15","category-postgresql-16","tag-postgresql","tag-triggers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - 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=\"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - OpenSource DB\" \/>\n<meta property=\"og:description\" content=\"Introduction: TRIGGERS in PostgreSQL are a special user-defined function that is automatically executed when a specific event occurs in a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\" \/>\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=\"2025-02-26T10:30:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-26T11:10:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.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=\"Shameer Bhupathi\" \/>\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=\"Shameer Bhupathi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 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\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\"},\"author\":{\"name\":\"Shameer Bhupathi\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/422480fbefed0b2cee82aeab232110f5\"},\"headline\":\"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I\",\"datePublished\":\"2025-02-26T10:30:52+00:00\",\"dateModified\":\"2025-02-26T11:10:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\"},\"wordCount\":638,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png\",\"keywords\":[\"postgresql\",\"triggers\"],\"articleSection\":[\"PostgreSQL 14\",\"PostgreSQL 15\",\"PostgreSQL 16\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\",\"name\":\"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - OpenSource DB\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png\",\"datePublished\":\"2025-02-26T10:30:52+00:00\",\"dateModified\":\"2025-02-26T11:10:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png\",\"contentUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png\",\"width\":1800,\"height\":945},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/test.opensource-db.in\/wp1\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I\"}]},{\"@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\/422480fbefed0b2cee82aeab232110f5\",\"name\":\"Shameer Bhupathi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2cfa95999202132ded07acd24f6faf25dca145a6c3efe47919204f115ffbf625?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2cfa95999202132ded07acd24f6faf25dca145a6c3efe47919204f115ffbf625?s=96&d=mm&r=g\",\"caption\":\"Shameer Bhupathi\"},\"url\":\"https:\/\/test.opensource-db.in\/wp1\/author\/shameer-bhupathi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - 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":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - OpenSource DB","og_description":"Introduction: TRIGGERS in PostgreSQL are a special user-defined function that is automatically executed when a specific event occurs in a [&hellip;]","og_url":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/","og_site_name":"OpenSource DB","article_publisher":"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/","article_published_time":"2025-02-26T10:30:52+00:00","article_modified_time":"2025-02-26T11:10:33+00:00","og_image":[{"width":1800,"height":945,"url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png","type":"image\/png"}],"author":"Shameer Bhupathi","twitter_card":"summary_large_image","twitter_creator":"@opensource_db","twitter_site":"@opensource_db","twitter_misc":{"Written by":"Shameer Bhupathi","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#article","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/"},"author":{"name":"Shameer Bhupathi","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/422480fbefed0b2cee82aeab232110f5"},"headline":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I","datePublished":"2025-02-26T10:30:52+00:00","dateModified":"2025-02-26T11:10:33+00:00","mainEntityOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/"},"wordCount":638,"commentCount":0,"publisher":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#organization"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png","keywords":["postgresql","triggers"],"articleSection":["PostgreSQL 14","PostgreSQL 15","PostgreSQL 16"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/","url":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/","name":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I - OpenSource DB","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#website"},"primaryImageOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png","datePublished":"2025-02-26T10:30:52+00:00","dateModified":"2025-02-26T11:10:33+00:00","breadcrumb":{"@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#primaryimage","url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png","contentUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png","width":1800,"height":945},{"@type":"BreadcrumbList","@id":"https:\/\/test.opensource-db.in\/wp1\/how-to-use-triggers-for-event-driven-data-auditing-and-integrity-enforcement-part-i\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/test.opensource-db.in\/wp1\/"},{"@type":"ListItem","position":2,"name":"How to Use Triggers for event-driven Data auditing and Integrity enforcement-Part I"}]},{"@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\/422480fbefed0b2cee82aeab232110f5","name":"Shameer Bhupathi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2cfa95999202132ded07acd24f6faf25dca145a6c3efe47919204f115ffbf625?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2cfa95999202132ded07acd24f6faf25dca145a6c3efe47919204f115ffbf625?s=96&d=mm&r=g","caption":"Shameer Bhupathi"},"url":"https:\/\/test.opensource-db.in\/wp1\/author\/shameer-bhupathi\/"}]}},"rttpg_featured_image_url":{"full":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",1800,945,false],"landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",1800,945,false],"portraits":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",1800,945,false],"thumbnail":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19-150x150.png",150,150,true],"medium":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19-300x158.png",300,158,true],"large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19-1024x538.png",1024,538,true],"1536x1536":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19-1536x806.png",1536,806,true],"2048x2048":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",1800,945,false],"ultp_layout_landscape_large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",1200,630,false],"ultp_layout_landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",870,457,false],"ultp_layout_portrait":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",600,315,false],"ultp_layout_square":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2025\/02\/image-19.png",600,315,false]},"rttpg_author":{"display_name":"Shameer Bhupathi","author_link":"https:\/\/test.opensource-db.in\/wp1\/author\/shameer-bhupathi\/"},"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: TRIGGERS in PostgreSQL are a special user-defined function that is automatically executed when a specific event occurs in a [&hellip;]","_links":{"self":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/7204","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/comments?post=7204"}],"version-history":[{"count":7,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/7204\/revisions"}],"predecessor-version":[{"id":7213,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/7204\/revisions\/7213"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media\/7215"}],"wp:attachment":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media?parent=7204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/categories?post=7204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/tags?post=7204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}