Skip to content

Instantly share code, notes, and snippets.

@outoftime
Forked from thobbs/gist:4163576
Created November 28, 2012 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save outoftime/4163589 to your computer and use it in GitHub Desktop.
Save outoftime/4163589 to your computer and use it in GitHub Desktop.
CREATE TABLE stats (
column_name text,
column_value int,
test_id uuid,
score int,
height int,
PRIMARY KEY (column_name, column_value, test_id)
);
-- Now let's say we have a logical row with score=20, height=150
INSERT INTO stats (column_name, column_value, test_id, score, height) VALUES ("score", 20, "some-id", 20, 150);
INSERT INTO stats (column_name, column_value, test_id, score, height) VALUES ("height", 150, "some-id", 20, 150);
-- And query for score > 20
SELECT test_id, score, height FROM stats WHERE column_name="score" AND column_value > 20
-- This only works if all of your stats are of the same type (or can reasonably be coerced to the same type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment