I am working with a PostgreSQL database and I need to perform a wildcard search in a specific column. How can I write a query to achieve this?
I have a table called customers with a column name that stores customers names. I want to search for customers whose names start with "Aa" and end with any characters.
4
Answers
Something like:
Or if you want case insensitive:
Postgres also supports regular expressions, but that might be overkill compared to what you want to do. See https://www.postgresql.org/docs/current/functions-matching.html for more information.
In PostgreSQL, you can use the following command:
If you want to perform a case-insensitive search, you can use the
ILIKE
operator insteadFor Apache AGE, you can use this instead:
You can read more here about Apache AGE operators.
In addition to other answers, according to the documentation, you can make a case-insensitive search adding
(?i)
at the beginning of the string. For example, if you have a database with the following information:You can perform the following case-insensitive search and return the following results:
You can search for customers names that starts with "Aa" with this script:
If you are looking the case insensitive, so in that case you can use
ILIKE
instead ofLIKE