<?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>last updated time &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/last-updated-time/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 09 Oct 2017 14:35:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>PostgreSQL: Update the Timestamp column with the use of TRIGGER</title>
		<link>https://www.dbrnd.com/2016/03/postgresql-update-the-timestamp-column-with-the-use-of-trigger/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 06 Mar 2016 20:12:57 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[last updated time]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[TIMESTAMP]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1904</guid>

					<description><![CDATA[Like MySQL, PostgreSQL doesn&#8217;t have different column for Datetime and Timestamp. You can visit this MySQL article here: In this post, I am sharing small demonstration on how to update a timestamp column automatically when a row is updated in the table of the PostgreSQL. In the big transactional system like the banking system, we [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F03%2Fpostgresql-update-the-timestamp-column-with-the-use-of-trigger%2F&#038;title=PostgreSQL%3A%20Update%20the%20Timestamp%20column%20with%20the%20use%20of%20TRIGGER" data-a2a-url="https://www.dbrnd.com/2016/03/postgresql-update-the-timestamp-column-with-the-use-of-trigger/" data-a2a-title="PostgreSQL: Update the Timestamp column with the use of TRIGGER"></a></p><p>Like MySQL, PostgreSQL doesn&#8217;t have different column for Datetime and Timestamp.<br />
<a href="https://www.dbrnd.com/2015/09/difference-between-datetime-and-timestamp-in-mysql/" target="_blank"><strong>You can visit this MySQL article here:</strong></a></p>
<p>In this post, I am sharing small demonstration on how to update a timestamp column automatically when a row is updated in the table of the PostgreSQL.</p>
<p>In the big transactional system like the banking system, we always require last updated datetime of every transaction and row.</p>
<blockquote><p>We have also common practice to create last_modified_datetime column in table.<br />
We can also update this column using application, and we can also update this column using the user-defined function.</p>
<p>But we can also create Trigger to perform this operation, and this automatic approach is good.</p></blockquote>
<p><strong>Below is a small demonstration by creating update Trigger:</strong></p>
<p><strong>Create a sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_EmployeeDetails
(
	EmpID SERIAL
	,EmpName CHARACTER VARYING(50)
	,EmpDOB TIMESTAMP WITHOUT TIME ZONE 
	,LastUpdatedDateTime TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW()
	,CONSTRAINT pk_tbl_EmployeeDetails_EmpID PRIMARY KEY(EmpID)
);</pre><p>
<p><strong>Insert a sample data for EmpName and EmpDOB column:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_EmployeeDetails
(EmpName,EmpDOB)
VALUES 
('Anvesh','1988-01-26')
,('Neevan','2000-06-29')
,('Martin','1985-08-04')
,('Jeny','1990-09-12');</pre><p>
<p><strong>Create a Trigger function:</strong></p><pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION trg_fn_tbl_EmployeeDetails_LastUpdatedDateTime()
RETURNS TRIGGER AS $$
BEGIN
   NEW.LastUpdatedDateTime = NOW(); 
   RETURN NEW;
END;
$$ language 'plpgsql';</pre><p>
<p><strong>Create an UPDATE TRIGGER:</strong></p><pre class="crayon-plain-tag">CREATE TRIGGER trg_update_tbl_EmployeeDetails BEFORE UPDATE
ON tbl_EmployeeDetails FOR EACH ROW EXECUTE PROCEDURE 
trg_fn_tbl_EmployeeDetails_LastUpdatedDateTime();</pre><p>
<p><strong>Update a record and check LastUpdatedDateTime:</strong></p><pre class="crayon-plain-tag">UPDATE tbl_EmployeeDetails SET EmpDOB = '1991-09-12' WHERE EmpID=4;</pre><p>
<p><strong>The Result:</strong></p><pre class="crayon-plain-tag">SELECT *FROM tbl_EmployeeDetails;</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateTimeStamp.png" rel="attachment wp-att-1908"><img fetchpriority="high" decoding="async" class="alignnone wp-image-1908 size-full" title="PostgreSQL Update TimeStamp" src="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateTimeStamp.png" alt="PostgreSQL Update TimeStamp" width="533" height="117" srcset="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateTimeStamp.png 533w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateTimeStamp-300x66.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateTimeStamp-150x33.png 150w" sizes="(max-width: 533px) 100vw, 533px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
