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
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 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 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 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 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 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 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''' |
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 |
NewerOlder