Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts
Monday, March 23, 2015

Transactions Control in SQL & PostgreSQL

Transactions control is the most important thing for the Data Integrity.
Transaction record is one or more related changes to the database that are made at once.

Properties of Transactions


  • Atomicity:
    ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state.

  • Consistency:
    ensures that the database properly changes states upon a successfully committed transaction.

  • Isolation:
    enables transactions to operate independently of and transparent to each other.

  • Durability:
    ensures that the result or effect of a committed transaction persists in case of a system failure.

Thursday, March 19, 2015

PostgreSQL Calculate Age From Birthdate

There is AGE() function that performs two calculations depending of provided params:

  • It substracts date2 from date1 if two params are provided:
    --calculation: date1 - date2
    age(date1, date2)
  • It substracts date from the current date if only one param is provided:
    --calculation: current_date - date
    age(date)