SkipLabs / skdb

SKDB is an embedded SQL database that stays in sync.

Home Page:https://skdb.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Evaluating a select where in (select...) query does not seem to work

gregsexton opened this issue · comments

root@ws://localhost:3586/skiplabs> select * from task_events;
┌─────────┬───────────────────────────────┬──────────────────────────────┬────────────┬───────────────────────┬─────────────┬──────────────┐
│ (index) │              eid              │             tid              │   event    │           t           │ skdb_author │ skdb_access  │
├─────────┼───────────────────────────────┼──────────────────────────────┼────────────┼───────────────────────┼─────────────┼──────────────┤
│    0    │ 'f901qBX3mFn7cKmNYxufzsCxKp4' │ 'f90149mur-5jz9xT8AJa9LB4N9' │ 'created'  │ '2024-02-21 17:02:39' │   'root'    │ 'read-write' │
│    1    │ 'f901t_YPdQOXA9AI24hAlm6nv8E' │ 'f90149mur-5jz9xT8AJa9LB4N9' │ 'assigned' │ '2024-02-21 17:02:53' │   'root'    │ 'read-write' │
└─────────┴───────────────────────────────┴──────────────────────────────┴────────────┴───────────────────────┴─────────────┴──────────────┘
root@ws://localhost:3586/skiplabs> SELECT max(eid) AS eid FROM task_events WHERE event = 'assigned' GROUP BY tid;
┌─────────┬───────────────────────────────┐
│ (index) │              eid              │
├─────────┼───────────────────────────────┤
│    0    │ 'f901t_YPdQOXA9AI24hAlm6nv8E' │
└─────────┴───────────────────────────────┘
root@ws://localhost:3586/skiplabs> select * from task_events where eid in (SELECT max(eid) AS eid FROM task_events WHERE event = 'assigned' GROUP BY tid);

Relevant schema:

CREATE TABLE task_events (
  eid TEXT PRIMARY KEY,
  tid TEXT NOT NULL,
  event TEXT NOT NULL,
  t TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
  skdb_author TEXT NOT NULL,
  skdb_access TEXT NOT NULL
);

I'm expecting the relevant row to be returned but I get an empty result set.

Simplifying as much as I can select * from task_events where eid in (SELECT max(eid) FROM task_events); doesn't return any results either.

Ah! But select * from task_events where eid in (SELECT eid FROM task_events); does. So must be the function?