[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79MZ7TZ55QYMFHS50YAGQYV":3,"skill-same:01M79MZ7TZ55QYMFHS50YAGQYV":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":43},"01M79MZ7TZ55QYMFHS50YAGQYV","sql-queries",null,"Pull records with SQL. OmniSkill Legal crew — writes correct, safe queries for audits, discovery, and reporting, with the join and aggregation traps called out.","IPedrax\u002FOmniSkill","IPedrax","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F64429409?v=4","01M79MSCRSKESGTTRZMGK54KW0","01M79MSCSDY16CNNHW0VRGZFHF",9,"MIT","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fsql-queries\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: sql-queries\ndescription: Pull records with SQL. OmniSkill Legal crew — writes correct, safe queries for audits, discovery, and reporting, with the join and aggregation traps called out.\ndisable-model-invocation: true\n---\n\n# SQL Queries\n\n> Pull records with SQL · OmniSkill Legal crew\n\nGetting the right records out of a database — for an audit, a discovery request, a compliance report, or an operational question.\n\n## 1. Understand the schema before writing\n\nNever write a query against an assumed schema. Inspect first:\n\n```sql\n-- Postgres\n\\d table_name\nSELECT column_name, data_type, is_nullable\nFROM information_schema.columns WHERE table_name = 'orders';\n```\n\nEstablish: primary and foreign keys, which columns are nullable, whether deletes are soft (`deleted_at`) or hard, and the timezone convention on timestamps. Each of these silently changes results.\n\n## 2. The traps that produce wrong answers\n\n**Soft deletes.** If the schema has `deleted_at`, every query needs `WHERE deleted_at IS NULL` unless deleted rows are wanted. Forgetting this inflates every count.\n\n**Fan-out on joins.** Joining a one-to-many relationship multiplies rows. `SUM(orders.total)` after joining line items sums each order once per line item. Aggregate in a subquery or CTE first, then join.\n\n**NULL semantics.** `NULL = NULL` is not true. `NOT IN (subquery)` returns *no rows* if the subquery yields a single NULL — use `NOT EXISTS`. Aggregates skip NULLs, so `AVG` over a column with NULLs divides by a smaller count than expected.\n\n**`COUNT(*)` vs `COUNT(col)`.** The first counts rows; the second counts non-NULL values.\n\n**Timezones.** `created_at` in UTC bucketed by local day shifts records across boundaries. Convert explicitly: `created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America\u002FNew_York'`.\n\n**Inclusive ranges.** `BETWEEN '2026-01-01' AND '2026-01-31'` on a timestamp excludes almost all of January 31. Use `>= start AND \u003C next_day`.\n\n**Implicit type coercion.** Comparing a string column to a number can silently cast and full-scan, or error, depending on engine.\n\n## 3. Write it safely\n\n**Read-only by default.** For audit and discovery work, connect with a read-only role. If a mutation is genuinely required, that is a separate, explicitly confirmed action.\n\n**Never build SQL by string concatenation with untrusted input.** Use parameterised queries — this is injection prevention, not style.\n\n**Test the shape before the full run.** Run with `LIMIT 10` first and check the columns and row shape are what was intended. Then remove the limit.\n\n**Check the plan on anything large.** `EXPLAIN ANALYZE` before running a query over millions of rows on a production replica. A sequential scan on a large table can lock up a shared database.\n\nPrefer a read replica for analytical work. Long analytical queries on a primary compete with the application.\n\n## 4. Structure for review\n\nLegal and audit output gets scrutinised, so the query must be readable:\n\n```sql\nWITH active_customers AS (\n    SELECT id, email, created_at\n    FROM customers\n    WHERE deleted_at IS NULL\n      AND created_at >= '2026-01-01'\n),\norder_totals AS (\n    SELECT customer_id, SUM(total) AS lifetime_value, COUNT(*) AS order_count\n    FROM orders\n    WHERE status = 'completed' AND deleted_at IS NULL\n    GROUP BY customer_id          -- aggregate BEFORE joining, to avoid fan-out\n)\nSELECT c.id, c.email, COALESCE(o.lifetime_value, 0) AS lifetime_value\nFROM active_customers c\nLEFT JOIN order_totals o ON o.customer_id = c.id\nORDER BY lifetime_value DESC;\n```\n\nCTEs over nested subqueries. Comment the non-obvious filter, not the obvious one.\n\n## 5. Data minimisation\n\nFor a legal or compliance pull, select only the columns actually needed. Exporting a full table when three fields were requested creates a new personal-data problem while solving a records problem. Route handling questions to `\u002Fomniskill:compliance`.\n\n## 6. Deliver\n\nVerify the row count is plausible before sending. State the exact query, the database and environment, and the timestamp it ran — a result set without its query cannot be reproduced or checked.\n\nExport tabular results via `\u002Fomniskill:xlsx`.\n\n## Checks before delivering\n\n- Schema inspected, not assumed.\n- Soft deletes handled.\n- No fan-out in aggregates.\n- Date ranges half-open; timezone stated.\n- Only necessary columns selected.\n- Query, environment, and run time recorded alongside the results.\n","# SQL Queries\n\n> Pull records with SQL · OmniSkill Legal crew\n\nGetting the right records out of a database — for an audit, a discovery request, a compliance report, or an operational question.\n\n## 1. Understand the schema before writing\n\nNever write a query against an assumed schema. Inspect first:\n\n```sql\n-- Postgres\n\\d table_name\nSELECT column_name, data_type, is_nullable\nFROM information_schema.columns WHERE table_name = 'orders';\n```\n\nEstablish: primary and foreign keys, which columns are nullable, whether deletes are soft (`deleted_at`) or hard, and the timezone convention on timestamps. Each of these silently changes results.\n\n## 2. The traps that produce wrong answers\n\n**Soft deletes.** If the schema has `deleted_at`, every query needs `WHERE deleted_at IS NULL` unless deleted rows are wanted. Forgetting this inflates every count.\n\n**Fan-out on joins.** Joining a one-to-many relationship multiplies rows. `SUM(orders.total)` after joining line items sums each order once per line item. Aggregate in a subquery or CTE first, then join.\n\n**NULL semantics.** `NULL = NULL` is not true. `NOT IN (subquery)` returns *no rows* if the subquery yields a single NULL — use `NOT EXISTS`. Aggregates skip NULLs, so `AVG` over a column with NULLs divides by a smaller count than expected.\n\n**`COUNT(*)` vs `COUNT(col)`.** The first counts rows; the second counts non-NULL values.\n\n**Timezones.** `created_at` in UTC bucketed by local day shifts records across boundaries. Convert explicitly: `created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America\u002FNew_York'`.\n\n**Inclusive ranges.** `BETWEEN '2026-01-01' AND '2026-01-31'` on a timestamp excludes almost all of January 31. Use `>= start AND \u003C next_day`.\n\n**Implicit type coercion.** Comparing a string column to a number can silently cast and full-scan, or error, depending on engine.\n\n## 3. Write it safely\n\n**Read-only by default.** For audit and discovery work, connect with a read-only role. If a mutation is genuinely required, that is a separate, explicitly confirmed action.\n\n**Never build SQL by string concatenation with untrusted input.** Use parameterised queries — this is injection prevention, not style.\n\n**Test the shape before the full run.** Run with `LIMIT 10` first and check the columns and row shape are what was intended. Then remove the limit.\n\n**Check the plan on anything large.** `EXPLAIN ANALYZE` before running a query over millions of rows on a production replica. A sequential scan on a large table can lock up a shared database.\n\nPrefer a read replica for analytical work. Long analytical queries on a primary compete with the application.\n\n## 4. Structure for review\n\nLegal and audit output gets scrutinised, so the query must be readable:\n\n```sql\nWITH active_customers AS (\n    SELECT id, email, created_at\n    FROM customers\n    WHERE deleted_at IS NULL\n      AND created_at >= '2026-01-01'\n),\norder_totals AS (\n    SELECT customer_id, SUM(total) AS lifetime_value, COUNT(*) AS order_count\n    FROM orders\n    WHERE status = 'completed' AND deleted_at IS NULL\n    GROUP BY customer_id          -- aggregate BEFORE joining, to avoid fan-out\n)\nSELECT c.id, c.email, COALESCE(o.lifetime_value, 0) AS lifetime_value\nFROM active_customers c\nLEFT JOIN order_totals o ON o.customer_id = c.id\nORDER BY lifetime_value DESC;\n```\n\nCTEs over nested subqueries. Comment the non-obvious filter, not the obvious one.\n\n## 5. Data minimisation\n\nFor a legal or compliance pull, select only the columns actually needed. Exporting a full table when three fields were requested creates a new personal-data problem while solving a records problem. Route handling questions to `\u002Fomniskill:compliance`.\n\n## 6. Deliver\n\nVerify the row count is plausible before sending. State the exact query, the database and environment, and the timestamp it ran — a result set without its query cannot be reproduced or checked.\n\nExport tabular results via `\u002Fomniskill:xlsx`.\n\n## Checks before delivering\n\n- Schema inspected, not assumed.\n- Soft deletes handled.\n- No fan-out in aggregates.\n- Date ranges half-open; timezone stated.\n- Only necessary columns selected.\n- Query, environment, and run time recorded alongside the results.\n",{"name":5,"description":7,"disable-model-invocation":23},true,"main","cc238b48e3c4fe0061cad0b0475142fbff5b183d","skills\u002Fsql-queries",0,"https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill","https:\u002F\u002Fgithub.com\u002FIPedrax","2026-10-14 10:26:53",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":23},[33,36,39],{"tool":34,"command":35},"npx","npx skills add IPedrax\u002FOmniSkill --skill sql-queries",{"tool":37,"command":38},"bunx","bunx skills add IPedrax\u002FOmniSkill --skill sql-queries",{"tool":40,"command":41},"pnpm","pnpm dlx skills add IPedrax\u002FOmniSkill --skill sql-queries","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fsql-queries\u002FSKILL.md",[],[45,52,59,66,73,79],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M79N058MCJZPHNFYZCPJG3ZZ","xlsx","Excel with live formulas. OmniSkill Operations crew — adapter for the xlsx skill, which installs separately.","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fxlsx\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M79N01GR5C5EK22CKGG38VYH","webapp-testing","Browser-test a web app. OmniSkill Developers crew — drives a real browser to verify user flows, catches console and network errors, and writes tests that do not flake.","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M79MZZSJHFKJRE46BNEHCYZ3","web-artifacts","shadcn HTML artifacts. OmniSkill Design crew — bundled copy of the Web Artifacts skill.","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M79MZXFMCV0QSQ2WN316JKGZ","video","Script and produce video. OmniSkill Social crew — structures short-form and long-form video around retention, with shot lists, captions, and platform-specific delivery.","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fvideo\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M79MZV8SR0N02YX539Z5PS5E","vgpu","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fvgpu\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M79MZS7JG9X0T4T5TGA4MMJS","uisfx","https:\u002F\u002Fgithub.com\u002FIPedrax\u002FOmniSkill\u002Fblob\u002Fmain\u002Fskills\u002Fuisfx\u002FSKILL.md",[],[]]