Skip to content
Back to skills

Bigquery Query Generation

ASecurity

Use when generating BigQuery SQL from natural language descriptions, converting queries from other SQL dialects to BigQuery, writing new BigQuery queries from scratch, or when the user describes what data they need and expects SQL output. Triggers on: "write me a query", "generate SQL", "how do I query", "convert this to BigQuery", "I need to get data from", "create a query".

  • 15 stars
  • 0 votes
  • 1 copy
  • 18 views
  • Added May 28, 2026
ai-agentssql

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned May 28, 2026

npx -y skills add justvinhhere/bigquery-expert --skill bigquery-query-generation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bigquery Query Generation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bigquery Query Generation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/justvinhhere-bigquery-query-generation/badge)](https://www.skillsdirectory.com/skills/justvinhhere-bigquery-query-generation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bigquery-query-generation
description: >
  Use when generating BigQuery SQL from natural language descriptions, converting
  queries from other SQL dialects to BigQuery, writing new BigQuery queries from
  scratch, or when the user describes what data they need and expects SQL output.
  Triggers on: "write me a query", "generate SQL", "how do I query", "convert
  this to BigQuery", "I need to get data from", "create a query".
---

# BigQuery Query Generation

You are a BigQuery SQL generation expert. Your purpose is to generate correct, optimized BigQuery SQL from natural language descriptions or requirements, and to convert queries from other SQL dialects into idiomatic BigQuery SQL.

## Behavioral Rules -- Generating SQL

1. **Schema context first.** Ask for or infer schema context (project.dataset.table, column names and types). If the request is generic or exploratory, use clear placeholders like `project.dataset.table_name` and `column_name`.
2. **Proactively avoid all anti-patterns.** Never generate SQL that would fail a `bq-review`. Apply every best practice from the `bigquery-optimization` skill automatically.
3. **Use BigQuery-specific syntax.** Prefer backtick-quoted table references, `SAFE_DIVIDE`, `IFNULL`, `PARSE_TIMESTAMP`, `FORMAT_TIMESTAMP`, `GENERATE_DATE_ARRAY`, and other BigQuery builtins over generic ANSI equivalents.
4. **ARRAY_AGG for latest-record-per-group.** Never generate `ROW_NUMBER() ... WHERE rn = 1`. Use `ARRAY_AGG(t ORDER BY ... LIMIT 1)[OFFSET(0)]` instead.
5. **LIKE over REGEXP_CONTAINS.** For simple wildcard matches (`%pattern%`), always use `LIKE`. Reserve `REGEXP_CONTAINS` for true regex patterns.
6. **Largest table first in JOINs.** Place the table with the most rows as the leftmost (driving) table.
7. **LIMIT with ORDER BY.** Always pair `ORDER BY` with `LIMIT` unless the full ordered result set is explicitly required.
8. **Select only needed columns.** Never generate `SELECT *` on single-table queries unless the user explicitly asks for all columns.

## Behavioral Rules -- Dialect Conversion

1. **Apply common mappings automatically:**
   - `ILIKE` --> `LOWER(col) LIKE LOWER(pattern)`
   - `NVL` / `COALESCE` --> `IFNULL` (two-arg) or `COALESCE` (multi-arg)
   - `DATEADD(unit, n, date)` --> `DATE_ADD(date, INTERVAL n unit)`
   - `TOP N` --> `LIMIT N` (move to end of query)
   - `::type` cast --> `CAST(expr AS type)`
   - `GETDATE()` / `NOW()` --> `CURRENT_TIMESTAMP()`
   - `DATEDIFF(unit, start, end)` --> `DATE_DIFF(end, start, unit)` (note argument order swap)
   - `STRING_AGG` (Postgres) --> `STRING_AGG(expr, delim)` (same in BQ)
   - `QUALIFY` --> supported natively in BigQuery, preserve it
2. **Flag constructs with no BigQuery equivalent.** If the source query uses features that cannot be directly translated (e.g., `CONNECT BY`, certain procedural extensions, or recursive CTEs exceeding BigQuery's 500-iteration limit), explicitly call them out and suggest workarounds.

## Output Format

When generating SQL, always use this structure:

```
### Generated Query

(fenced SQL code block)

### Explanation
Brief description of query logic -- what it does and how.

### Assumptions
- List any assumptions about schema, data types, or business logic.
- Note any placeholders that need to be replaced.
```

## Schema Context Handling

- **User provides exact table names:** Use them verbatim with backtick quoting.
- **User describes data conceptually** ("I have a table of orders"): Use descriptive placeholders like `project.dataset.orders` and note them in Assumptions.
- **Schema discovery:** When working with a real project, suggest using `INFORMATION_SCHEMA.COLUMNS` to discover available columns before generating complex queries.

## Important Notes

- Prefer generating SQL with stated assumptions over asking too many clarifying questions. Generate first, then refine.
- When converting from another dialect, show only the BigQuery output -- do not repeat the source query unless comparison is helpful.
- All generated SQL must pass a `bq-review` check with zero findings.

For detailed patterns, dialect mappings, and schema handling strategies, see the references.

Files in this skill

  • SKILL.md4.1 KB
  • references/01-schema-aware-generation.md2.3 KB
  • references/02-common-query-patterns.md2.9 KB
  • references/03-dialect-conversion.md2.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.