Skip to content

Instantly share code, notes, and snippets.

@mgramin
Created January 25, 2022 19:37
Show Gist options
  • Select an option

  • Save mgramin/6f30d31bddcdd58dd648f232a5e29ce2 to your computer and use it in GitHub Desktop.

Select an option

Save mgramin/6f30d31bddcdd58dd648f232a5e29ce2 to your computer and use it in GitHub Desktop.
Relational Interval Tree Example
CREATE TABLE test(text value, int node_id, int left_bound_id, int right_bound_id);
INSERT INTO test VALUES ('Food', 0, 1, 10000);
INSERT INTO test VALUES ('Fruit', 100, 101, 199);
INSERT INTO test VALUES ('Cherry', 101, null, null);
INSERT INTO test VALUES ('Banana', 102, null, null);
INSERT INTO test VALUES ('Meat', 200, 201, 299);
INSERT INTO test VALUES ('Beaf', 201, null, null);
INSERT INTO test VALUES ('Pork', 202, null, null);
-- get all fruits
SELECT value FROM tests WHERE node_id between 101 and 199;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment