Install PostgreSQL on Ubuntu 18.04

The following steps demonstrate how to install PostgresSQL on Ubuntu 18.04.

There are a couple of ways to go about installing Postgres on Ubuntu.

But before we start jumping in and installing it, did you know that by default, PostgreSQL is already available in Ubuntu 18.04?

So one option is to go right ahead and use the version that’s already included with Ubuntu.

But unless you have reason not to, you will probably want to run the latest version of PostgreSQL, in which case you’ll want to download and install the latest version.

This tutorial covers both options.

Continue reading

How to Pause the Execution of a Statement in PostgreSQL

PostgreSQL includes three functions that allow you to delay the execution of the server process. the execution of a statement.

In other words, you can run a statement and have it pause half way through, before continuing on its merry way.

The three functions are:

These are all very similar, but they work in slightly different ways.

Below are examples of each one.

Continue reading

Calculate the Age in Years in PostgreSQL

Postgres has the age() function that returns the age in years, months, and days based on two dates.

This works fine unless you only want to return the age in years.

For example, you simply want to return a person’s age based on their birthday. You want something like 32 instead of 32 years 4 mons 67 days, which is what age() is likely to return.

Fortunately there’s an easy way to do this in PostgreSQL.

Continue reading