Here are three ways to get the data type of a given column in MariaDB.
Continue readingCategory: PostgreSQL
MAX() Function in PostgreSQL
In PostgreSQL, the MAX()
function computes the maximum of the non-null input values and returns the result.
This function can be used on any numeric, string, date/time, or enum type, as well as inet
, interval
, money
, oid
, pg_lsn
, tid
, and arrays of any of these types.
MIN() Function in PostgreSQL
In PostgreSQL, the MIN()
function computes the minimum of the non-null input values and returns the result.
This function can be used on any numeric, string, date/time, or enum type, as well as inet
, interval
, money
, oid
, pg_lsn
, tid
, and arrays of any of these types.
How to Format Numbers with Commas in SQL
Most of the major RDBMSs have functions that enable us to format numbers with commas as either the group separator, or the decimal separator.
Some RDBMSs also output certain numeric data types with commas in the relevant place.
Below are examples of formatting numbers with commas in some of the more popular DBMSs.
Continue reading3 Ways to List all Stored Procedures in a PostgreSQL Database
Here are three options for listing out all the stored procedures in a Postgres database.
Continue readingFormat a Number as a Percentage in SQL
There are several ways to format a number as a percentage in SQL, depending on the DBMS being used.
Here are examples of adding a percent sign to a number in some of the most popular DBMSs.
Continue readingHow to Change the Locale When Formatting Numbers in PostgreSQL
If you’re formatting a number in PostgreSQL, and you want to change the locale so that the correct group and decimal separators are used, here’s how you can do that.
Continue readingPostgreSQL GROUP_CONCAT() Equivalent
Some RDBMSs like MySQL and MariaDB have a GROUP_CONCAT()
function that allows you to return a query column as a delimited list (for example, a comma separated list).
PostgreSQL has a similar function called STRING_AGG()
. This function works in pretty much the same way that GROUP_CONCAT()
works in MySQL and MariaDB.
SQL LPAD()
In SQL, LPAD()
is a commonly used function that pads the left part of a string with a specified character. The function can be used on strings and numbers, although depending on the DBMS, numbers may have to be passed as a string before they can be padded.
DBMSs that have an LPAD()
function include MySQL, MariaDB, PostgreSQL, and Oracle.
DBMSs that don’t have an LPAD()
function include SQL Server and SQLite (although there are other ways to apply left padding in these DBMSs).
SQL RPAD()
In SQL, RPAD()
is used to pad the right part of a string with a specified character. The function can be used on strings and numbers, although depending on the DBMS, numbers may have to be passed as a string before they can be padded.
DBMSs that have an RPAD()
function include MySQL, MariaDB, PostgreSQL, and Oracle.
DBMSs that don’t have an RPAD()
function include SQL Server and SQLite.