# How to Generate SQL Queries from Natural Language Using PM Skills Marketplace

> Easily generate SQL queries from natural language with the PM Skills Marketplace data-analytics plugin. Convert English questions into optimized SQL for BigQuery PostgreSQL MySQL and Snowflake.

- Repository: [Pawel Huryn/pm-skills](https://github.com/phuryn/pm-skills)
- Tags: how-to-guide
- Published: 2026-07-09

---

**The PM Skills Marketplace data-analytics plugin converts plain English questions into optimized SQL through the `sql-queries` skill and `/write-query` command, supporting multiple dialects including BigQuery, PostgreSQL, MySQL, and Snowflake.**

The PM Skills Marketplace provides a dedicated data-analytics plugin that enables users to generate SQL queries from natural language without writing code manually. This functionality centers on the `sql-queries` skill located in [`pm-data-analytics/skills/sql-queries/SKILL.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/skills/sql-queries/SKILL.md) and the `/write-query` command defined in [`pm-data-analytics/commands/write-query.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/commands/write-query.md), which together handle schema parsing, dialect selection, and query optimization.

## Architecture of the SQL Generation Pipeline

The natural language to SQL conversion follows a modular workflow implemented in the `sql-queries` skill. According to the source code in [`pm-data-analytics/skills/sql-queries/SKILL.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/skills/sql-queries/SKILL.md), the process involves four distinct phases that transform user intent into executable code.

### Schema Discovery and Ingestion

First, the skill analyzes available database schema files to understand table structures, primary keys, foreign keys, and indexes (lines 13-16). If you upload a DDL file or schema documentation, the skill automatically extracts table and column definitions. Without a schema, it requests the database type and applies a generic SaaS data model fallback.

### Intent and Dialect Resolution

Next, the skill parses the natural language request to identify required metrics, dimensions, filters, time ranges, and grouping logic (lines 19-21). It simultaneously confirms the target SQL dialect—whether BigQuery, PostgreSQL, MySQL, Snowflake, or another supported variant—to ensure syntax compatibility.

### Query Construction and Optimization

The generation phase produces optimized SQL featuring Common Table Expressions (CTEs) for readability (line 46), inline comments explaining each step (line 25), and explicit handling of edge cases such as NULL values, timezone conversions, and duplicate rows (line 48).

## Using the `/write-query` Command

The `/write-query` command serves as the front-end interface that orchestrates the user interaction. Defined in [`pm-data-analytics/commands/write-query.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/commands/write-query.md), this slash command accepts natural language input, invokes the `sql-queries` skill, and formats the complete response according to the assembly rules specified in lines 60-68.

Basic usage follows this pattern:

```text
/write-query Show me daily active users for the last 30 days, broken down by plan tier

```

The command returns a structured response containing the dialect tag, list of tables used, and a SQL code block. For example, a BigQuery request produces:

```sql
-- BigQuery dialect
/* Daily active users per plan tier, last 30 days */
WITH recent_events AS (
  SELECT user_id, plan_tier, event_date
  FROM `project.dataset.events`
  WHERE event_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
    AND CURRENT_DATE()
)
SELECT plan_tier,
       COUNT(DISTINCT user_id) AS daily_active_users
FROM recent_events
GROUP BY plan_tier
ORDER BY daily_active_users DESC;

```

The response includes:

- **Dialect** specification (e.g., BigQuery)
- **Tables used** list
- Complete SQL code block
- Human-readable explanation of assumptions
- Performance recommendations

## Schema-Aware Query Generation

When working with specific database schemas, upload your DDL file before requesting queries:

```text
/upload database_schema.sql
/write-query Generate a query to find users who signed up in the last 30 days and had at least 5 active sessions

```

The skill extracts table relationships from the uploaded schema and generates dialect-specific JOINs. For PostgreSQL, this produces CTEs separating signup data from session counts:

```sql
-- PostgreSQL dialect
/* Users with ≥5 sessions in the last 30 days */
WITH signup AS (
  SELECT id, created_at
  FROM users
  WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
),
session_counts AS (
  SELECT user_id, COUNT(*) AS sess_cnt
  FROM sessions
  WHERE timestamp >= CURRENT_DATE - INTERVAL '30 days'
  GROUP BY user_id
)
SELECT u.id, u.email, sc.sess_cnt
FROM signup u
JOIN session_counts sc ON sc.user_id = u.id
WHERE sc.sess_cnt >= 5;

```

## Cross-Dialect Support

The `sql-queries` skill can emit the same logical query in multiple SQL dialects simultaneously. Requesting dialect variants allows you to compare syntax differences between platforms:

```text
/write-query I need the same revenue-by-region query for both BigQuery and MySQL

```

The skill adjusts date functions, quotation styles, and platform-specific optimizations while preserving the core query logic.

## Summary

- The **`sql-queries` skill** in [`pm-data-analytics/skills/sql-queries/SKILL.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/skills/sql-queries/SKILL.md) encodes the complete logic for converting natural language to SQL, including schema parsing and dialect selection (lines 13-21).
- The **`/write-query` command** provides the user interface that invokes the skill and formats responses with SQL blocks, dialect tags, and performance notes (lines 60-68).
- **Schema upload** enables accurate table/column resolution and foreign key relationships for complex JOIN operations.
- **Multi-dialect support** allows simultaneous generation of BigQuery, PostgreSQL, MySQL, Snowflake, and other SQL variants from a single natural language prompt.
- Generated queries include **CTEs for readability**, **inline comments**, and **edge-case handling** for NULLs and timezones.

## Frequently Asked Questions

### How do I generate SQL queries from natural language using PM Skills?

Use the `/write-query` slash command followed by your question in plain English. The command invokes the `sql-queries` skill to parse your intent, analyze any uploaded schema, and return an optimized SQL query with dialect specification and usage notes.

### What SQL dialects does the PM Skills Marketplace support?

The `sql-queries` skill supports major dialects including BigQuery, PostgreSQL, MySQL, and Snowflake. The skill automatically adjusts syntax for date functions, interval operators, and platform-specific optimizations based on the dialect specified or inferred from your schema.

### Can I use my existing database schema with the SQL generator?

Yes. Upload your schema file using `/upload database_schema.sql` before running `/write-query`. The skill reads table definitions, primary keys, foreign keys, and indexes from the uploaded DDL to generate accurate queries with proper JOIN conditions and column references.

### Does the generated SQL include performance optimizations?

The skill generates queries using CTEs for readability and includes comments explaining each step. For large tables, the response includes performance notes recommending specific indexes—such as indexing `event_date` columns for time-range queries—though the generated code focuses on correctness and clarity over radical optimization.