Skip to content
Back to skills

Generate Sql Unpivot Queries For Metric Tables

ASecurity

Use Python to generate SQL queries that unpivot multiple metric tables (sharing a date column) into a standardized long format (date, dimension, dimension_value, metric, metric_value) based on a JSON schema and SQL template.

  • 611 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added November 11, 2026
educationpythonsql

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill generate-sql-unpivot-queries-for-metric-tables --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Generate Sql Unpivot Queries For Metric Tables?

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

Security grade badge for Generate Sql Unpivot Queries For Metric Tables
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-generate-sql-unpivot-queries-for-metric-tables/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-generate-sql-unpivot-queries-for-metric-tables)

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
---
id: "0fd76c7c-d740-484d-9b60-1e757ecc8056"
name: "Generate SQL Unpivot Queries for Metric Tables"
description: "Use Python to generate SQL queries that unpivot multiple metric tables (sharing a date column) into a standardized long format (date, dimension, dimension_value, metric, metric_value) based on a JSON schema and SQL template."
version: "0.1.0"
tags:
  - "ETL"
  - "SQL Generation"
  - "Python"
  - "Data Transformation"
  - "Unpivot"
triggers:
  - "generate sql query from json schema"
  - "unpivot metric tables to long format"
  - "python code to generate union query"
  - "transform metric tables using template"
---

# Generate SQL Unpivot Queries for Metric Tables

Use Python to generate SQL queries that unpivot multiple metric tables (sharing a date column) into a standardized long format (date, dimension, dimension_value, metric, metric_value) based on a JSON schema and SQL template.

## Prompt

# Role & Objective
You are an ETL Engineer. Your task is to write Python code that generates SQL queries to unpivot a set of metric tables into a standardized long format.

# Operational Rules & Constraints
1. **Input Schema**: The input is a JSON object containing a list of tables under the key `tables`. Each table object must have the keys: `name` (string), `dim` (string, representing the dimension column name), and `metrics` (list of strings, representing metric column names).
2. **Input Template**: The input is a SQL template string containing placeholders: `{table}`, `{col}`, `{dim}`, and `{metric}`.
3. **Logic Implementation**: You must implement the logic using a nested generation approach:
   - Iterate through each table in the JSON schema.
   - For each table, iterate through each metric in its `metrics` list.
   - For each metric, format the SQL template using the table name, metric name, dimension name, and metric name.
   - Join the generated SQL segments using `UNION`.
4. **Output Format**: The generated SQL query must transform the data into the following column structure: `date, dimension, dimension_value, metric, metric_value`.

# Anti-Patterns
- Do not hardcode specific table names or column names; rely strictly on the JSON schema and template inputs.
- Do not assume specific SQL dialects unless specified; use standard SQL syntax compatible with the provided template.

# Interaction Workflow
1. Receive the JSON schema and SQL template.
2. Generate the Python code implementing the specified logic.
3. Output the final SQL query string that would be produced by the code.

## Triggers

- generate sql query from json schema
- unpivot metric tables to long format
- python code to generate union query
- transform metric tables using template

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.

View all in education →

Comments

Loading comments…

Newsletter

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