작은 SQLite 파일로 패치 상태를 계속 관리하고 있고, sqlite3 :memory: < main.sql로 실행해요. 2026-10-01 이전에 마지막으로 패치됐고 활성 유지보수 hold가 없는 호스트를 찾고 싶어요. 활성은 until >= '2026-11-02'를 뜻해요.
제가 세어 보면 5개 호스트가 나와야 해요. 기한이 지난 호스트만 세면 6개이고, 그중 live hold가 있는 건 db-la-01뿐이에요. 그런데 아래 쿼리는 아무것도 반환하지 않아요. 종료 상태는 0이고 경고도 없어요.
SELECT hostname, env, last_patched
FROM hosts
WHERE last_patched < '2026-10-01'
AND id NOT IN (
SELECT host_id FROM maint_holds WHERE until >= '2026-11-02'
)
ORDER BY last_patched;
count 버전은 이렇게 출력돼요:
candidates
----------
0
확인해 본 것들이에요:
- 인벤토리와 hold 목록은 맞아 보여요.
- 서브쿼리만 따로 실행하면 예상한 행이 나와요.
until은 TEXT지만 값이 전부 ISO 8601이고 형식도 일정해요.
>=를 >로 바꿔도 달라지는 게 없었어요.
참고로 활성 hold 목록은 이래요:
id host_id hostname_hint until
-- ------- ------------- ----------
1 3 db-la-01 2026-11-15
3 db-la-02 2026-12-01
두 번째 hold는 아직 hosts에 없는 db-la-02 거예요. 호스트명을 아직 연결하지 않아서 host_id가 비어 있어요. 만들다 만 기능이라서, 실제로 있는 호스트를 조회하는 쿼리에 왜 영향을 주는지 모르겠어요.
그러면 왜 필터가 db-la-01만 빼는 게 아니라 모든 행을 없애는 걸까요? 텍스트 비교를 의심했는데 날짜는 문제없어요. 제가 놓친 게 뭘까요?
영어에서 번역·원문 보기I keep patching state in a small SQLite file and run it with sqlite3 :memory: < main.sql. I want hosts last patched before 2026-10-01 that have no active maintenance hold. Active means until >= '2026-11-02'.
By my count that is 5 hosts. The overdue count alone is 6, and only db-la-01 has a live hold. The query below returns nothing at all. Exit status 0, no warning.
SELECT hostname, env, last_patched
FROM hosts
WHERE last_patched < '2026-10-01'
AND id NOT IN (
SELECT host_id FROM maint_holds WHERE until >= '2026-11-02'
)
ORDER BY last_patched;
The count version prints this:
candidates
----------
0
What I checked:
- The inventory and holds listings look right.
- The subquery run by itself returns the rows I expect.
until is TEXT, but every value is ISO 8601 and the format is consistent.
- Swapping
>= for > changed nothing.
The active holds listing, for reference:
id host_id hostname_hint until
-- ------- ------------- ----------
1 3 db-la-01 2026-11-15
3 db-la-02 2026-12-01
The second hold is for db-la-02, which isn't in hosts yet. I haven't resolved the hostname, so host_id is empty. That's a half-finished feature, and I don't see why it would affect a query about hosts that do exist.
So why does the filter remove every row instead of just db-la-01? I suspected the text comparison, but the dates are fine. What am I missing?