Repository navigation
Expand file tree
/
Copy pathanalytics_fts5_jsonb.sql
More file actions
43 lines (36 loc) · 1.54 KB
/
Copy pathanalytics_fts5_jsonb.sql
File metadata and controls
43 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- SuperCode IDE — Native SQLite 3.54.1 Analytics: Window Functions + FTS5 + JSON
-- Run directly inside SuperCode SQL Studio (100% offline).
-- Docs: https://supercode-ide.github.io/sql-window-functions-fts5-json.html
.mode box
.headers on
CREATE TABLE metrics (
id INTEGER PRIMARY KEY,
lang TEXT NOT NULL,
region TEXT NOT NULL,
runs INTEGER NOT NULL
);
INSERT INTO metrics (lang, region, runs) VALUES
('Python', 'US', 420), ('Python', 'IN', 390), ('Python', 'RU', 280),
('C++20', 'RU', 340), ('C++20', 'US', 260), ('C++20', 'BR', 210),
('SQLite', 'DE', 195), ('SQLite', 'JP', 230), ('Java17', 'ES', 245);
-- 1. Window function ranking & cumulative runs per language
SELECT
lang,
region,
runs,
RANK() OVER (PARTITION BY lang ORDER BY runs DESC) AS region_rank,
SUM(runs) OVER (PARTITION BY lang) AS lang_total
FROM metrics
ORDER BY lang_total DESC, region_rank ASC;
-- 2. FTS5 full-text search index
CREATE VIRTUAL TABLE docs_fts USING fts5(slug, summary);
INSERT INTO docs_fts VALUES
('large-file-editor', 'Open 1GB log files on Android with 120Hz disk pagination'),
('python-pip-manager', 'Install local Python .whl wheels completely offline'),
('sql-ide', 'Native SQLite 3.54 Studio with FTS5 and JSONB support');
SELECT slug, snippet(docs_fts, 1, '[', ']', '...', 12) AS match_snippet
FROM docs_fts
WHERE docs_fts MATCH 'offline OR pagination';
-- 3. JSON aggregation
SELECT json_group_object(lang, total_runs) AS summary_json
FROM (SELECT lang, SUM(runs) AS total_runs FROM metrics GROUP BY lang);