In PostgreSQL, the trunc()
function truncates a number.
More specifically, it truncates the number either toward zero, or to a specific number of decimal places.
Continue readingIn PostgreSQL, the trunc()
function truncates a number.
More specifically, it truncates the number either toward zero, or to a specific number of decimal places.
Continue readingThe PostgreSQL to_char()
function provides us with the option of adding the ordinal number suffix to the result.
This means we can add the ordinal indicator when formatting dates.
For example, instead of outputting 10 Feb we could output 10th Feb.
Continue readingThe easiest way to install PostgreSQL on a Mac is by installing Postgres.app. Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac application.
You simply download it and drag it to your Applications folder, just like with any other application.
Continue readingIn PostgreSQL, the ceiling()
function is used for rounding a number up to the nearest integer.
It’s similar to round()
, except that it only rounds up. The round()
function will round up or down as required.
It’s also similar to floor()
, except that floor()
rounds down instead of up.
In PostgreSQL, the floor()
function is used for rounding a number down to the nearest integer.
It’s basically the opposite of ceiling()
, which rounds a number up.
It’s also similar to round()
, except that it only rounds down. The round()
function will round up or down as required.
In PostgreSQL, the round()
function is used for rounding a number.
The function can work in one of two ways, depending on how you use it. You can make it round the number to the nearest integer, or to a specified number of decimal places.
This is determined by the number of arguments you pass to the function when you call it.
Continue readingWhen 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 readingIn Postgres, the age()
function returns the age based on two timestamp or date variables.
The result is returned using years and months, rather than just days.
For example, a result might look like this: 3 years 2 mons 30 days.
Continue readingIn PostgreSQL, you can use the to_char()
to output a number in a certain format, including with a plus or minus sign to indicate whether it’s a positive or negative number.
To do this, use one of S
, MI
, PL
, or SG
in your format string.
Another option is to use PR
in order to enclose any negative values in angle brackets.
In Postgres, to_char()
is a data type formatting function that converts its first argument to a string.
The format of the string is determined by the second argument.
The to_char()
function can be used to do the following conversions: