Chapter 2. Basic queries

Table of Contents
Case insensitive searches
Escaping LIKE wildcards
Records without a corresponding key in another table
Returning the first N results
Returning the next N results
Returning the last N results
Selecting part of a date
Converting a date to unix timestamp (epoch seconds)
Combining two sets of results

Case insensitive searches

You want to check equality or do a regular expression search but ignoring case

Solution

Either use lower() on the field and the value being compared or use the ILIKE or ˜˜* regular expression operators ref.

Discussion

If you want to do a simple comparison of a text field use the lower() or upper() functions:

SELECT * FROM companies WHERE lower('Archonet')=lower(co_name);
   

If you want to do a case-insensitive wildcard match use the ILIKE keyword or ˜˜* operator:

SELECT * FROM companies WHERE co_name ILIKE 'Arc%';
   

Note that both ILIKE and ˜˜* are locale-dependent and are Postgres-specific.