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.
Understanding 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.
Understanding 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.
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.
A 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).
Overview 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.
Create a Multi-Dimensional Array from a Query in PostgreSQL
In PostgreSQL, we can use array constructors to create arrays that contain elements that we specify. We can populate the array from literal values, or we can let a query provide the values.
We can also create multi-dimensional arrays. When populating the array from a query, we can use multiple subqueries to create each sub-array. Therefore we can create a multi-dimensional array from a query.