Skip to content

Instantly share code, notes, and snippets.

@robrich
robrich / data-load.sql
Created January 22, 2021 19:21
Loading Geography Data into SingleStore
create database maps;
use maps;
create table countries (
boundary geography,
name_short varchar(3),
name varchar(50),
name_long varchar(50),
abbrev varchar(10),
postal varchar(4),
@robrich
robrich / sql-to-json.sql
Created January 5, 2021 01:07
Select relational data into JSON with SingleStore: to_json() and json_agg()
-- Create database
create database if not exists acme;
use acme;
-- Create table
create rowstore table `record` (
`name` varchar(100) DEFAULT NULL,
`type` varchar(100) DEFAULT NULL,
`amount` int(11) DEFAULT NULL,
SHARD KEY ()
@robrich
robrich / universal-storage-7.3.sql
Created December 15, 2020 23:22
Universal Storage in 7.3
create database db1;
use db1;
create table t(a int not null, shard(a), sort key());
insert t values(1);
delimiter //
/* Fill table t with n or more rows, doubling the size until
the goal is reached. */
@robrich
robrich / time-series.sql
Created October 12, 2020 19:34
time-series.sql
-- TIME SERIES
-- ===========
-- setup schema
CREATE DATABASE temp_history;
USE temp_history;
CREATE TABLE temperatures (
location VARCHAR(200) NOT NULL,
-- FULL TEXT SEARCH
-- ================
-- setup schema
CREATE DATABASE library;
USE library;
CREATE TABLE books (
title VARCHAR(200) not null,
@robrich
robrich / cluster_file.yaml
Created September 23, 2020 16:39
Cluster configuration file
license: YOUR_LICENSE_KEY
memsql_server_version: 7.1.8
package_type: rpm
hosts:
- hostname: 127.0.0.1
localhost: true
nodes:
- register: false
role: Master
config:
-- Step_1: setup
Create database testDB;
use testDB;
Create table t( a int, b varchar(70));
insert into t values (1, now(6));
insert into t select a+(select max(a) from t), now(6) from t;
select count(*) from t;
-- Step_3: updates on primary
insert into t values (-1, now(6));
@robrich
robrich / init.sql
Created August 18, 2020 00:11
Get started with MemSQL on Windows
CREATE DATABASE IF NOT EXISTS hellomemsql;
USE hellomemsql;
CREATE TABLE IF NOT EXISTS messages (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
content varchar(300) NOT NULL,
createdate TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
@robrich
robrich / cluster1.sql
Created August 3, 2020 21:00
MemSQL Disaster Recovery - failback to primary cluster demo
-- Step_1: setup
Create database testDB;
use testDB;
Create table t( a int, b varchar(70));
insert into t values (1, now(6));
insert into t select a+(select max(a) from t), now(6) from t;
select count(*) from t; -- 262144
-- Step_3: updates on primary
insert into t values (-1, now(6));
@robrich
robrich / memsql-json.sql
Created August 3, 2020 16:57
CRUD with JSON in MemSQL
create database acme;
use acme;
create table customer (
id int,
name varchar(200),
properties json not null,
key (id) using clustered columnstore
);