SQL
The shaman's Far Sight: stand still, see across an entire database at once. Data lives in tables; SQL is how you ask them questions.
Wears the Classic spell Far Sight.
Coming from Python: Your dict-of-lists intuition becomes rows and columns. The re-orientation is thinking in whole sets at once instead of looping row by row.
Summoning the language
First summoning
SQLite is already on your machine and Python ships a module for it. Create a table, insert rows, and ask for some back. Notice there is no loop: the question IS the work.
CREATE TABLE spells (name TEXT, rank INTEGER);
INSERT INTO spells VALUES ('fireball', 3);
SELECT * FROM spells WHERE rank >= 2;The temper
The power move is joining tables and aggregating: one question that cross-references two tables and counts as it goes. GROUP BY collapses rows into answers; ORDER BY ranks them.
SELECT c.name, COUNT(s.id) AS castable
FROM characters c
JOIN spells s ON s.owner_id = c.id
GROUP BY c.name
ORDER BY castable DESC;First real chore
Put real data you care about into SQLite (your expenses, your game collection, a log file you parse with Python) and answer five real questions with queries. Then learn EXPLAIN: it shows the plan, and indexes are how you change it.
EXPLAIN QUERY PLAN
SELECT * FROM spells WHERE name = 'fireball';
CREATE INDEX idx_spells_name ON spells(name); -- then EXPLAIN again