PostgreSQL has a bit_length()
function that returns the number of bits in a given string. We pass the string as an argument and the function returns the number of bits in that string.
Tag: string functions
Understanding the BTRIM() Function in PostgreSQL
PostgreSQL has a function called btrim()
that we can use to trim both sides of a string. We can trim blank spaces or we can specify certain characters to trim.
It removes the longest string containing only characters from the ones we specify. If we don’t specify any characters, then it removes blank spaces from both sides.
We provide the string as the first argument, and the (optional) characters as the second.
Continue readingImprovements to the TRIM(), LTRIM() and RTRIM() Functions in SQL Server 2022
The release of SQL Server 2022 in November 2022 introduced a bunch of new functionality, including some enhancements to the TRIM()
, LTRIM()
and RTRIM()
functions.
The enhancements in the LTRIM()
and RTRIM()
functions are different to those in the TRIM()
function. Below is a quick overview of the enhancements to these functions, along with examples.
Understanding the TRIM() Function in SQL Server
In SQL Server, we can use the TRIM()
function to remove leading and trailing characters from a given string.
A common use case is to remove whitespace from the start and end of the string, but we can also specify other characters to remove.
Also, as from SQL Server 2022, we can specify which side of the string to remove the characters from (i.e. leading, trailing, or both).
Continue readingOverview of the RTRIM() Function in SQL Server
In SQL Server, we can use the T-SQLÂ RTRIM()
function to remove trailing blanks from a given string. Trailing blanks are white spaces, tabs, etc that come at the end of the string.
Also, as from SQL Server 2022, we can specify other trailing characters to remove from the string.
Continue readingUnderstanding the LTRIM() Function in SQL Server
In SQL Server, we can use the T-SQL LTRIM()
function to remove leading blanks from a given string.
Also, as from SQL Server 2022, we can specify other leading characters to remove from the string.
Continue readingUnderstanding the STRING_SPLIT() Function in SQL Server
In SQL Server STRING_SPLIT()
is a table-valued function that splits a string into rows of substrings, based on a specified separator character.
Each substring is returned on its own row, in a column called value
.
SQLite SUBSTRING() Explained
In SQLite, substring()
is an alias for substr()
.
It returns a substring from a string, based on a given starting location within the string. Two arguments are required, and a third optional argument is accepted.
The substring()
naming was introduced in SQLite 3.34.0, which was released on 1st December 2020. The reason that the substring()
syntax was introduced was for compatibility with SQL Server.
2 Ways to Return the ASCII Code for a Given Character in MariaDB
MariaDB includes two built-in functions that allow us to get the ASCII code from a given character.
Continue readingSQL 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).