Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
http://bonesmoses.org/2016/07/15/pg-phriday-a-postgres-persepctive-on-mongodb/
CREATE TABLE sensor_log (
id SERIAL NOT NULL PRIMARY KEY,
location VARCHAR NOT NULL,
reading BIGINT NOT NULL,
reading_date TIMESTAMP NOT NULL
);
\timing
INSERT INTO sensor_log (id, location, reading, reading_date)
SELECT s.id, s.id % 1000, s.id % 100,
CURRENT_DATE - ((s.id * 10) || 's')::INTERVAL
FROM generate_series(1, 1000000) s(id);
TIME: 7236.906 ms
CREATE INDEX idx_sensor_log_date
ON sensor_log (reading_date);
TIME: 804.044 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment