This file contains hidden or 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
-- 1. Create the extension (if not already created) | |
CREATE EXTENSION IF NOT EXISTS timescaledb; | |
-- 2. Create the base order table without storing cumulative values | |
DROP TABLE IF EXISTS table_order CASCADE; | |
CREATE TABLE table_order ( | |
time TIMESTAMPTZ NOT NULL DEFAULT NOW(), | |
address TEXT NOT NULL, | |
customer TEXT NOT NULL, | |
amount_order_A INTEGER NOT NULL, |
This file contains hidden or 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
CREATE EXTENSION IF NOT EXISTS ai CASCADE; | |
DROP TABLE IF EXISTS vecs CASCADE; | |
DROP TABLE IF EXISTS interests CASCADE; | |
DROP TABLE IF EXISTS notifications CASCADE; | |
-- Create or replace the function to embed content | |
CREATE OR REPLACE FUNCTION embed(content TEXT) RETURNS VECTOR AS $$ | |
DECLARE | |
vectorized_content VECTOR; | |
BEGIN |
This file contains hidden or 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
# Search time_bucket calls | |
Fast.shortcut :time_bucket, '^^(func_call (funcname (string (sval "time_bucket")' | |
if ENV['PG_URI'] | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'timescaledb', path: '../../code/timescale/timescale-gem' | |
gem 'pry' |
This file contains hidden or 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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'timescaledb' | |
gem 'bulk_insert' | |
gem 'pry' | |
end | |
require 'timescaledb' |
This file contains hidden or 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; | |
CREATE TABLE "ticks" ("time" timestamp with time zone not null, "symbol" text, "price" decimal, "volume" float); | |
SELECT create_hypertable('ticks', 'time', chunk_time_interval => INTERVAL '1 week'); | |
ALTER TABLE ticks SET ( | |
timescaledb.compress, | |
timescaledb.compress_orderby = 'time', | |
timescaledb.compress_segmentby = 'symbol' |
This file contains hidden or 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 * FROM crosstab($$ | |
WITH city_names AS ( | |
SELECT DISTINCT city_name as name | |
FROM weather_metrics order by 1 | |
), | |
pairs as ( | |
SELECT a.name as first, b.name as second | |
FROM city_names a | |
JOIN city_names b ON true --# a.name != b.name | |
), |
This file contains hidden or 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
require 'bundler/inline' | |
gemfile(true) do | |
gem 'timescaledb' | |
gem 'pry' | |
end | |
require 'pp' | |
# ruby caggs.rb postgres://user:pass@host:port/db_name | |
ActiveRecord::Base.establish_connection( ARGV.last) |
This file contains hidden or 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
-- First set the numbers of hypertables you'd like to test | |
\set hypertables_count 100 | |
-- Hypertable configuration with the chunk time interval for every hypertable | |
\set chunk_time_interval '''1 hour''' | |
-- How much data you'd like to append for every append_data call | |
\set append_interval '''1 day''' | |
-- How many devices would you like to simulate in parallel | |
\set number_of_devices '''1''' | |
-- When the data starts | |
\set start_date '''2000-01-01''' |
NewerOlder