This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists table1; | |
create table if not exists table1(time timestamp, category varchar, value numeric(10,2)); | |
SELECT create_distributed_hypertable('table1','time','category',3, chunk_time_interval => Interval '3 hours'); | |
--SELECT add_dimension('table1', 'col1', number_partitions => 3); | |
INSERT INTO table1 | |
SELECT time, 'category-'||((random()*3)::int), (random()*100)::numeric(10,2) | |
FROM generate_series(TIMESTAMP '2000-01-01 00:01:00', | |
TIMESTAMP '2000-01-01 00:01:00' + INTERVAL '5 minutes', | |
INTERVAL '1 second') AS time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE if exists ticks CASCADE; | |
DROP view if exists ohlc_1m CASCADE; | |
CREATE TABLE ticks | |
( time TIMESTAMP NOT NULL, | |
symbol varchar, | |
price decimal, | |
volume int); | |
SELECT create_hypertable('ticks', 'time', chunk_time_interval => INTERVAL '1 day'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table batteries cascade; | |
CREATE TABLE batteries (t timestamp not null, batt_uid varchar, charge int); | |
SELECT create_hypertable('batteries', 't'); | |
DROP FUNCTION IF EXISTS watch_charge; | |
CREATE OR REPLACE FUNCTION watch_charge(INOUT t timestamp, INOUT batt_uid varchar, INOUT charge int) AS | |
$BODY$ | |
BEGIN | |
IF charge > 100 then | |
raise notice 'Battery % charge is too high: %', batt_uid, charge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE if exists ticks CASCADE; | |
DROP view if exists ohlc_1m CASCADE; | |
CREATE TABLE ticks ( time TIMESTAMP NOT NULL, symbol varchar, price decimal, volume int); | |
SELECT create_hypertable('ticks', 'time'); | |
CREATE MATERIALIZED VIEW ohlc_1m | |
WITH (timescaledb.continuous) AS | |
SELECT time_bucket('1m', time) as bucket, | |
symbol, | |
FIRST(price, time) as open, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE if exists ticks CASCADE; | |
DROP view if exists ohlc_1m CASCADE; | |
CREATE TABLE ticks ( time TIMESTAMP NOT NULL, symbol varchar, price decimal, volume int); | |
SELECT create_hypertable('ticks', 'time'); | |
CREATE MATERIALIZED VIEW ohlc_1m | |
WITH (timescaledb.continuous) AS | |
SELECT time_bucket('1m', time) as bucket, | |
symbol, | |
FIRST(price, time) as open, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
ruby '2.6.5' | |
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | |
gem 'rails', '~> 6.0.3', '>= 6.0.3.6' | |
# Use postgresql as the database for Active Record | |
gem 'pg', '>= 0.18', '< 2.0' | |
# Use Puma as the app server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select delete_job(job_id) from timescaledb_information.jobs where job_id >=1000; | |
drop table conditions cascade; | |
CREATE TABLE conditions ( | |
time TIMESTAMPTZ NOT NULL, | |
device INTEGER NOT NULL, | |
temperature FLOAT NOT NULL | |
); | |
SELECT * FROM create_hypertable('conditions', 'time'); | |
INSERT INTO conditions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE ticks CASCADE; | |
DROP TABLE ohlc_1s CASCADE; | |
CREATE TABLE ticks ( time TIMESTAMP NOT NULL, symbol varchar, price decimal, volume int); | |
CREATE TABLE ohlc_1s ( time TIMESTAMP NOT NULL, symbol varchar, o decimal, h decimal, l decimal, c decimal, v int); | |
SELECT create_hypertable('ticks', 'time'); | |
SELECT create_hypertable('ohlc_1s', 'time'); | |
CREATE OR REPLACE FUNCTION feed_ohlc_1s() RETURNS trigger AS | |
$BODY$ | |
DECLARE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem "activerecord", "~> 6.1" | |
gem "composite_primary_keys", "~> 6.0" | |
gem "pg", "~> 1.2" | |
gem 'pry' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem "activerecord", "~> 6.1" | |
gem "composite_primary_keys", "~> 6.0" | |
gem "pg", "~> 1.2" | |
gem 'pry' | |