I have strings like "keepme: cutme" or "string-without-separator", which should become respectively "keepme" and "string-without-separator". Can this be done in PostgreSQL? I tried:
select substring('first:last' from '.+:')
But this leaves : in and will not work if there is no : in the line.
:
Use split_part() :
split_part()
SELECT split_part('first:last', ':', 1) AS first_part
Returns the entire string if the delimiter does not exist. And it's just to get a second or third part, etc.
Significantly faster than regular expression functions. And since we have a fixed delimiter, we don’t need the magic of regular expressions.
on this topic:
regexp_replace () can be overloaded for what you need, but it also gives the added benefit of a regular expression. For example, if strings use multiple delimiters.
Usage example:
select regexp_replace( 'first:last', E':.*', '');
SQL Select to select everything after the last occurrence of a character
select right('first:last', charindex(':', reverse('first:last')) - 1)
Source: https://habr.com/ru/post/984862/More articles:python highlighting in Rmarkdown in RStudio - pythonHow to change a ListView element designated as "React-Native" - react-nativehow to save xls file as xlsx file using C # NPOI? - c #enabling TypeFamilies makes code more rigorous - haskellConvert xlsx file to xls using NPOI in C # - c #Compiling Roslyn does not allow mscorlib links - c #How can I resolve all links with Roslyn OpenSolutionAsync? - c #Fix Chrome Notification of Obsolete Encryption in IIS8.5 and SQL Server 2012 - google-chromeHow to perform runtime binding based on CPU capabilities on Linux - linuxHow to get authenticated user in serializer class for verification - djangoAll Articles