Skip to content

Commit c99d05c

Browse files
committed
query-optimization: add case-insensitive text search and apostrophe escaping guidance
Fixes #41. Two recurring SQL generation errors observed in tpl-ca logs: - LIKE on uppercase name fields returning zero results (missing lower()) - Apostrophes in site names causing parse errors (need doubled quotes)
1 parent 635727d commit c99d05c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

query-optimization.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ JOIN read_parquet('<STAC_CARBON_HEX_PATH>') c
3939
**Note:** `rook-ceph-rgw-nautiluss3.rook` is an internal endpoint only accessible from k8s. Always use it — not the public endpoint — to run queries.
4040

4141
You must read parquet datasets from S3 using read_parquet(). There are no local tables.
42+
43+
## 3. Case-insensitive text search
44+
45+
DuckDB `LIKE` is case-sensitive by default. Name/label fields (site names, owner names,
46+
program names) are often stored in uppercase or mixed case. Always normalize both sides:
47+
48+
```sql
49+
WHERE lower(site) LIKE '%' || lower('user input') || '%'
50+
```
51+
52+
## 4. Apostrophes in string literals
53+
54+
Site names and owner names can contain apostrophes (e.g. `O'Brien Ranch`). Double any
55+
single quote inside a SQL string literal — do not use a backslash:
56+
57+
```sql
58+
WHERE site = 'O''Brien Ranch' -- correct
59+
WHERE site = 'O'Brien Ranch' -- parse error
60+
```

0 commit comments

Comments
 (0)