In PostgreSQL, gcd()
is a mathematical function that returns the greatest common divisor. We pass two numbers and the function returns the largest positive number that divides both inputs with no remainder.
Author: Ian
An Overview of PostgreSQL’s LCM() Function
In PostgreSQL, lcm()
is a mathematical function that returns the least common multiple. We pass two numbers and the function returns the smallest strictly positive number that is an integral multiple of both inputs.
Fix Error “cannot take logarithm of zero” in PostgreSQL
If you’re getting an error that reads “ERROR: cannot take logarithm of zero” when using either the log()
function or log10()
function in PostgreSQL, it’s probably because you’re passing an argument of zero.
These functions require a value greater than zero. This is true even for the base argument of the log()
function (the argument that specifies which base to use).
To fix this issue, be sure to pass a value greater than zero to these functions.
Continue readingUnderstanding Composite Types in PostgreSQL
In PostgreSQL, a composite type is a kind of data type that consists of multiple data types. It consists of a list of field names and their respective data types.
We can use composite types to fit multiple fields into one column.
We can create our own custom composite types, and they can be used in many of the same scenarios that simple data types can be used.
Continue readingUnderstanding PostgreSQL’s TRANSLATE() Function
PostgreSQL has a translate()
function which replaces certain characters in a string with certain other characters.
We specify the characters in the string that we want to replace, as well as the characters that we want to replace them with. The function then performs the translation and returns the string with the replaced characters.
Continue readingAdvanced T-SQL Join Techniques: Beyond INNER and LEFT Joins
While INNER
and LEFT JOIN
s are the workhorses of SQL queries, T-SQL offers several more advanced join techniques that can be invaluable for complex data analysis and manipulation. This article explores some of these powerful join methods and how they can enhance our queries.
Date Formats Accepted by SQL Server’s datetime2 Type
Below are the string literal date formats that SQL Server supports for the datetime2 data type. These are the formats that we can provide when setting a datetime2 date from a string literal.
Continue readingA Quick Look at TO_ASCII() in PostgreSQL
In PostgreSQL, we can use the to_ascii()
function to convert a string to ASCII from another encoding. This usually involves dropping any accents (diacritic signs) from the original string.
We pass the string as an argument to the function. We also have the option of specifying the encoding (either its name or its number).
Continue readingOverview of the REPEAT() Function in PostgreSQL
We can use PostgreSQL’s repeat()
function to repeat a string multiple times. We pass the string to the function, along with an integer that specifies how many times we want it repeated, and it returns the string repeated that many times.
5 String Functions that Return Length in PostgreSQL
PostgreSQL provides us with a handful of string functions that return the length of a given string.
But the result between these functions can be different, depending on which function we use. That’s because the “length” can be different, depending on what we’re measuring. Are we talking about the number of characters in the string? Or the number of bytes in the string? Or perhaps we want to know the number of bits in the string.
The function we use will depend on which of the above we’re trying to measure. Below are five functions that cater for each of the above questions.
Continue reading