I am trying CHARINDEX
in Postgresql. But it says:
function CHARINDEX() does not exist
If no such inbuilt function exists in postgresql, then is there any function that serves as an alternative to charindex?
If yes, What is the CHARINDEX
(SQL SERVER) equivalent in POSTGRESQL ?
SQL Server CHARINDEX() function searches for a substring inside a string starting from a specified location. It returns the position of the substring found in the searched string, or zero if the substring is not found. The starting position returned is 1-based, not 0-based.
SQL Server CHARINDEX() Function The CHARINDEX() function searches for a substring in a string, and returns the position. If the substring is not found, this function returns 0. Note: This function performs a case-insensitive search.
The PostgreSQL reverse() function is used to arrange a string in reverse order. Example: PostgreSQL reverse() function: In the example below, the string 'w3resource' have arranged in reverse order.
The equivalent function in postgresql is:
strpos(string, substring)
Or:
position(substring in string)
They are equivalent, just with different order in parameters.
If you also need parameter start_location, you will need to pass a substring to strpos.
You can find them in: https://www.postgresql.org/docs/current/functions-string.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With