If you’ve ever used the TO_CHAR()
function to format a date that uses the month name, you might have noticed that sometimes the month is returned with right padding.
Author: Ian
INSTR() Equivalent in SQL Server
Many RDBMSs have an INSTR()
function that enables us to find a substring within a string. Some (such as MySQL and MariaDB) also have a LOCATE()
function and a POSITION()
function (also supported by PostgreSQL), that do a similar thing.
SQL Server doesn’t have an INSTR()
function. Nor does it have a LOCATE()
or POSITION()
function. But it does have the CHARINDEX()
function that does the same thing.
SQL Server also has the PATINDEX()
function, which does a similar job to CHARINDEX()
.
3 Ways to Separate the Year, Month, and Day from a Date in MariaDB
MariaDB has several functions that enable you to extract various date and time parts from date/time values. You can use these to separate each date/time component into its own column if required.
Below are three ways to extract the year, month, and day from a date value in MariaDB.
Continue readingGROUP_CONCAT() Function in MySQL
MySQL has a GROUP_CONCAT()
function that enables us to return columns from a query as a delimited list.
It returns a string result with the concatenated non-NULL
values from a group.
LISTAGG() Function in Oracle
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 GROUP_CONCAT()
MariaDB has a GROUP_CONCAT()
function that enables us to return columns from a query as a delimited list.
STRING_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 readingHow to Format Numbers with Leading Zeros in SQLite
In SQLite, we can use the PRINTF()
function or FORMAT()
function to format numbers with leading zeros.