0

I want to make a search function in my website. I want to search for a string in all fields of my table (about 13 columns). If one row contains a field that matches the string (like operator) I want it to be added to result.

Example

|field 1 | field 2 | field 3|
 some      string     test    
 test      some      string
 one       simple    string

Now basically if I search for the string "test" I want to have the first two rows.

Is there a wildcard option for WHERE that I could do something :

SELECT * from my.table WHERE * like '%string%';

2
  • 1
    No, you need to write the WHERE clause. It's much less typing than you did to write this question. Just throw the column names into an array and loop over it to produce the list of ORed comparisons. Commented Jul 21, 2011 at 9:29
  • Whatever technique you use, it's going to produce a dead slow query. Commented Jul 21, 2011 at 9:54

1 Answer 1

2

There is no such syntax in PostgreSQL (or any other DBMS).

As Spudley pointed out using a query like like '%string%' will be quite slow.

If this is something that is needed very often you should definitely look into PostgreSQL's full text search capabilities.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.