Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the CHARINDEX (SQL SERVER) equivalent in POSTGRESQL?

Tags:

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 ?

like image 278
Manoj Soundararajan Avatar asked Jun 11 '15 10:06

Manoj Soundararajan


People also ask

What is SQL Charindex?

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.

How does Charindex work in SQL Server?

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.

How do I reverse a string in PostgreSQL?

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.


1 Answers

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

like image 86
user_0 Avatar answered Sep 19 '22 04:09

user_0