Return a List of Timezones Supported by PostgreSQL

When working with PostgreSQL, you may occasionally find yourself in the situation where you need a list of timezones that Postgres recognises.

For example, you could be trying to set the timezone for your current session, or you could be using one of the datetime functions that allow you to manipulate the timezone.

Below are two views and two functions that return a list of timezones.

Continue reading

How to Format Numbers in PostgreSQL

When working with Postgres, you can use the to_char() function to output numbers in a given format.

The way it works is that you provide two arguments. The first argument is the number to be formatted. The second argument determines how it is formatted.

The return value is text.

Depending on your requirements, you might prefer to convert the number to the appropriate data type, for example using the cast() function.

Examples of both methods are below.

Continue reading

Set a Default Value for a Column in SQLite: DEFAULT Constraint

When creating a table in SQLite, you have the option of adding constraints to each column.

One such constraint is the DEFAULT constraint.

The DEFAULT constraint allows you to specify a value to be used in the event no value is supplied for that column when a new row is inserted.

If you don’t use a DEFAULT clause, then the default value for a column is NULL.

Continue reading