In PostgreSQL, LPAD()
is a function that enables us to add padding to the left part of a string.
Category: PostgreSQL
How to Concatenate Strings in SQL
Most of the major RDBMSs provide several options for concatenating two or more strings.
- There’s the
CONCAT()
function, which concatenates its arguments. - There’s also a
CONCAT_WS()
that allows you to specify a separator that separates the concatenated strings. - And there’s also a string concatenation operator, which allows us to concatenate its operands.
Below are examples of each method.
Continue readingFormat Numbers with Commas in PostgreSQL
In PostgreSQL, we can use the TO_CHAR()
function to format numbers in a given format. This includes formatting numbers with commas in the relevant location.
PostgreSQL also has a money
data type, which outputs the value using the current locale. This can include commas in the appropriate place, based on the locale being used.
How to Get the Day, Month, and Year from a Date in SQL
Most of the major RDBMSs have functions that enable us to extract the day, month, and year from datetime values.
Some RDBMSs provide multiple ways to do this, and others are more limited. Below are examples of extracting the day, month, and year from date values in some of the most popular RDBMSs.
Continue readingHow to Get the Short Month Name in SQL
Below are examples that demonstrate how to use SQL to return the short month name from a date in the major RDBMSs.
Continue readingHow CONCAT_WS() Works in PostgreSQL
In PostgreSQL, the CONCAT_WS()
function concatenates two or more strings, placing a separator between each one. The separator is specified by the first argument.
How the CONCAT() Function Works in PostgreSQL
In PostgreSQL, the CONCAT()
function concatenates the text representations of its arguments.
3 Functions that Get the Day, Month, and Year from a Date in PostgreSQL
PostgreSQL provides us with several ways to get the day, month, and year from a date.
Three functions that immediately come to mind are; DATE_PART()
, EXTRACT()
, and TO_CHAR()
.
Get the Month Name from a Date in SQL
Most major RDBMSs provide at least one function that enables us to return the month name from a date.
Continue readingInstall PostgreSQL on Ubuntu 20.04
Did you know that PostgreSQL is available in all Ubuntu versions by default?
Yes, that means that your Ubuntu 20.04 installation probably already has a PostgreSQL package sitting there waiting for you to install it.
And you can install it with one command, which I’ll show you below.
But what if you prefer to run the latest version of Postgres instead? Well, I’ll also show you how to install that. Installing the latest version is almost as easy as installing your local package.
Continue reading