In Oracle, the LISTAGG()
function enables us to combine data from multiple rows in to a single row.
We have the option of specifying a separator (such as a comma). We can also order the results produced by the LISTAGG()
function, and more.
In Oracle, the LISTAGG()
function enables us to combine data from multiple rows in to a single row.
We have the option of specifying a separator (such as a comma). We can also order the results produced by the LISTAGG()
function, and more.
MariaDB has a GROUP_CONCAT()
function that enables us to return columns from a query as a delimited list.
In PostgreSQL, we can use the STRING_AGG()
function to return columns from a query as a delimited list.
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.
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 readingIn SQLite, we can use the PRINTF()
function or FORMAT()
function to format numbers with leading zeros.
MariaDB has an LPAD()
function that allows us to pad the left part of a string or number with our chosen character or series of characters.
We can use this function on numeric values in order to add leading zeros.
Continue readingIn 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.
Azure SQL Edge uses a limited version of the SQL Server Database Engine. One of the limitations of Azure SQL Edge, is that it doesn’t currently support CLR-dependent T-SQL functions, such as the FORMAT()
function.
This can be a problem when trying to format numbers.
However, there are often ways around such limitations. Here are examples of how we can pad numbers with leading and trailing zeros in SQL Edge.
Continue readingSome DBMSs have an LPAD()
and RPAD()
function which can be used to pad numbers with leading and trailing zeros.
SQL Server doesn’t have such a function. But that doesn’t prevent us from being able to pad numbers with leading/trailing zeros.
Continue reading