Below are two ways to return the size of a specific database in PostgreSQL.
Continue readingCategory: PostgreSQL
3 Ways to Format a Number as a Percentage in PostgreSQL
We have several options if we want to display numbers with a percentage sign in PostgreSQL.
We can use the TO_CHAR()
function to format the number along with the percentage sign. Or we can simply concatenate the number with the percentage sign, either with the CONCAT()
function or with the concatenation operator.
Add Leading Zeros in SQL
Below are examples of adding a leading zero to a number in SQL, using various DBMSs.
Continue readingSTRING_AGG() Function in PostgreSQL
In PostgreSQL, we can use the STRING_AGG()
function to return columns from a query as a delimited list.
How to Show Null Values When Running Queries in psql (PostgreSQL)
By default, null values are returned as an empty string in psql. But this can easily be changed.
One reason you might want to change this is to avoid null values being confused with actual empty strings.
You can change this with the \pset null 'value'
command.
How POSITION() Works in PostgreSQL
PostgreSQL has a POSITION()
function that returns the first starting index of a specified substring within a string.
If the substring doesn’t exist in the string, then zero is returned.
Continue reading2 Ways to Add Leading Zeros in PostgreSQL
In PostgreSQL, we can use the TO_CHAR()
function to add leading zeros to a number. The function converts the number to a string, using the (optional) format we specify.
Another option is to use the LPAD()
function to pad a number with leading zeros.
Padding in SQL
Some RDBMSs provide an LPAD()
and RPAD()
function that enables us to left pad or right pad a string. Some functions also allow us to add leading or trailing zeros numbers.
Below are examples of applying SQL padding in some of the more popular RDBMSs.
Continue readingConcatenate a String and a Number in PostgreSQL
PostgreSQL provides us with the following ways to concatenate strings and numbers:
- The
CONCAT()
function, which concatenates its arguments. - The pipe concatenation operator (
||
), which concatenates its operands.
Examples of each below.
Continue readingRPAD() Function in PostgreSQL
In PostgreSQL, RPAD()
is a function that enables us to add padding to the right part of a string.