![]() ![]() So in order to automatically populate and maintain creation and modification timestamps, we will be defining a generic function (called a Trigger Function) as the database level that will contain the logic for the updating the timestamps and then binding that trigger function to events within each table through the definition a Trigger at the table level. With triggers, it is trivial to automate the management of the creation and last modified date timestamp fields.Ī Trigger in PostgreSQL is a special type of user defined function that is automatically invoked by the PostgreSQL database any time a particular set of events occur at the row level (or statement level) within a table. This is done through the PostgreSQL feature known as triggers. Luckily, for those working with the PostgreSQL database there is a very easy to way to overcome this issue by remove the responsibility for setting and maintaining of these timestamps from developers and putting it into the hands of the database itself. The moment that the values within a modified timestamp can’t be trusted to be accurate, you’ve not only destroyed the utility that timestamp is meant to provide, but also turned a potential asset into a liability as any other code that relies on these timestamps breaks. No matter the length and breadth of your engineering standards, there is always that one developer who will not properly keep these values up to date and in doing so introduce very serious issues to a code base. ![]() ![]() While the creation timestamp is usually very straightforward to implement and enforce usage, making sure all developers on a team are always properly updating the date of last modification on every row across every table can become a tediously annoying management task. Knowing when a row was inserted and when it was last updated are important pieces of information that are used across all kinds of apps.Ī data synchronization tool might use a modified date to identify rows that have changed since the last sync, while a dating app might use the creation timestamp to identify spam accounts. “DateModified”, “updated_at”, “last_modified_date”,etc.). “DateCreated”,”date_created”,”created_at”.etc) and the date that the row was last modified (ie. Aside from a field named “id”, the next two most commonly found columns in a typical database table are usually some form of timestamp column to track the date the row was created at (ie. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |