ggsql Query Writer
Write valid ggsql visualization queries from natural-language requests. ggsql combines SQL data shaping with a declarative grammar of graphics.
Use this skill when
- Creating or modifying a ggsql query.
- Converting a chart request into ggsql.
- Explaining, validating, or running ggsql.
- Choosing ggsql layers, mappings, scales, facets, projections, or labels.
Do not trigger for ordinary SQL work that has no visualization component.
Required reference
Read references/syntax.md before writing or changing a query. It is the complete upstream language reference and defines the allowed clauses, aesthetics, layers, settings, palettes, and CLI commands.
Never invent ggsql syntax. If the reference does not document a requested feature, say so and offer the closest documented form.
Workflow
- Identify the data source, columns, desired visual encodings, grouping, and output.
- Shape data with SQL or CTEs before
VISUALISE when necessary.
- Choose the simplest documented
DRAW layer and mappings.
- Add
SCALE, FACET, PROJECT, or LABEL only when the request needs them.
- If
ggsql is available, validate with ggsql validate. Render with ggsql exec ... -v only when output is requested.
- Return the complete query, then briefly explain consequential choices.
Minimal pattern
SELECT category, SUM(value) AS total
FROM 'data.parquet'
GROUP BY category
VISUALISE category AS x, total AS y
DRAW bar
LABEL
title => 'Total by category',
x => 'Category',
y => 'Total'
Alternatively, let VISUALISE name the source:
VISUALISE bill_len AS x, bill_dep AS y, species AS color
FROM ggsql:penguins
DRAW point
Guardrails
- Use only documented clauses, settings, aesthetics, layers, transforms, and palettes.
- Preserve the user's source names and column names.
- Prefer
ggsql:penguins or ggsql:airquality only when example data is needed.
- Do not claim validation or rendering unless the command actually ran.
- Keep SQL portable unless the selected backend requires a documented dialect feature.
1---2name: ggsql3description: Writes, modifies, explains, validates, and runs ggsql grammar-of-graphics visualization queries.4license: MIT5---67# ggsql Query Writer89Write valid ggsql visualization queries from natural-language requests. ggsql combines SQL data shaping with a declarative grammar of graphics.1011## Use this skill when1213- Creating or modifying a ggsql query.14- Converting a chart request into ggsql.15- Explaining, validating, or running ggsql.16- Choosing ggsql layers, mappings, scales, facets, projections, or labels.1718Do not trigger for ordinary SQL work that has no visualization component.1920## Required reference2122Read [references/syntax.md](references/syntax.md) before writing or changing a query. It is the complete upstream language reference and defines the allowed clauses, aesthetics, layers, settings, palettes, and CLI commands.2324Never invent ggsql syntax. If the reference does not document a requested feature, say so and offer the closest documented form.2526## Workflow27281. Identify the data source, columns, desired visual encodings, grouping, and output.292. Shape data with SQL or CTEs before `VISUALISE` when necessary.303. Choose the simplest documented `DRAW` layer and mappings.314. Add `SCALE`, `FACET`, `PROJECT`, or `LABEL` only when the request needs them.325. If `ggsql` is available, validate with `ggsql validate`. Render with `ggsql exec ... -v` only when output is requested.336. Return the complete query, then briefly explain consequential choices.3435## Minimal pattern3637```ggsql38SELECT category, SUM(value) AS total39FROM 'data.parquet'40GROUP BY category41VISUALISE category AS x, total AS y42DRAW bar43LABEL44 title => 'Total by category',45 x => 'Category',46 y => 'Total'47```4849Alternatively, let `VISUALISE` name the source:5051```ggsql52VISUALISE bill_len AS x, bill_dep AS y, species AS color53FROM ggsql:penguins54DRAW point55```5657## Guardrails5859- Use only documented clauses, settings, aesthetics, layers, transforms, and palettes.60- Preserve the user's source names and column names.61- Prefer `ggsql:penguins` or `ggsql:airquality` only when example data is needed.62- Do not claim validation or rendering unless the command actually ran.63- Keep SQL portable unless the selected backend requires a documented dialect feature.