<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>NewPush &#187; PL/PGSQL</title> <atom:link href="http://newpush.com/tag/plpgsql/feed/" rel="self" type="application/rss+xml" /><link>http://newpush.com</link> <description>Server Hosting, Data Warehouse Hosting, Collaboration</description> <lastBuildDate>Wed, 23 May 2012 03:47:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Creating Delete Triggers in PostgreSQL</title><link>http://newpush.com/2009/08/creating-delete-triggers-in-postgresql/</link> <comments>http://newpush.com/2009/08/creating-delete-triggers-in-postgresql/#comments</comments> <pubDate>Mon, 03 Aug 2009 22:31:57 +0000</pubDate> <dc:creator>Balazs</dc:creator> <category><![CDATA[DB2]]></category> <category><![CDATA[PL/PGSQL]]></category> <category><![CDATA[PostgreSQL]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[Trigger]]></category><guid isPermaLink="false">http://www.wdream.com/2009/08/creating-delete-triggers-in-postgresql/</guid> <description><![CDATA[One of the common data integrity issues that can happen in a database is the unintended deletion of a row. Here is how to create a DELETE trigger in PostgreSQL. The example code below assumes you have a &#8220;customer_cus&#8221; table &#8230; <a href="http://newpush.com/2009/08/creating-delete-triggers-in-postgresql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>One of the common data integrity issues that can happen in a database is the unintended deletion of a row.  Here is how to create a DELETE trigger in PostgreSQL.</p><p>The example code below assumes you have a &#8220;customer_cus&#8221; table and a &#8220;customer_archive_cua&#8221; table with at least two fields.  It is a good idea to add a timestamp field to the archive table with DEFAULT now(), so that the date of deletion is captured.<br /> <code><br /> CREATE FUNCTION archive_customer() RETURNS TRIGGER AS '<br /> BEGIN<br /> INSERT INTO customer_archive_cua (name_cua, address_cua)<br /> VALUES (OLD.name_cus,OLD.address_cus);<br /> RETURN NULL;<br /> END;<br /> ' LANGUAGE 'plpgsql';<br /> CREATE TRIGGER customer_archive_on_delete AFTER DELETE ON customer_cus<br /> FOR EACH ROW EXECUTE PROCEDURE archive_customer();<br /> </code></p><h4>References</h4><ul><li><a href="http://www.amazon.com/gp/product/0672327562?ie=UTF8&#038;tag=wdr-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0672327562">PostgreSQL (2nd Edition) (Developer&#8217;s Library)</a><img src="http://www.assoc-amazon.com/e/ir?t=wdr-20&#038;l=as2&#038;o=1&#038;a=0672327562" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li></ul><p><iframe src="http://rcm.amazon.com/e/cm?t=wdr-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=0672327562&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p> ]]></content:encoded> <wfw:commentRss>http://newpush.com/2009/08/creating-delete-triggers-in-postgresql/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: newpush.com @ 2012-05-23 05:16:29 by W3 Total Cache -->
