Sunday, May 1, 2011

Can I search multiple table columns in SQLite using a wildcard?

I have a table, contacts, that has a dozen columns or so. I want to identify each row in which at least one column contains a regular expression. I'm wondering if it's possible to do something like this:

select * from contacts where * like '%re%';

instead of this:

select * from contacts where last_name like '%re%' or first_name like '%re%' or ... ;

Is this possible?

From stackoverflow
  • I don't think that's possible. Perhaps you could put a trigger on the table to update a single denormalized column?

    Tony : Thanks. I think you're right. I was able to construct the query in Python easily enough.
  • select * from contacts where concat(last_name, ' ', first_name) like '%re%'
    
    Tony : Interesting. This isn't quite what I was looking for (I have 10+ columns for various fields), but this is good to know.

0 comments:

Post a Comment