Most major RDBMSs provide ways for us to format numbers using SQL. Some provide only basic formatting capabilities, while others are more advanced.
Below are examples of formatting a number in some of the more popular RDBMSs.
In Postgres, we can use the STRING_AGG() function to transform our query results into a comma separated list.
Instead of each value being output in a separate row (as with any regular query), the values are output to a single row, separated by a comma (or some other delimiter of our choosing).
If you get the “operator does not exist: integer || integer” error in PostgreSQL, it’s probably because you’re trying to concatenate two numbers.
If you really want to concatenate two numbers, the easiest way to overcome this issue is to cast at least one of them to a string data type first.
Another way to do it is to use the CONCAT() function.
Below are two ways to return the size of a specific database 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.
In PostgreSQL, we can use the STRING_AGG() function to return columns from a query as a delimited list.
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.