sqlite-sql
SQLite-specific SQL patterns: substr/instr for string ops, || for concatenation, LIKE (no ILIKE), date()/strftime() for dates, CAST for type coercion, no FULL OUTER JOIN, GROUP_CONCAT, typeof(), COALESCE/IFNULL, printf() formatting.
适合你,如果经常用 SQLite 写复杂 SQL 查询
/ 通过 npx 安装 校验哈希
npx oh-my-skill add signalpilot-labs/signalpilot/sqlite-sql/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- signalpilot-labs/signalpilot/sqlite-sql/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify signalpilot-labs/signalpilot/sqlite-sql安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
473GitHub stars
~1.2K上下文体积 · 单文件
索引托管
怎么用
商店整理自技能原文 · 版本 436a4c4 · 表述以原文为准它做什么
Claude会用SQLite特有的SQL语法(如substr/instr、||、LIKE、date()等)来编写数据库查询,避免使用其他数据库的语法。
什么时候触发
当用户要求编写SQLite数据库的SQL查询或进行数据操作时,例如连接字符串、处理日期或聚合数据。
装好后可以这样说
Claude会使用||运算符
Claude会使用strftime()函数
Claude会给出UNION模拟写法
技能原文 SKILL.md
SQLite SQL Skill
1. String Functions - substr() and instr()
SQLite has no POSITION() or SPLIT_PART(). Use substr() and instr():
-- Extract substring starting at position 3, length 5 SELECT substr(col, 3, 5) FROM t; -- Find position of substring (0 if not found) SELECT instr(col, 'needle') FROM t; -- Extract everything after a delimiter SELECT substr(col, instr(col, '/') + 1) FROM t WHERE instr(col, '/') > 0;
2. String Concatenation - Use || (not CONCAT)
-- Concatenate two strings SELECT first_name || ' ' || last_name AS full_name FROM employees; -- With NULL handling (|| propagates NULL) SELECT COALESCE(first_name, '') || ' ' || COALESCE(last_name, '') AS full_name FROM employees;
3. Case-Insensitive Matching - LIKE Only (no ILIKE)
SQLite's LIKE is case-insensitive for ASCII letters by default. There is no ILIKE:
-- Case-insensitive search (ASCII only by default)
WHERE name LIKE '%widget%'
-- For Unicode/non-ASCII, use UPPER/LOWER explicitly
WHERE UPPER(name) LIKE UPPER('%widget%')
4. Date Functions - date(), datetime(), strftime()
SQLite stores dates as text (ISO 8601), real, or integer. Use built-in date functions:
-- Current date / datetime
SELECT date('now');
SELECT datetime('now');
-- Add/subtract time
SELECT date('now', '+7 days');
SELECT date('now', '-1 month');
SELECT date(col, '+1 year') FROM t;
-- Truncate to month start
SELECT date(col, 'start of month') FROM t;
-- Extract parts
SELECT strftime('%Y', col) AS year FROM t;
SELECT strftime('%m', col) AS month FROM t;
SELECT strftime('%Y-%m', col) AS year_month FROM t;
-- Difference in days (days between two dates)
SELECT CAST(julianday(end_date) - julianday(start_date) AS INTEGER) AS days_diff
FROM t;
5. Type Coercion - CAST() Only (no :: syntax)
SQLite does not support the :: cast syntax. Use CAST():
-- Cast to integer SELECT CAST(price AS INTEGER) FROM products; -- Cast to real SELECT CAST(score AS REAL) FROM results; -- Cast to text SELECT CAST(id AS TEXT) FROM records;
6. No FULL OUTER JOIN - Simulate with UNION
SQLite does not support FULL OUTER JOIN. Simulate it:
-- FULL OUTER JOIN equivalent SELECT a.id, a.val, b.val FROM table_a a LEFT JOIN table_b b ON a.id = b.id UNION SELECT b.id, a.val, b.val FROM table_b b LEFT JOIN table_a a ON b.id = a.id WHERE a.id IS NULL;
7. String Aggregation - GROUP_CONCAT
-- Comma-separated list of values per group
SELECT department, GROUP_CONCAT(name) AS members
FROM employees
GROUP BY department;
-- Custom separator
SELECT department, GROUP_CONCAT(name, ' | ') AS members
FROM employees
GROUP BY department;
-- With ordering (SQLite 3.44+, use subquery for older versions)
SELECT department,
GROUP_CONCAT(name ORDER BY name) AS sorted_members
FROM employees
GROUP BY department;
8. Runtime Type Checking - typeof()
-- Returns 'integer', 'real', 'text', 'blob', or 'null' SELECT typeof(col) FROM t; -- Filter by storage class SELECT * FROM t WHERE typeof(col) = 'integer';
9. NULL Handling - COALESCE, IFNULL, NULLIF
-- COALESCE: first non-NULL value SELECT COALESCE(col1, col2, 'default') FROM t; -- IFNULL: SQLite shorthand for two-argument COALESCE SELECT IFNULL(col, 0) FROM t; -- NULLIF: return NULL if two values are equal SELECT NULLIF(col, 0) FROM t; -- returns NULL when col = 0
10. Formatted Output - printf()
-- Zero-padded integer
SELECT printf('%05d', id) FROM t;
-- Fixed decimal places
SELECT printf('%.2f', price) FROM t;
-- String formatting
SELECT printf('%s-%s', category, subcategory) FROM t;
11. Common Anti-Patterns to Avoid
- No
BOOLEANtype - use0and1(integers) - No
ALTER COLUMN- SQLite only supportsADD COLUMNinALTER TABLE - Prefer
WITHOUT ROWIDonly for tables with non-integer primary keys - Do NOT use
AUTOINCREMENTunless you need gap-free IDs - plainINTEGER PRIMARY KEYgives auto-increment behavior and is faster LIKEpattern uses%(any chars) and_(one char) - no regex by defaultIN (SELECT ...)is generally faster than correlated subqueries in SQLite- Do NOT use
= NULL- useIS NULL ||propagates NULL - wrap withCOALESCEwhen concatenating nullable columns
12. Benchmark Patterns
- Window functions: SQLite supports ROW_NUMBER, RANK, DENSE_RANK, NTILE, LAG, LEAD since 3.25. No QUALIFY - use subquery wrapping.
- HAVING without GROUP BY: Not valid in SQLite - always pair HAVING with GROUP BY.
- Recursive CTEs:
WITH RECURSIVEworks in SQLite - useful for hierarchical data (org charts, category trees). - No LIMIT in subqueries with IN:
WHERE col IN (SELECT ... LIMIT N)is not supported - use a CTE instead.
按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →
评论
登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。
…