What is the "~*" operator for in a select in SQL?

Asked

Viewed 44 times

3

I saw this line of code in some examples:

SELECT * from produto where nome ~*'$texto_pesquisado';"

But I don’t know what the function of ~*, I found no explanation. What is it for?

2 answers

3

The ~* is a Postgresql regex operator that does not differentiate case from case, as you can see in documentation.

So, in your example, you’re looking for a name that doesn’t matter if it starts out as uppercase or lowercase.

  • Thanks for the clarification.

2

In Postgresql the operator ~* serves to search for regular expressions containing the string passed as a search parameter, without differentiating between uppercase and lowercase characters, i.e., in case sensitive.

In this case, your query SELECT * from produto where nome ~*'$texto_pesquisado';", will return all lines that contain in your name the expression '$texto_pesquisado', no matter if it is capitalized or minuscula.

You can see more about here https://www.postgresql.org/docs/9.3/functions-matching.html.

  • Thanks for the clarification.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.