I have an SQLite query like:
SELECT max(e), url, branch
FROM (
SELECT max(T1.entry) e, T1.url, T1.branch
FROM repo_history T1
WHERE (
SELECT active
FROM repos T2
WHERE url = T1.url
AND branch = T1.branch
AND project = ?1
)
GROUP BY T1.url, T1.branch
UNION
SELECT null, T3.url, T3.branch
FROM repos T3
WHERE active
AND project = ?1
)
GROUP BY url
ORDER BY e
Note that there are two occurrences of the ?1
parameter. Anyway, in some cases, it can be null (None
in Python, as far as I know, becomes NULL
in SQLite). This is a problem because I don't understand null handling but basically I don't get anything back.
How do I handle where "project" = ?1
when ?1
is a null? I'd like to avoid having 2 separate queries for it. I looked around but I can only find stuff about IS NULL
/IS NOT NULL
, which doesn't work for me because I'm not trying to check if a column is null or not null, but rather, I'm trying to check if two nullable values match, be they null or not null.