diff --git a/.env.example b/.env.example index bddf32c..c511812 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,10 @@ GOOGLE_API_KEY=your_main_google_api_key_here # Get your API key from: https://console.mistral.ai/ MISTRAL_API_KEY=your_mistral_api_key_here +# NVIDIA API Key +# Get your API key from: https://developer.nvidia.com/ai-enterprise +NVIDIA_API_KEY=your_nvidia_api_key_here + # Name of the database to connect to when launching the web UI DATABASE=name_of_your_database_here diff --git a/.gitignore b/.gitignore index 555ca20..36a3372 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ benchmark/logs/ benchmark/data/ requirements.txt environment.yml -CLAUDE.md \ No newline at end of file +src/db_confirmed_fixes/chroma/ \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index fa15ea3..1ab3561 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -22,52 +22,50 @@ This project uses [uv](https://github.com/astral-sh/uv) for fast, reliable Pytho uv sync ``` -2. **Set up LogFire (optional, for logging and monitoring):** +2. **Configure API keys:** + ```bash + cp .env.example .env + ``` + Edit `.env` and add your keys: + - `MISTRAL_API_KEY` — primary model (Mistral Large) + - `GOOGLE_API_KEY` — optional (Gemini Flash) + - `DATABASE` — PostgreSQL database name for the web UI + - `LOGFIRE_TOKEN` — optional, for observability + +3. **Set up LogFire (optional):** ```bash uv run logfire auth uv run logfire projects new ``` - Then uncomment LogFire configuration in [src/agent/sqlagent.py](src/agent/sqlagent.py) - -3. **Configure Google API Key:** - - Visit [Google AI Studio](https://aistudio.google.com/apikey) - - Create a new API key - - Copy `.env.example` to `.env`: - ```bash - cp .env.example .env - ``` - - Add your API key to `.env`: - ``` - GOOGLE_API_KEY=your_actual_api_key_here - ``` + LogFire is already configured in [src/agent/sqlagent.py](src/agent/sqlagent.py) via `logfire.configure(send_to_logfire="if-token-present")`. ### Running the Application +The web interface requires a running PostgreSQL instance (see Docker section below). + ```bash -# Run the web interface (main application) +# Run the web interface — connects to DATABASE from .env (default: "postgres") uv run python sequel2sql.py -``` - -Then open http://localhost:8000 in your browser to access the chat interface. -```bash -# Run the agent pipeline directly with test cases -uv run python src/agent/sqlagent.py +# Use a different database without editing .env +DATABASE=california_schools_template uv run python sequel2sql.py ``` +Open http://localhost:8000 for the chat interface. + ### Testing ```bash # Run all tests uv run pytest -# Run specific test file +# Run a specific test file uv run pytest tests/test_validator.py -# Run tests with verbose output +# Verbose output uv run pytest -v -# Run tests and inspect ChromaDB +# Inspect ChromaDB contents uv run python tests/inspect_chroma_db.py ``` @@ -79,43 +77,41 @@ Run the BIRD-CRITIC PostgreSQL benchmark (530 queries): # Interactive mode (recommended for first-time users) ./benchmark.sh -# Command-line mode - test with limited queries +# Command-line mode — limit to N queries, optionally choose provider ./benchmark.sh --limit 20 +./benchmark.sh --limit 20 --provider mistral -# Run full benchmark +# Full benchmark ./benchmark.sh ``` -See [benchmark/README.md](benchmark/README.md) for detailed setup instructions, data downloads, and configuration. +Available `--provider` options: `mistral`, `google`, `sequel2sql` (uses the agentic pipeline directly). + +See [benchmark/README.md](benchmark/README.md) for data download and setup details. -### Docker Setup for Testing +### Docker (PostgreSQL for development/web UI) + +All Docker configuration lives in `benchmark/docker-compose.yml` — there is no separate `docker/` directory. ```bash -# Start PostgreSQL container -docker compose -f docker/docker-compose.yml up -d postgres +# Start containers (PostgreSQL + evaluation container) +docker compose -f benchmark/docker-compose.yml up -d -# Check container status -docker compose -f docker/docker-compose.yml ps +# Check status +docker compose -f benchmark/docker-compose.yml ps -# Test PostgreSQL connection -docker compose -f docker/docker-compose.yml exec postgres psql -U root -d postgres -c "SELECT 1, version();" +# Test connection +docker compose -f benchmark/docker-compose.yml exec postgresql psql -U root -d postgres -c "SELECT 1, version();" -# Stop containers -docker compose -f docker/docker-compose.yml down +# Stop +docker compose -f benchmark/docker-compose.yml down ``` -See [docker/README.md](docker/README.md) for engine versions and connection strings. - ### Managing Dependencies ```bash -# Add a new dependency uv add - -# Add a development dependency uv add --dev - -# Update dependencies uv sync ``` @@ -123,75 +119,93 @@ uv sync ### System Overview -Sequel2SQL uses a **deterministic orchestration pipeline** that combines AST-based validation, semantic retrieval, and LLM reasoning to fix SQL queries. The workflow (see [assets/flowchart.jpg](assets/flowchart.jpg)): +Sequel2SQL uses an **agentic pipeline** combining AST-based validation, semantic retrieval, and LLM reasoning. The core flow for fixing a SQL query: -1. **Syntax Validation** - Parse query through AST validator to detect syntax/schema errors -2. **Syntax Fixing** - If errors found, use syntax fixer agent (up to 3 retries) -3. **Semantic Retrieval** - Embed query and retrieve top 6 similar examples from ChromaDB -4. **LLM Reasoning** - Main agent generates corrected query with few-shot context -5. **Validation** - Return corrected query with explanation +1. **Schema Discovery** — retrieve relevant table schemas from the live database +2. **Validation** — AST-based syntax and schema error detection via sqlglot +3. **Semantic Retrieval** — embed query intent and fetch top-6 similar examples from ChromaDB +4. **LLM Reasoning** — agent generates corrected query using schema, errors, and few-shot examples +5. **Execution** — optionally run corrected query to verify ### Core Components **Agent Layer** ([src/agent/](src/agent/)): -- **sqlagent.py**: Main orchestration pipeline with two Pydantic AI agents: - - `agent`: Main SQL assistant using `gemini-3-flash-preview` - - `syntax_fixer_agent`: Dedicated syntax error fixer -- **prompts/db_agent_prompt.py**: System prompts for agents -- Tools: `validate_query()` and `similar_examples_tool()` available to main agent +- **sqlagent.py**: Defines three Pydantic AI agents and their registered tools: + - `agent`: Benchmark/default agent (`mistral:mistral-large-latest`, uses `BENCHMARK_PROMPT`) + - `webui_agent`: Interactive chat agent (`mistral:mistral-large-latest`, uses `WEBUI_PROMPT`). This is what `sequel2sql.py` exposes via `webui_agent.to_web()`. + - `syntax_fixer_agent`: Dedicated syntax-only fixer (returns raw SQL string, no explanation) + - `DEFAULT_MODEL = "mistral:mistral-large-latest"` — change here to switch models globally +- **prompts/base_prompt.py**: Core identity, constraints, and tool catalog shared by all agents +- **prompts/benchmark_prompt.py**: Batch/benchmark-mode prompt extension +- **prompts/webui_prompt.py**: Interactive chat prompt extension with routing logic + +**Tools registered on `agent` and `webui_agent`:** +- `analyze_and_fix_sql` — orchestrates schema fetch + validation + few-shot retrieval in one call +- `describe_database_schema` — returns DDL-like schema for specified tables +- `execute_sql_query` — runs SELECT queries against the live database +- `validate_query` — plain validation without database context +- `similar_examples_tool` / `find_similar_examples` — semantic search over ChromaDB **AST Parser & Validation** ([src/ast_parsers/](src/ast_parsers/)): -- **validator.py**: SQL syntax and schema validation using sqlglot -- **query_analyzer.py**: AST-based query analysis for structural patterns -- **llm_tool.py**: Simplified validation interface for agent tool calls -- **error_codes.py**, **error_context.py**: Structured error handling with canonical tags -- **models.py**: Pydantic models for validation results +- **validator.py**: SQL syntax and schema validation using sqlglot; detects silent fixes +- **query_analyzer.py**: AST-based structural analysis (joins, aggregations, subqueries, etc.) +- **llm_tool.py**: `validate_sql()` — the validation interface called by agent tools +- **error_codes.py**, **error_context.py**: Structured error taxonomy with canonical tags (e.g., `SYNTAX_ERROR`, `SCHEMA_ERROR`) +- **models.py**: Pydantic models for `ValidationResult`, `ValidationErrorOut` + +**Database Layer** ([src/database/](src/database/)): +- **database.py**: `Database` class — SQLAlchemy-based, PostgreSQL-only, reflects schema on init, limits queries to SELECT only (caps at 100 rows) +- **deps.py**: `AgentDeps` dataclass — dependency injection container for agent tools +- **tools.py**: `execute_sql()` tool function; blocks system catalog queries and routes through `AgentDeps` +- **format_schema.py**: Formats reflected SQLAlchemy metadata into human-readable DDL text **Vector Database RAG** ([src/query_intent_vectorDB/](src/query_intent_vectorDB/)): -- **search_similar_query.py**: Semantic search over training examples using ChromaDB -- **embed_query_intent.py**: Query embedding using sentence-transformers -- **process_query_intent.py**: AST-based query intent extraction -- Uses `all-MiniLM-L6-v2` for embeddings, stored in [src/chroma_db/](src/chroma_db/) +- **search_similar_query.py**: `find_similar_examples()` — semantic search returning `FewShotExample` objects +- **embed_query_intent.py**: Embedding logic using `all-MiniLM-L6-v2` +- **process_query_intent.py**: AST-based query intent extraction for indexing +- ChromaDB collection `query_intents` persisted in [src/chroma_db/](src/chroma_db/) **Entry Points:** -- **sequel2sql.py**: Web interface via `agent.to_web()` (http://localhost:8000) -- **src/agent/sqlagent.py**: Direct pipeline execution with test cases +- **sequel2sql.py**: Launches web UI via `webui_agent.to_web(deps=...)` on port 8000 +- **benchmark/main.py**: Benchmark orchestrator (called by `benchmark.sh`); 5-phase pipeline: prompt generation → LLM inference → post-processing → Docker eval → results **Benchmarking** ([benchmark/](benchmark/)): -- BIRD-CRITIC PostgreSQL benchmark runner (530 queries) -- Smart API key rotation, checkpointing, Docker-based evaluation -- See [benchmark/README.md](benchmark/README.md) for details +- **main.py**: Main entry point; interactive or `--limit N --provider PROVIDER` CLI mode +- **src/config.py**: Provider configs (mistral, google, sequel2sql), API key loading +- **src/inference_engine.py**: Sequential query processing with checkpointing +- **src/sequel2sql_client.py**: Calls the local `webui_agent` pipeline instead of an external API +- **src/checkpoint_manager.py**: Saves/resumes benchmark runs; outputs in `benchmark/outputs/run_/` ### Key Dependencies -- **pydantic-ai**: Agent framework and LLM orchestration -- **google-genai**: Gemini API access (`gemini-3-flash-preview` model) +- **pydantic-ai**: Agent framework, tool registration, `RunContext`, `ModelRetry` +- **mistralai** / **google-genai**: LLM backends - **chromadb**: Vector database for semantic search -- **sentence-transformers**: Query embedding (`all-MiniLM-L6-v2`) -- **sqlglot**: SQL parsing and AST analysis -- **logfire**: Optional observability and monitoring +- **sentence-transformers**: `all-MiniLM-L6-v2` embedding model +- **sqlglot**: SQL parsing, AST analysis, dialect-aware validation +- **sqlalchemy**: Database connectivity and schema reflection +- **logfire**: Optional observability (`send_to_logfire="if-token-present"`) - **uvicorn**: ASGI server for web interface ### Important Implementation Details -**Pipeline Execution Flow** ([src/agent/sqlagent.py](src/agent/sqlagent.py)): -- `run_pipeline()` is the main async orchestration function -- Validation happens deterministically BEFORE agent calls (not as agent tool) -- Syntax fixing uses a separate agent with up to 3 retries -- Few-shot examples retrieved using AST-based semantic search -- Final agent call includes: query intent, validated SQL, and similar examples +**Database Connection** ([src/agent/sqlagent.py](src/agent/sqlagent.py)): +- `get_database_deps(database_name, ...)` creates an `AgentDeps` with a `Database` instance +- Default connection: `localhost:5534`, user `root`, password `123123` +- `Database.__init__` defaults to port 5432; `get_database_deps` overrides to 5534 for Docker **Validation Strategy**: -- Schema files stored in [benchmark/data/schemas/](benchmark/data/schemas/) as JSON -- Validation uses sqlglot parser with PostgreSQL dialect -- Returns structured errors with canonical tags (e.g., `SYNTAX_ERROR`, `SCHEMA_ERROR`) -- See [src/ast_parsers/llm_tool.py](src/ast_parsers/llm_tool.py) for validation interface +- `validate_sql(sql, db_name, dialect)` in [src/ast_parsers/llm_tool.py](src/ast_parsers/llm_tool.py) is the agent-facing interface +- Schema context is loaded from the live database via SQLAlchemy reflection (not from static JSON schema files) +- Validation catches both hard parse errors and "silent fixes" (sqlglot auto-corrects without raising) **Vector Database**: - ChromaDB collection: `query_intents` -- Documents indexed by AST-based query structure, not just raw SQL text -- Semantic search uses query intent + structural similarity -- Database persisted in [src/chroma_db/](src/chroma_db/) +- Documents indexed by AST-extracted query intent, not raw SQL +- `find_similar_examples(query, n_results=6)` returns structurally diverse examples with diversity filtering to prevent near-duplicate results + +**Module Import Note**: +- The directory is `src/query_intent_vectorDB/` (uppercase DB) but Python imports use `src.query_intent_vectordb` (lowercase). This works silently on macOS (case-insensitive filesystem) but may fail on Linux. ## Code Style Guidelines @@ -202,12 +216,11 @@ From [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md): - **Braces**: Opening braces on next line for class/method declarations - **Spacing**: One space between operators and operands - **Variable naming**: Descriptive names (avoid single-letter variables like `a` or `x`) -- **Commits**: Must be atomic - one logical change per commit -- **Testing**: Add tests for any new functionality +- **Commits**: Must be atomic — one logical change per commit ## Project-Specific Notes -- This project focuses on PostgreSQL specifically, not general SQL -- The goal is error correction and optimization, not initial query generation -- RAG context includes database schemas, official PostgreSQL docs, and past corrections -- Agent-based approach means queries go through multi-step reasoning, not single-shot generation +- PostgreSQL-only — not intended for other SQL dialects +- The goal is error correction, not initial query generation (NL2SQL) +- Only SELECT queries are permitted; INSERT/UPDATE/DELETE/DDL are blocked at the tool layer +- `benchmark/agent/` directory exists but is currently empty (the pipeline is in `benchmark/main.py` + `benchmark/src/`) diff --git a/benchmark.sh b/benchmark.sh index 173234d..cb57c37 100755 --- a/benchmark.sh +++ b/benchmark.sh @@ -108,8 +108,9 @@ echo -e "${GREEN}✓${NC} Database dumps found" # Show available models echo "" echo -e "${CYAN}Available models:${NC}" -echo -e " -- Google Gemma 3 27B (requires GOOGLE_API_KEY in .env)" +echo -e " -- Gemini 3 Flash Preview (requires GOOGLE_API_KEY in .env)" echo -e " -- Mistral Large Latest (requires MISTRAL_API_KEY in .env)" +echo -e " -- NVIDIA (requires NVIDIA_API_KEY in .env)" echo -e " -- Sequel2SQL Pipeline (requires MISTRAL_API_KEY in .env)" echo "" echo -e "${CYAN}Starting benchmark...${NC}" diff --git a/benchmark/README.md b/benchmark/README.md index 7ccedab..ddeab32 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -1,6 +1,6 @@ # SEQUEL2SQL Benchmark -A clean, user-friendly console application for running the BIRD-CRITIC PostgreSQL benchmark (530 queries) using Google Gemma 3 27B with intelligent API key rotation and full Docker-based evaluation. +A clean, user-friendly console application for running the BIRD-CRITIC PostgreSQL benchmark (530 queries) using various models and full Docker-based evaluation. This benchmark tool was built with a lot of code being reused from the [BIRD-CRITIC-1](https://github.com/bird-bench/BIRD-CRITIC-1) repository. You can refer to it for more details on the benchmark dataset and evaluation methodology along with data sources. @@ -126,7 +126,7 @@ All configuration is in [src/config.py](src/config.py): ```python MODEL_CONFIG = { - "model_name": "models/gemma-3-27b-it", + "model_name": "models/google-gla:gemini-3-flash-preview", "timeout": 10, "max_threads": 8, "checkpoint_frequency": 10 diff --git a/benchmark/docker-compose.yml b/benchmark/docker-compose.yml index 4828af9..6b925a7 100644 --- a/benchmark/docker-compose.yml +++ b/benchmark/docker-compose.yml @@ -19,7 +19,7 @@ services: - "-c" - "shared_buffers=256MB" ports: - - "5433:5432" + - "5534:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U root"] interval: 10s diff --git a/benchmark/main.py b/benchmark/main.py index 0d905f4..77ad010 100644 --- a/benchmark/main.py +++ b/benchmark/main.py @@ -41,6 +41,8 @@ from src.sequel2sql_client import Sequel2SQLClient from src.ui import ( ask_provider, + ask_select_only_size, + ask_single_query_number, ask_subset_size, confirm_delete, confirm_start, @@ -260,6 +262,8 @@ def main(): # ========== Main Menu Loop ========== query_limit = args.limit # From command line + query_index = None # For single-query mode (0-based) + select_only = False # For SELECT-only mode output_dir = None checkpoint_manager = None resume_mode = False @@ -298,6 +302,13 @@ def main(): logger.info(f"Output directory: {output_dir}") checkpoint_manager = CheckpointManager(output_dir) + checkpoint_manager.set_run_config( + provider=provider if cli_provider is not None else selected_provider, + model_id=model_config["model_id"], + model_name=model_config["display_name"], + pipeline_type="subset", + query_limit=total_queries, + ) logger.info("Starting new run...") else: # Interactive menu @@ -341,6 +352,13 @@ def main(): logger.info(f"Output directory: {output_dir}") checkpoint_manager = CheckpointManager(output_dir) + checkpoint_manager.set_run_config( + provider=selected_provider, + model_id=model_config["model_id"], + model_name=model_config["display_name"], + pipeline_type="full", + query_limit=None, + ) resume_mode = False logger.info("Starting new complete run...") break @@ -380,10 +398,134 @@ def main(): logger.info(f"Output directory: {output_dir}") checkpoint_manager = CheckpointManager(output_dir) + checkpoint_manager.set_run_config( + provider=selected_provider, + model_id=model_config["model_id"], + model_name=model_config["display_name"], + pipeline_type="subset", + query_limit=total_queries, + ) resume_mode = False logger.info("Starting new subset run...") break + elif action == "select_only": + # Ask which model to use + selected_provider = ask_provider(PROVIDERS) + if selected_provider is None: + continue + try: + validate_config(selected_provider) + model_config = get_model_config(selected_provider) + except SystemExit: + continue + + # Count available SELECT queries so we can validate the limit + import json as _json + + with open(data_file, "r") as _f: + _all_data = [_json.loads(line) for line in _f] + _select_count = sum( + 1 + for d in _all_data + if d.get("issue_sql", [""]) + and d["issue_sql"][0].strip().upper().startswith("SELECT") + ) + + query_limit = ask_select_only_size(_select_count) + if query_limit is None: + continue + + select_only = True + + timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + logger = setup_logger(timestamp) + logger.info("=" * 70) + logger.info("SEQUEL2SQL Benchmark Starting - SELECT-ONLY RUN") + logger.info("=" * 70) + + total_queries = query_limit + logger.info( + f"Running SELECT-ONLY MODE with {total_queries} queries " + f"(from {_select_count} available SELECT queries)" + ) + + display_config_summary(model_config, total_queries) + + if not confirm_start(): + select_only = False + query_limit = None + continue + + output_dir = get_outputs_dir() / f"run_{timestamp}" + output_dir.mkdir(parents=True, exist_ok=True) + logger.info(f"Output directory: {output_dir}") + + checkpoint_manager = CheckpointManager(output_dir) + checkpoint_manager.set_run_config( + provider=selected_provider, + model_id=model_config["model_id"], + model_name=model_config["display_name"], + pipeline_type="select_only", + query_limit=total_queries, + ) + resume_mode = False + logger.info("Starting new SELECT-only run...") + break + + elif action == "single": + # Pick a specific query by 1-based number + selected_provider = ask_provider(PROVIDERS) + if selected_provider is None: + continue + try: + validate_config(selected_provider) + model_config = get_model_config(selected_provider) + except SystemExit: + continue + + query_number = ask_single_query_number() + if query_number is None: + continue + + # Convert to 0-based index + query_index = query_number - 1 + + timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + logger = setup_logger(timestamp) + logger.info("=" * 70) + logger.info( + f"SEQUEL2SQL Benchmark Starting - SINGLE QUERY #{query_number}" + ) + logger.info("=" * 70) + + total_queries = 1 + query_limit = 1 + logger.info( + f"Running SINGLE QUERY mode: query #{query_number} (index {query_index})" + ) + + display_config_summary(model_config, total_queries) + + if not confirm_start(): + continue + + output_dir = get_outputs_dir() / f"run_{timestamp}" + output_dir.mkdir(parents=True, exist_ok=True) + logger.info(f"Output directory: {output_dir}") + + checkpoint_manager = CheckpointManager(output_dir) + checkpoint_manager.set_run_config( + provider=selected_provider, + model_id=model_config["model_id"], + model_name=model_config["display_name"], + pipeline_type="single", + query_limit=1, + ) + resume_mode = False + logger.info(f"Starting single query run for query #{query_number}...") + break + elif action == "previous": # View previous runs runs = get_previous_runs(get_outputs_dir()) @@ -471,6 +613,8 @@ def main(): prompts_file, schema_field="preprocess_schema", limit=query_limit, + query_index=query_index, + select_only=select_only, ) logger.info(f"✓ Generated {num_generated} prompts") checkpoint_manager.save_checkpoint() diff --git a/benchmark/src/api_client.py b/benchmark/src/api_client.py index cb5c654..3e94cbc 100644 --- a/benchmark/src/api_client.py +++ b/benchmark/src/api_client.py @@ -1,11 +1,14 @@ -"""LLM API client backed by pydantic-ai (Google Gemma 3 27B / Mistral Large)""" +"""LLM API client backed by pydantic-ai (Google Gemini 3 Preview / Mistral Large)""" import os import time -from typing import Any, Dict +from typing import Any, Dict, Union +from openai import AsyncOpenAI from pydantic_ai import Agent from pydantic_ai.models import Model +from pydantic_ai.models.openai import OpenAIChatModel +from pydantic_ai.providers.openai import OpenAIProvider from .logger_config import get_logger @@ -15,8 +18,9 @@ class LLMClient: LLM client backed by pydantic-ai. Supports: - - Google Gemma 3 27B (provider="google") + - Google Gemini 3 Preview (provider="google") - Mistral Large Latest (provider="mistral") + - NVIDIA (provider="nvidia") No key rotation — one API key per provider, retries handled by pydantic-ai. """ @@ -37,7 +41,8 @@ def __init__(self, model_config: Dict[str, Any]): self._configure_env() # Create a simple text agent with no tools - self.agent: Agent[None, str] = Agent(self.model_id) + model: Union[str, OpenAIChatModel] = self._build_model() + self.agent: Agent[None, str] = Agent(model) # Statistics self.total_requests = 0 @@ -48,6 +53,24 @@ def __init__(self, model_config: Dict[str, Any]): f"Initialized LLMClient: {model_config['display_name']} ({self.model_id})" ) + def _build_model(self) -> Union[str, OpenAIChatModel]: + """Build the pydantic-ai model. NVIDIA requires a custom OpenAIChatModel.""" + if self.provider == "nvidia": + nvidia_api_key = os.environ.get("NVIDIA_API_KEY", "") + if not nvidia_api_key: + raise ValueError( + "NVIDIA_API_KEY is not set. Please add it to your .env file." + ) + nvidia_client = AsyncOpenAI( + base_url="https://integrate.api.nvidia.com/v1", + api_key=nvidia_api_key, + ) + return OpenAIChatModel( + self.model_id, + provider=OpenAIProvider(openai_client=nvidia_client), + ) + return self.model_id + def _configure_env(self) -> None: """Ensure the right env var is set for the pydantic-ai provider.""" from pathlib import Path @@ -64,10 +87,14 @@ def _configure_env(self) -> None: os.environ.setdefault("GEMINI_API_KEY", key) elif self.provider == "mistral": # pydantic-ai mistral provider reads MISTRAL_API_KEY - # .env.example has a typo (MISTAL_API_KEY) — support both key = os.getenv("MISTRAL_API_KEY") or os.getenv("MISTAL_API_KEY") if key: os.environ["MISTRAL_API_KEY"] = key + elif self.provider == "nvidia": + # pydantic-ai nvidia provider reads NVIDIA_API_KEY + key = os.getenv("NVIDIA_API_KEY") + if key: + os.environ["NVIDIA_API_KEY"] = key def call_api(self, prompt: str, max_retries: int = 3) -> str: """ @@ -143,7 +170,7 @@ def get_statistics(self) -> Dict[str, Any]: timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") setup_logger(timestamp) - for provider in ["google", "mistral"]: + for provider in ["google", "mistral", "nvidia"]: print(f"\nTesting provider: {provider}") try: config = get_model_config(provider) diff --git a/benchmark/src/checkpoint_manager.py b/benchmark/src/checkpoint_manager.py index f22874b..fa45f7e 100644 --- a/benchmark/src/checkpoint_manager.py +++ b/benchmark/src/checkpoint_manager.py @@ -49,6 +49,13 @@ def _initialize_checkpoint_data(self) -> None: "created_at": datetime.now().isoformat(), "last_updated": datetime.now().isoformat(), "phase": "initialization", + "run_config": { + "provider": None, + "model_id": None, + "model_name": None, + "pipeline_type": None, + "query_limit": None, + }, "total_queries": 0, "completed_queries": 0, "failed_queries": 0, @@ -230,6 +237,33 @@ def is_evaluation_completed(self) -> bool: """Check if evaluation is completed.""" return self.checkpoint_data.get("evaluation_completed", False) + def set_run_config( + self, + provider: str, + model_id: str, + model_name: str, + pipeline_type: str, + query_limit: Optional[int] = None, + ) -> None: + """ + Persist run configuration metadata to the checkpoint. + + Args: + provider: LLM provider key (e.g. "google", "mistral", "sequel2sql") + model_id: Model identifier string (e.g. "mistral:mistral-large-latest") + model_name: Human-readable model display name (e.g. "Mistral Large Latest") + pipeline_type: "full" for the complete benchmark, "subset" for a limited run + query_limit: Number of queries for subset runs; None for a full run + """ + self.checkpoint_data["run_config"] = { + "provider": provider, + "model_id": model_id, + "model_name": model_name, + "pipeline_type": pipeline_type, + "query_limit": query_limit, + } + self.save_checkpoint() + def set_total_queries(self, total: int, save: bool = True) -> None: """Set the total number of queries. diff --git a/benchmark/src/config.py b/benchmark/src/config.py index eb9e739..f26ed91 100644 --- a/benchmark/src/config.py +++ b/benchmark/src/config.py @@ -15,13 +15,21 @@ # Supported providers and their model configs PROVIDERS = { "google": { - "model_id": "google-gla:models/gemma-3-27b-it", - "display_name": "Google Gemma 3 27B", + "model_id": "google-gla:gemini-3-flash-preview", + "display_name": "Google Gemini 3 Flash Preview", }, "mistral": { "model_id": "mistral:mistral-large-latest", "display_name": "Mistral Large Latest", }, + "codestral": { + "model_id": "mistral:codestral-latest", + "display_name": "Codestral Latest", + }, + "nvidia": { + "model_id": "deepseek-ai/deepseek-v3.2", + "display_name": "DeepSeek 3.2", + }, "sequel2sql": { "model_id": "sequel2sql:pipeline", "display_name": "Sequel2SQL Pipeline", @@ -66,6 +74,8 @@ def load_api_key(provider: str) -> str: env_var_map = { "google": "GOOGLE_API_KEY", "mistral": "MISTRAL_API_KEY", + "codestral": "MISTRAL_API_KEY", + "nvidia": "NVIDIA_API_KEY", } env_var = env_var_map.get(provider) diff --git a/benchmark/src/inference_engine.py b/benchmark/src/inference_engine.py index 36d084e..0603955 100644 --- a/benchmark/src/inference_engine.py +++ b/benchmark/src/inference_engine.py @@ -214,6 +214,7 @@ def run_inference( task_id, description=f"Generating SQL Solutions [{model_name}] [green]\u2713{passed}[/green] [red]\u2717{failed}[/red]", ) + time.sleep(2) # brief pause between queries # Final checkpoint save self.checkpoint_manager.save() diff --git a/benchmark/src/prompt_generator.py b/benchmark/src/prompt_generator.py index 9948cc2..836cbd0 100644 --- a/benchmark/src/prompt_generator.py +++ b/benchmark/src/prompt_generator.py @@ -53,11 +53,29 @@ def generate_prompt( return prompt +def _is_select_query(data: Dict[str, Any]) -> bool: + """ + Return True if the first issue_sql in a record starts with SELECT. + + Args: + data: A single dataset record + + Returns: + True if the first issue_sql entry starts with SELECT (case-insensitive) + """ + issue_sqls = data.get("issue_sql", []) + if not issue_sqls: + return False + return issue_sqls[0].strip().upper().startswith("SELECT") + + def generate_prompts_from_file( input_path: Path, output_path: Path, schema_field: str = "preprocess_schema", limit: int = None, + query_index: int = None, + select_only: bool = False, ) -> int: """ Generate prompts from input JSONL file and save to output file. @@ -67,6 +85,8 @@ def generate_prompts_from_file( output_path: Path to output JSONL file for prompts schema_field: Field name containing the schema limit: Optional limit on number of instances to process + query_index: If set, extract only the single 0-based record at this index + select_only: If True, filter to records whose first issue_sql starts with SELECT Returns: Number of prompts generated @@ -78,8 +98,15 @@ def generate_prompts_from_file( with open(input_path, "r", encoding="utf-8") as f: data_list = [json.loads(line) for line in f] - if limit: - data_list = data_list[:limit] + if query_index is not None: + data_list = [data_list[query_index]] + else: + if select_only: + before = len(data_list) + data_list = [d for d in data_list if _is_select_query(d)] + logger.info(f"SELECT-only filter: {len(data_list)}/{before} records kept") + if limit: + data_list = data_list[:limit] logger.info(f"Generating prompts for {len(data_list)} instances...") diff --git a/benchmark/src/sequel2sql_client.py b/benchmark/src/sequel2sql_client.py index f0b226e..15bcc3b 100644 --- a/benchmark/src/sequel2sql_client.py +++ b/benchmark/src/sequel2sql_client.py @@ -11,6 +11,7 @@ extract identically to responses from Google/Mistral. """ +import concurrent.futures import importlib.util import sys import time @@ -18,6 +19,22 @@ from typing import Any, Dict import logfire +import psycopg2 +from pydantic_ai.exceptions import UsageLimitExceeded +from pydantic_ai.usage import UsageLimits + +from .logger_config import get_logger + +# --------------------------------------------------------------------------- +# Benchmark agent limits — prevent runaway tool-calling loops +# --------------------------------------------------------------------------- +BENCHMARK_REQUEST_LIMIT = 10 # max LLM round-trips per query +BENCHMARK_TOOL_CALLS_LIMIT = 10 # max successful tool invocations per query + +# Per-query wall-clock timeout for the agent run (seconds). +# Prevents a single query from hanging the whole benchmark run. +AGENT_RUN_TIMEOUT = 300 # 5 minutes + # I have no idea what any of the below code below means, I did not create this import mess and I am not going to bother trying to fix it. @@ -52,7 +69,45 @@ agent = _sqlagent.agent get_database_deps = _sqlagent.get_database_deps -from .logger_config import get_logger +# invalidate_schema_cache is available now because _PROJECT_ROOT is in sys.path +# from the module loading block above and ast_parsers is already in sys.modules. +from ast_parsers.validator import invalidate_schema_cache # noqa: E402 + +# psycopg2 connection config — same host/port as get_database_deps +_PG_HOST = "localhost" +_PG_PORT = 5534 +_PG_USER = "root" +_PG_PASSWORD = "123123" + + +def _run_psycopg2_statements(db_id: str, statements: list, logger) -> None: + """ + Execute a list of raw SQL statements via a plain psycopg2 connection. + + Using psycopg2 directly (not SQLAlchemy) keeps this completely isolated + from the SQLAlchemy connection pool that Database.__init__ creates during + metadata.reflect(). A pooled connection left open in autobegin state would + hold a relation-level lock and block any subsequent DELETE/DDL. + + Each statement is committed and the connection is closed before returning, + so there are zero open transactions when the agent runs. + """ + conn = psycopg2.connect( + dbname=db_id, + user=_PG_USER, + password=_PG_PASSWORD, + host=_PG_HOST, + port=_PG_PORT, + ) + conn.autocommit = True + try: + with conn.cursor() as cur: + for stmt in statements: + stmt = stmt.strip() + if stmt: + cur.execute(stmt) + finally: + conn.close() class Sequel2SQLClient: @@ -81,7 +136,7 @@ def __init__(self, model_config: Dict[str, Any]): ) def call_api_with_data( - self, task_data: Dict[str, Any], max_retries: int = 3 + self, task_data: Dict[str, Any], max_retries: int = 2 ) -> str: """ Run the Sequel2SQL agent pipeline on a single benchmark task. @@ -100,8 +155,30 @@ def call_api_with_data( """ db_id = task_data.get("db_id", "postgres") query = task_data.get("query", "") + issue_sql_raw = task_data.get("issue_sql", []) + schema = task_data.get("preprocess_schema", "") + preprocess_sql = task_data.get("preprocess_sql", []) + clean_up_sql = task_data.get("clean_up_sql", []) + + # issue_sql is stored as a list of SQL strings in the benchmark data + if isinstance(issue_sql_raw, list): + issue_sql_str = "\n".join(issue_sql_raw) + else: + issue_sql_str = str(issue_sql_raw) + + # Build the user message matching the baseline prompt format, + # including the pre-processed schema from the benchmark data. + user_message = ( + f"# Database Schema:\n{schema}\n\n" + f"# User issue:\n{query}\n\n" + f"# Problematic SQL:\n```sql\n{issue_sql_str}\n```" + ) last_error = None + usage_limits = UsageLimits( + request_limit=BENCHMARK_REQUEST_LIMIT, + tool_calls_limit=BENCHMARK_TOOL_CALLS_LIMIT, + ) with logfire.span( "benchmark.sequel2sql", @@ -115,14 +192,70 @@ def call_api_with_data( # Build database deps for this specific database deps = get_database_deps(db_id) - # Run the full agent pipeline (tools: schema lookup, validation, - # few-shot retrieval, SQL analysis) - result = agent.run_sync(query, deps=deps) + # Run preprocess_sql via psycopg2 — fully independent from + # the SQLAlchemy pool so there are no lock conflicts. + # Then invalidate the validator's per-engine schema cache + # so EXPLAIN sees the post-preprocess table state. + if preprocess_sql: + self.logger.debug( + f"Running {len(preprocess_sql)} preprocess_sql" + f" statement(s) for {db_id}" + ) + _run_psycopg2_statements(db_id, preprocess_sql, self.logger) + invalidate_schema_cache(deps.database.engine) + + try: + # Run the agent pipeline with capped tool usage. + # NOTE: do NOT use the executor as a context manager + # (`with` calls shutdown(wait=True) on exit, which + # blocks until the thread finishes and defeats the + # timeout entirely). Instead create it explicitly and + # call shutdown(wait=False) so a timed-out thread is + # simply abandoned. + executor = concurrent.futures.ThreadPoolExecutor( + max_workers=1, thread_name_prefix="agent_run" + ) + future = executor.submit( + agent.run_sync, + user_message, + deps=deps, + usage_limits=usage_limits, + ) + try: + result = future.result(timeout=AGENT_RUN_TIMEOUT) + except concurrent.futures.TimeoutError: + executor.shutdown(wait=False, cancel_futures=True) + raise TimeoutError( + f"Agent run timed out after " + f"{AGENT_RUN_TIMEOUT}s for db_id={db_id}" + ) + finally: + executor.shutdown(wait=False, cancel_futures=True) + finally: + # Restore DB state via psycopg2 — same reasoning as above. + if clean_up_sql: + try: + _run_psycopg2_statements( + db_id, clean_up_sql, self.logger + ) + except Exception as cleanup_err: + self.logger.warning( + f"clean_up_sql failed (non-fatal): {cleanup_err}" + ) self.successful_requests += 1 span.set_attribute("attempts", attempt) - time.sleep(1) # respect 1 req/sec rate limit - return str(result.output) + time.sleep(2) # respect rate limits + sql_text = result.output.sql.strip() + return f"```sql\n{sql_text}\n```" + + except UsageLimitExceeded as e: + # Agent exhausted its tool-call / request budget. + # This is NOT a transient error — retrying will hit + # the same limit. Treat as a hard failure. + self.logger.warning(f"⚠️ Usage limit exceeded for {db_id}: {e}") + last_error = e + break # skip retries except Exception as e: last_error = e @@ -131,12 +264,16 @@ def call_api_with_data( ) error_str = str(e).lower() + # Exponential backoff: base 2s, doubles each attempt, + # capped at 60s + backoff = min(2**attempt, 60) + if ( "429" in error_str or "rate" in error_str or "quota" in error_str ): - wait = 15 * attempt + wait = min(60 * attempt, 240) self.logger.warning( f"⚠️ Rate limit hit. Waiting {wait}s before retry {attempt}/{max_retries}..." ) @@ -147,21 +284,21 @@ def call_api_with_data( or "server" in error_str ): self.logger.warning( - f"⚠️ Server error. Waiting 5s before retry {attempt}/{max_retries}..." + f"⚠️ Server error. Waiting {backoff}s before retry {attempt}/{max_retries}..." ) - time.sleep(5) + time.sleep(backoff) elif attempt < max_retries: - time.sleep(2) + time.sleep(backoff) self.failed_requests += 1 - span.set_attribute("attempts", max_retries) + span.set_attribute("attempts", attempt) span.set_attribute("error", str(last_error)[:240]) self.logger.error( - f"❌ Pipeline call failed after {max_retries} attempts. " + f"❌ Pipeline call failed after {attempt} attempt(s). " f"Last error: {str(last_error)[:120]}" ) raise RuntimeError( - f"Pipeline call failed after {max_retries} retries: {last_error}" + f"Pipeline call failed after {attempt} attempt(s): {last_error}" ) def get_statistics(self) -> Dict[str, Any]: diff --git a/benchmark/src/ui.py b/benchmark/src/ui.py index 27e026d..b05a2ac 100644 --- a/benchmark/src/ui.py +++ b/benchmark/src/ui.py @@ -110,8 +110,15 @@ def show_main_menu() -> Dict[str, Any]: choice = questionary.select( "What would you like to do?", choices=[ - questionary.Choice("Start a complete run (531 queries)", value="complete"), + questionary.Choice("Start a complete run (530 queries)", value="complete"), questionary.Choice("Start a run on a subset of queries", value="subset"), + questionary.Choice( + "SELECT-only run (filter to SELECT queries only)", + value="select_only", + ), + questionary.Choice( + "Single query eval (pick one query by number)", value="single" + ), questionary.Choice("View previous runs", value="previous"), questionary.Choice("Exit", value="exit"), ], @@ -123,6 +130,37 @@ def show_main_menu() -> Dict[str, Any]: return {"action": choice} +def ask_select_only_size(max_select: int) -> Optional[int]: + """ + Ask how many SELECT-only queries to run. + + Args: + max_select: Total number of SELECT queries available in the dataset + + Returns: + Desired count, or None if cancelled + """ + + def validate_number(text): + if not text.isdigit(): + return "Please enter a valid number" + num = int(text) + if num < 1 or num > max_select: + return f"Please enter a number between 1 and {max_select}" + return True + + answer = questionary.text( + f"How many SELECT queries do you want to run? (1-{max_select})", + default="20", + validate=validate_number, + ).ask() + + if answer is None: + return None + + return int(answer) + + def ask_provider(providers: Dict[str, Any]) -> Optional[str]: """ Ask the user to select an LLM provider/model. @@ -155,8 +193,8 @@ def validate_number(text): if not text.isdigit(): return "Please enter a valid number" num = int(text) - if num < 1 or num > 531: - return "Please enter a number between 1 and 531" + if num < 1 or num > 530: + return "Please enter a number between 1 and 530" return True answer = questionary.text( @@ -169,6 +207,28 @@ def validate_number(text): return int(answer) +def ask_single_query_number() -> Optional[int]: + """Ask the user to pick a single query number (1-530).""" + + def validate_number(text): + if not text.isdigit(): + return "Please enter a valid number" + num = int(text) + if num < 1 or num > 530: + return "Please enter a number between 1 and 530" + return True + + answer = questionary.text( + "Enter query number to evaluate (1-530):", + validate=validate_number, + ).ask() + + if answer is None: + return None + + return int(answer) + + def show_previous_runs_menu(runs: List[Dict[str, Any]]) -> Optional[Dict[str, Any]]: """ Show menu with previous runs. diff --git a/pyproject.toml b/pyproject.toml index 3c54856..5e70a30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ "sentence-transformers>=2.2.2", "chromadb>=1.4.1", "sqlalchemy>=2.0.46", + "pydantic-ai-skills>=0.1.1", ] [project.optional-dependencies] @@ -41,3 +42,8 @@ dev = [ [tool.pytest.ini_options] testpaths = ["tests"] pythonpath = ["src"] + +[dependency-groups] +dev = [ + "pytest>=9.0.2", +] diff --git a/sequel2sql.py b/sequel2sql.py index 061e0d6..10afe0a 100644 --- a/sequel2sql.py +++ b/sequel2sql.py @@ -65,6 +65,7 @@ models={ "Mistral Large Latest": SUPPORTED_MODELS["mistral"], "Google Gemini Flash": SUPPORTED_MODELS["google"], + "NVIDIA": SUPPORTED_MODELS["nvidia"], }, ) diff --git a/setup.py b/setup.py index 847aabd..b8b1faa 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ POSTGRES_CONTAINER = "sequel2sql_postgresql" POSTGRES_USER = "root" POSTGRES_PASSWORD = "123123" -POSTGRES_PORT = 5433 # Use 5433 to avoid conflicts with local PostgreSQL on 5432 +POSTGRES_PORT = 5534 # Use 5534 to avoid conflicts with local PostgreSQL on 5432 (5433 is reserved by Windows in WSL2) # load postgres_db from env if set, otherwise default to "postgres" POSTGRES_DB = dotenv_values(ENV_FILE).get("DATABASE", "postgres") diff --git a/src/agent/prompts/base_prompt.py b/src/agent/prompts/base_prompt.py index 83e100c..eb0e400 100644 --- a/src/agent/prompts/base_prompt.py +++ b/src/agent/prompts/base_prompt.py @@ -12,8 +12,8 @@ # CONSTRAINTS -* Only SELECT queries are allowed. Never run INSERT, UPDATE, DELETE, DROP, - CREATE, ALTER, TRUNCATE, or any other data-modifying statement. +* Never run INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, or any + other data-modifying statement (DDL COMMANDS NOT ALLOWED!). * NEVER query system catalog tables (information_schema, pg_catalog, pg_toast). They are not accessible. Use describe_database_schema instead. * Avoid redundant tool calls. If you already have the data from a previous @@ -36,14 +36,28 @@ validation errors, and similar corrected examples from training data. Use this when a user brings a SQL query that needs fixing. -4. **validate_query(sql, db_id?, dialect?)** — Check SQL syntax and - optionally validate against the database schema. Returns structured - error list. - -5. **find_similar_examples(query, n_results?)** — Semantic search over +4. **find_similar_examples(query, n_results?)** — Semantic search over past query corrections. Returns few-shot examples with similar intent or structure. +6. **get_error_taxonomy_skill(error_category)** — Retrieve a markdown + guide of best-practice approaches for fixing errors of a specific + taxonomy category (e.g. "join_related", "aggregation", "syntax", + "semantic"). Call this BEFORE attempting to reason through a fix + from scratch. The category comes from the taxonomy_category field + of a ValidationErrorOut. + +7. **find_similar_confirmed_fixes_tool(intent, database)** — Search + the database knowledge store for previously confirmed SQL fixes that + are semantically similar to the current query intent. Returns up to 4 + matches with their corrected SQL and explanation. Call this EARLY when + fixing a broken query — it may already have a validated solution. + +8. **save_confirmed_fix_tool(database, intent, corrected_sql, error_sql, + explanation)** — Persist a confirmed successful fix so the system can + learn from it. Call this ONLY after the user explicitly confirms the + fix is correct. Never call it speculatively. + # GUARDRAILS * If a tool call returns no results or an error, do NOT retry the same @@ -51,4 +65,10 @@ different tool, or ask the user for clarification. * Never make more than 3 consecutive tool calls without producing a response to the user. If you are stuck, say so. +* When fixing an error that has a taxonomy_category, call + get_error_taxonomy_skill before reasoning from scratch. +* When fixing a broken query, call find_similar_confirmed_fixes_tool + early to check if a similar fix already exists in the knowledge store. +* Only call save_confirmed_fix_tool after the user has explicitly + confirmed the fix is correct. """ diff --git a/src/agent/prompts/benchmark_prompt.py b/src/agent/prompts/benchmark_prompt.py index 31bd503..4a65a1e 100644 --- a/src/agent/prompts/benchmark_prompt.py +++ b/src/agent/prompts/benchmark_prompt.py @@ -3,41 +3,84 @@ Used during automated evaluation runs. The agent must produce SQL directly without asking clarifying questions or generating conversational filler. + +This prompt is STANDALONE — it does NOT inherit from base_prompt.py. +Only tools registered on the benchmark agent are referenced here. """ -from .base_prompt import BASE_PROMPT +BENCHMARK_PROMPT = """\ +You are Sequel2SQL, a PostgreSQL query-repair agent in automated benchmark mode. + +You receive a database schema, a user issue description, and the problematic SQL. +Your ONLY job: output the corrected PostgreSQL query. Nothing else. + +# TOOL BUDGET — 6 CALLS MAXIMUM + +You must use NO MORE than 6 tool calls for the entire task. +Most fixes need only 2–4 calls. Count every call. +After your 5th tool call, STOP calling tools and immediately output your best SQL. +A reasonable answer is always better than no answer. -BENCHMARK_PROMPT = ( - BASE_PROMPT - + """ -# BENCHMARK MODE +# WORKFLOW (follow in order — NEVER loop back) -You are running in automated benchmark / evaluation mode. Follow these rules strictly: +## Step 1: Gather context (1–2 calls) +- Call `find_similar_confirmed_fixes_tool` with the user's intent and the + database name. If a result closely matches, adapt it — don't reinvent. +- If a semantic-model skill is available for this database (check your + instructions), also call `load_skill('-semantic-model')` to get + business definitions, known join paths, and column gotchas. +- These two calls are independent — make them in parallel when possible. -* NEVER ask clarifying questions — always produce your best corrected SQL immediately. -* Use your tools (schema lookup, validation, few-shot examples) to analyse the query. -* If the request is ambiguous, make reasonable assumptions and proceed. -* Do NOT execute the corrected query — just return the corrected SQL text. -* Do NOT add conversational filler, greetings, sign-offs, or explanations. +## Step 2: Diagnose and write the fix (0 calls — reasoning only) +Using the schema already in the user message, the broken SQL, any retrieved +fixes, and the semantic model: +- Identify the root cause (wrong column/table, bad join, missing GROUP BY, + aggregation error, subquery issue, type mismatch, syntax error, etc.). +- Write the corrected SQL. +- Do NOT call any tools during this step. -# VALIDATION LOOP +## Step 3: Validate once — only if uncertain (0–1 calls) +- Call `validate_query` ONLY if you are genuinely unsure about a table name + or column name after reading the schema. +- NEVER call validate_query more than once. NEVER re-validate after editing. +- Treat results as hints — the validator can produce false positives. + Cross-check against the schema, not just the validator output. -After you have a candidate SQL query, you MUST call **validate_query** on it -before responding. If it returns errors: +## Step 4: Spot-check data — only if ambiguous (0–1 calls) +- Call `execute_sql_query` with a targeted SELECT ONLY if you need to inspect + actual data values to resolve genuine ambiguity (e.g., unclear column + semantics, uncertain filter values). +- NEVER use it to rediscover schema — you already have it. +- NEVER run a query you expect to fail. -1. Re-examine the errors alongside the schema and few-shot context. -2. Produce a revised query and call **validate_query** again. -3. Repeat up to 2 times total. If errors persist after 2 attempts, return - the best query you have — do NOT omit a response. +## Step 5: Output +Return the corrected SQL. Raw SQL only. One statement. Nothing else. -# OUTPUT FORMAT +# TOOLS -Your ENTIRE response must be exactly one fenced SQL block and nothing else: +1. `find_similar_confirmed_fixes_tool(intent, database)` — Past confirmed + fixes for this database. ALWAYS call first. +2. `load_skill(name)` — Load the database-specific semantic model (business + terms, join paths, gotchas). Call only if instructions mention one. +3. `validate_query(sql)` — Syntax/schema validation. Helpful but imperfect. + Use sparingly, at most once. +4. `execute_sql_query(sql)` — Execute a SELECT, return rows. For targeted + data inspection only. +5. `get_error_taxonomy_skill(category)` — Fix strategies for an error + category (e.g., "join_related", "aggregation", "syntax", "semantic"). + Call only for genuinely unfamiliar error patterns. -```sql - -``` +# ABSOLUTE RULES -No text before or after the fence. No explanation. No table results. Just the SQL. +1. NO LOOPS. Never validate → fix → re-validate → re-fix. One pass only. +2. NO SYSTEM CATALOGS. Never query information_schema, pg_catalog, or any + pg_* view. The schema is already in the user message. +3. NO CLARIFYING QUESTIONS. Always produce your best fix. +4. NO DDL EXECUTION. execute_sql_query supports SELECT only. +5. NO CONVERSATIONAL TEXT. Output only the corrected SQL statement. +6. BUDGET DISCIPLINE. If you have used 5 tool calls, stop and output SQL. +7. ADAPT, DON'T COPY. Use confirmed fixes and skills as patterns, not + verbatim templates — the current query has its own context. +8. POSTGRESQL IDIOMS. Use CTEs for layered logic, window functions for + ranking, proper type casts (e.g., ::numeric), standard aggregation. """ -) diff --git a/src/agent/prompts/webui_prompt.py b/src/agent/prompts/webui_prompt.py index b2c4b1f..2ac6bf2 100644 --- a/src/agent/prompts/webui_prompt.py +++ b/src/agent/prompts/webui_prompt.py @@ -8,8 +8,8 @@ from .base_prompt import BASE_PROMPT WEBUI_PROMPT = ( - BASE_PROMPT - + """ + BASE_PROMPT + + """ # INTERACTIVE MODE You are chatting with a user through a web interface. Be helpful and @@ -46,10 +46,31 @@ - Intent: explicit description, or infer from the SQL - If unclear: ask "What should this query do?" 2. Call analyze_and_fix_sql(issue_sql=..., query_intent=...) - 3. Review returned context: schema, validation_errors, similar_examples + The response includes taxonomy_skill_guidance — a markdown guide + of proven fix approaches for the detected error category. Use it + to inform your fix before reasoning from scratch. + 3. Review returned context: schema, validation_errors, similar_examples, + and taxonomy_skill_guidance 4. Optionally sample data: execute_sql_query("SELECT * FROM table LIMIT 5") 5. Produce the corrected query with a clear explanation of what was wrong 6. Optionally execute the corrected query to verify + 7. End your response with EXACTLY this confirmation prompt (do not vary + the wording): + + > If this is the correct and expected answer, reply with + > **"this is correct"** or **"right"** and the fix will be recorded + > for future ease of correction. + + 8. When the user replies with "this is correct", "right", "correct", + "that's right", "yes", "yep", or any clear affirmative confirmation: + - Call `save_confirmed_fix_tool` with: + * `intent`: the user's original natural language request from the start of + this session, taken verbatim — do not paraphrase or summarize it + * `explanation`: 2–4 sentences describing what was broken and what + specifically was changed to fix it — be precise, this gets retrieved later + * All other fields from the current session context + - Do not call this tool speculatively before confirmation. + - Then acknowledge: "Got it — recorded for future reference." ## 4. General SQL Help Trigger: user asks about SQL syntax, PostgreSQL features, best practices @@ -87,5 +108,23 @@ Assistant: (Should have used describe_database_schema instead) + +## Database-Specific Confirmed Fixes + +When fixing SQL queries, you have access to two distinct sources of examples, +and you must treat them differently: + +**General examples** (from the `find_similar_examples` tool): Drawn from a +broad SQL training corpus. Useful for general patterns and SQL structure but +have no knowledge of this database's specific quirks. + +**DB-confirmed fixes**: Fixes confirmed correct by real users on this exact database. +They reflect actual column types, working join paths, and real schema quirks. +Call the `find_similar_confirmed_fixes_tool` if possible to search for these past fixes. +It safely handles cases where the database-specific knowledge base does not exist yet +or is empty, returning an empty list in those cases. When present and relevant, weight +these more heavily than general examples. If a confirmed fix closely matches the +current query's intent, treat its `corrected_sql` as a strong reference point +and its `explanation` as direct guidance. """ ) diff --git a/src/agent/skills_config.py b/src/agent/skills_config.py new file mode 100644 index 0000000..2fd3763 --- /dev/null +++ b/src/agent/skills_config.py @@ -0,0 +1,74 @@ +""" +Skills configuration for the sequel2sql agent. + +Separated from sqlagent.py so it can be imported independently +(e.g., in tests) without pulling in the full agent dependency chain. +""" + +from pathlib import Path + +from pydantic_ai_skills import SkillsToolset + +SKILLS_DIR = Path(__file__).parent.parent / "skills" + +skills_toolset = SkillsToolset(directories=[str(SKILLS_DIR)]) + +# Normalize resource names to use forward slashes (Windows path separator fix). +# pydantic_ai_skills uses str(Path) which produces backslashes on Windows, +# but SKILL.md documents resources with forward slashes. +for _skill in skills_toolset._skills.values(): + if _skill.resources: + for _resource in _skill.resources: + _resource.name = _resource.name.replace("\\", "/") + + +def get_db_skill_instructions(db_identifier: str) -> str: + """ + Return skill instructions filtered to only what's relevant for this database. + + Replaces the previous pattern of calling skills_toolset.get_instructions() + (which listed ALL 11 skills) and then appending get_db_skill_hint(). + This version emits only the error_taxonomy skill and the DB-specific + semantic model, saving ~350-400 tokens of irrelevant context per run. + """ + normalized = db_identifier.replace("_", "-").lower() + db_skill_name = f"{normalized}-semantic-model" + relevant_names = {db_skill_name} + + relevant_skills = { + name: skill + for name, skill in skills_toolset._skills.items() + if name in relevant_names + } + + if not relevant_skills: + return "" + + # Build XML skill list — same format as pydantic_ai_skills._INSTRUCTION_SKILLS_HEADER + skills_list_lines: list[str] = [] + for skill in sorted(relevant_skills.values(), key=lambda s: s.name): + skills_list_lines.append("") + skills_list_lines.append(f"{skill.name}") + skills_list_lines.append(f"{skill.description}") + if skill.uri: + skills_list_lines.append(f"{skill.uri}") + skills_list_lines.append("") + skills_list = "\n".join(skills_list_lines) + + instructions = ( + "You have access to skills containing domain-specific knowledge and " + "capabilities.\n\n" + f"\n{skills_list}\n\n\n" + "Use `load_skill()` to load full skill instructions. " + "Load only what you need, when you need it." + ) + + if db_skill_name in relevant_skills: + instructions += ( + f"\n\n**IMPORTANT**: A semantic model skill is available for " + f"database '{db_identifier}'. Before writing SQL, call " + f"`load_skill('{db_skill_name}')` to load business definitions, " + f"metrics, and known patterns. Prefer the semantic model when available." + ) + + return instructions diff --git a/src/agent/sqlagent.py b/src/agent/sqlagent.py index 3f38efa..8b2eb48 100644 --- a/src/agent/sqlagent.py +++ b/src/agent/sqlagent.py @@ -6,16 +6,23 @@ errors, retrieves few-shot examples, and calls the main agent. """ +import os import sys from pathlib import Path from typing import List, Optional import logfire -import sqlglot from dotenv import load_dotenv -from pydantic import BaseModel +from openai import AsyncOpenAI +from pydantic import BaseModel, Field from pydantic_ai import Agent, RunContext -from sqlglot import exp +from pydantic_ai.models.openai import OpenAIChatModel +from pydantic_ai.providers.openai import OpenAIProvider + +from src.db_confirmed_fixes.retriever import ( + find_similar_confirmed_fixes, + save_confirmed_fix, +) # Add both project root and src/ to sys.path for imports to work project_root = Path(__file__).parent.parent.parent @@ -23,12 +30,16 @@ sys.path.insert(0, str(project_root / "src")) # noqa: E402 - Ignore import order since we need to set up sys.path first +import time + from src.agent.prompts.benchmark_prompt import BENCHMARK_PROMPT # noqa: E402 from src.agent.prompts.webui_prompt import WEBUI_PROMPT # noqa: E402 -from src.ast_parsers.llm_tool import validate_sql # noqa: E402 -from src.ast_parsers.models import ValidationErrorOut # noqa: E402 +from src.ast_parsers import ValidationResult, validate_with_db # noqa: E402 from src.database import AgentDeps, Database, DBQueryResponse # noqa: E402 from src.database import execute_sql as _execute_sql # noqa: E402 +from src.error_taxonomy.generic_skills import ( # noqa: E402 + get_error_taxonomy_skill as _get_taxonomy_skill, +) from src.query_intent_vectordb.search_similar_query import ( # noqa: E402 FewShotExample, find_similar_examples, @@ -44,14 +55,46 @@ SUPPORTED_MODELS = { "mistral": "mistral:mistral-large-latest", "google": "google-gla:gemini-3-flash-preview", + "codestral": "mistral:codestral-latest", + "nvidia": "deepseek-ai/deepseek-v3.2", } -DEFAULT_MODEL = "mistral:mistral-large-latest" + + +def _build_nvidia_model() -> OpenAIChatModel: + """Build an OpenAIChatModel pointed at the NVIDIA NIM API.""" + nvidia_api_key = os.environ.get("NVIDIA_API_KEY", "") + if not nvidia_api_key: + raise ValueError( + "NVIDIA_API_KEY is not set in the environment. " + "Please add it to your .env file." + ) + nvidia_client = AsyncOpenAI( + base_url="https://integrate.api.nvidia.com/v1", + api_key=nvidia_api_key, + ) + return OpenAIChatModel( + "deepseek-ai/deepseek-v3.2", + provider=OpenAIProvider(openai_client=nvidia_client), + ) + + +# Pick DEFAULT_MODEL value from .env, default to Mistral if not set or invalid +DEFAULT_MODEL = os.getenv("DEFAULT_MODEL", "mistral").lower() # Logfire configuration (make sure to set LOGFIRE_TOKEN in .env for logging to work) logfire.configure(send_to_logfire="if-token-present") logfire.instrument_pydantic_ai() +# ============================================================================= +# Skills Configuration +# ============================================================================= + +from src.agent.skills_config import ( # noqa: E402 + get_db_skill_instructions, + skills_toolset, +) + # ============================================================================= # Helper Functions # ============================================================================= @@ -60,7 +103,7 @@ def get_database_deps( database_name: str, host: str = "localhost", - port: int = 5433, + port: int = 5534, user: str = "root", password: str = "123123", max_return_values: int = 200, @@ -70,7 +113,7 @@ def get_database_deps( Args: database_name: Name of the PostgreSQL database to connect to host: PostgreSQL host (default: localhost) - port: PostgreSQL port (default: 5433) + port: PostgreSQL port (default: 5534) user: PostgreSQL username (default: root) password: PostgreSQL password (default: 123123) max_return_values: Maximum number of result values to return (default: 200) @@ -88,23 +131,6 @@ def get_database_deps( return AgentDeps(database=database, max_return_values=max_return_values) -def _extract_table_names(sql: str, dialect: str) -> set[str]: - """ - Best-effort extraction of table names from SQL query using sqlglot. - - Returns empty set if parsing fails. - """ - try: - parsed = sqlglot.parse_one(sql, dialect=dialect) - tables = set() - for table in parsed.find_all(exp.Table): - if table.name: - tables.add(table.name) - return tables - except Exception: - return set() - - # ============================================================================= # Pydantic Models # ============================================================================= @@ -123,7 +149,6 @@ class ValidateQueryToolInput(BaseModel): """Input for the SQL validation tool.""" sql: str - db_id: Optional[str] = None dialect: str = "postgres" @@ -151,6 +176,14 @@ class FewShotExamplesResult(BaseModel): # explanation: str = Field(..., description="Explanation of what was fixed and why") +class BenchmarkOutput(BaseModel): + """Structured output for the benchmark agent — one SQL query, no explanation.""" + + sql: str = Field( + description="The corrected PostgreSQL query. Raw SQL only — no commentary." + ) + + class SchemaDescription(BaseModel): """Database schema information returned by describe_database_schema tool.""" @@ -159,6 +192,14 @@ class SchemaDescription(BaseModel): schema_description: str +class SaveConfirmedFixInput(BaseModel): + database: str + intent: str # the user's original natural language request + corrected_sql: str + error_sql: str + explanation: str # what was wrong and what specifically was changed to fix it + + class SQLAnalysisContext(BaseModel): """Comprehensive context for SQL query fixing (webui_agent tool).""" @@ -169,11 +210,21 @@ class SQLAnalysisContext(BaseModel): # Validation results has_errors: bool - validation_errors: List[dict] # [{tag: "SYNTAX_ERROR", message: "..."}] + # Each dict: {tag, message, taxonomy_category} + validation_errors: List[dict] # Few-shot examples similar_examples: List[dict] # [{sql: "...", intent: "...", explanation: "..."}] + # Taxonomy skill guidance (populated when errors have a known category) + taxonomy_skill_guidance: Optional[str] = None + + db_confirmed_fixes: List[dict] = [] + # Past fixes confirmed correct by real users on this specific database. + # Retrieved from the per-database store in src/db_confirmed_fixes/. + # Weight these more heavily than general examples — they reflect real + # confirmed corrections on this exact schema. + # Metadata query_intent: str dialect: str @@ -187,7 +238,10 @@ class SQLAnalysisContext(BaseModel): agent = Agent( DEFAULT_MODEL, deps_type=AgentDeps, + output_type=BenchmarkOutput, system_prompt=BENCHMARK_PROMPT, + toolsets=[skills_toolset], + model_settings={"parallel_tool_calls": False}, ) # Web UI agent @@ -195,6 +249,7 @@ class SQLAnalysisContext(BaseModel): DEFAULT_MODEL, deps_type=AgentDeps, system_prompt=WEBUI_PROMPT, + toolsets=[skills_toolset], ) SYNTAX_FIXER_PROMPT = ( @@ -213,11 +268,11 @@ class SQLAnalysisContext(BaseModel): # ============================================================================= -# Tool Definitions (kept for future use as agent tools) +# Tool Definitions — registered on benchmark and/or webui agents # ============================================================================= -@agent.tool +@agent.tool() def execute_sql_query(ctx: RunContext[AgentDeps], sql: str) -> DBQueryResponse: """Execute the given SQL SELECT query on the connected database and return the result. @@ -231,49 +286,32 @@ def execute_sql_query(ctx: RunContext[AgentDeps], sql: str) -> DBQueryResponse: return _execute_sql(ctx, sql) -@agent.tool_plain -def validate_query(input: ValidateQueryToolInput) -> List[ValidationErrorOut]: +def validate_query( + ctx: RunContext[AgentDeps], sql: str, dialect: str = "postgres" +) -> ValidationResult: """ - Validate SQL query syntax and optionally check against a database schema. + Validate SQL query syntax and schema against the connected live database. Use this tool to: - Check if a SQL query has valid PostgreSQL syntax - - Detect schema errors like non-existent tables/columns (if schema provided) - - Get metadata about query structure - - Returns validation status, any errors found, and structural metadata. - """ - return validate_sql( - input.sql, - db_name=input.db_id, - dialect=input.dialect, - ) + - Detect schema errors like non-existent tables/columns + - Get metadata about query structure (clauses, complexity, tables referenced) + Reports ALL errors simultaneously: syntax errors, hallucinated tables, + hallucinated columns — even when the SQL is too broken to fully parse. -@agent.tool_plain -def similar_examples_tool( - query: str, - n_results: int = 6, -) -> FewShotExamplesResult: + Returns validation status, all errors found, and structural metadata. """ - Find similar SQL query examples from the training database - using semantic search. - - Use this tool to: - - Find examples of similar queries that were previously corrected - - Get context for how similar errors were fixed - - Retrieve queries with similar intent/structure - - Returns structurally diverse few-shot examples with metadata. - """ - examples = find_similar_examples(query, n_results=n_results) - return FewShotExamplesResult( - examples=examples, - query_intent=query, + return validate_with_db( + sql, + ctx.deps.database.engine, + dialect=dialect, ) -@agent.tool +# ============================================================================= +# analyze_and_fix_sql — webui-only orchestration tool (not registered on benchmark). +# ============================================================================= def analyze_and_fix_sql( ctx: RunContext[AgentDeps], issue_sql: str, @@ -311,26 +349,31 @@ def analyze_and_fix_sql( db_id = database.database_name dialect = "postgres" + # Step 1: Validate SQL against the live database. + # Collects syntax + hallucinated-table + hallucinated-column errors together. + result = validate_with_db(issue_sql, database.engine, dialect=dialect) + + # Step 2: Use table names from the parse result (no re-parse needed) if include_all_tables: schema_description = database.describe_schema() available_tables = database.table_names - else: - # Try to extract referenced tables from the query - # This is best-effort - if parsing fails, fall back to all tables - try: - referenced_tables = _extract_table_names(issue_sql, dialect) - if referenced_tables: - schema_description = database.describe_schema(list(referenced_tables)) - available_tables = list(referenced_tables) - else: - schema_description = database.describe_schema() - available_tables = database.table_names - except Exception: + elif result.query_metadata and result.query_metadata.tables: + referenced_tables = result.query_metadata.tables + # The issue_sql may reference wrong/typo table names (that's the bug + # we're fixing). Only describe tables that actually exist in the DB; + # fall back to the full schema when none of the referenced tables are + # real so the agent can see what IS available. + real_tables = database.table_names + existing_referenced = [t for t in referenced_tables if t in real_tables] + if existing_referenced: + schema_description = database.describe_schema(existing_referenced) + available_tables = real_tables # always show all real tables + else: schema_description = database.describe_schema() - available_tables = database.table_names - - # Step 2: Validate SQL query - validation_errors = validate_sql(issue_sql, db_name=db_id, dialect=dialect) + available_tables = real_tables + else: + schema_description = database.describe_schema() + available_tables = database.table_names # Step 3: Get similar examples examples = find_similar_examples(query_intent, n_results=6) @@ -345,21 +388,51 @@ def analyze_and_fix_sql( for ex in examples ] + # Step 4: Format validation errors and look up taxonomy skill guidance + validation_errors_formatted = [ + { + "tag": err.tag.value, + "message": err.message, + "taxonomy_category": err.taxonomy_category, + } + for err in result.errors + ] + + seen_categories: set[str] = set() + taxonomy_skill_parts: list[str] = [] + for err in result.errors: + cat = err.taxonomy_category + if cat in seen_categories: + continue + seen_categories.add(cat) + guidance = _get_taxonomy_skill(cat) + if not guidance.startswith("No skill file"): + taxonomy_skill_parts.append(guidance) + taxonomy_skill_guidance: Optional[str] = ( + "\n\n---\n\n".join(taxonomy_skill_parts) if taxonomy_skill_parts else None + ) + + db_fixes = find_similar_confirmed_fixes( + intent=query_intent, + database=db_id, + n_results=4, + ) + return SQLAnalysisContext( database_id=db_id, available_tables=available_tables, schema_description=schema_description, - has_errors=(len(validation_errors) > 0), - validation_errors=[ - {"tag": err.tag, "message": err.message} for err in validation_errors - ], + has_errors=bool(result.errors), + validation_errors=validation_errors_formatted, similar_examples=similar_examples_formatted, + taxonomy_skill_guidance=taxonomy_skill_guidance, + db_confirmed_fixes=db_fixes, query_intent=query_intent, dialect=dialect, ) -@agent.tool +# describe_database_schema — webui-only. def describe_database_schema( ctx: RunContext[AgentDeps], table_names: list[str] | None = None, @@ -385,11 +458,108 @@ def describe_database_schema( ) -webui_agent.tool(name="execute_sql_query")(execute_sql_query) -webui_agent.tool_plain(name="validate_query")(validate_query) -webui_agent.tool_plain(name="find_similar_examples")(similar_examples_tool) +# get_error_taxonomy_skill — registered on both agents. +def get_error_taxonomy_skill(error_category: str) -> str: + """ + Look up best-practice approaches for fixing a SQL error of + the given taxonomy category. + + Call this BEFORE attempting to fix any categorized error. + Pass the taxonomy_category from a ValidationErrorOut + (e.g. "join_related", "syntax", "aggregation", "semantic"). + + Returns a markdown guide with core approaches and any + previously learned examples from confirmed past fixes. + """ + return _get_taxonomy_skill(error_category) + + +# save_confirmed_fix_tool — webui-only. +def save_confirmed_fix_tool(input: SaveConfirmedFixInput) -> str: + """ + Persist a user-confirmed SQL fix to the database-specific knowledge store. + + Call this ONLY after the user explicitly confirms the fix is correct. + Confirmation phrases to watch for: "yes that's right", "perfect", "exactly", + "that works", "correct", "looks good", "that's correct", "great", "yeah". + + `intent` should be the user's original natural language request from the + start of this fix session — not a summary, not a paraphrase. Take it + directly from the first substantive user message describing what they wanted + the query to do. + + `explanation` should be 2–4 sentences: what was wrong in the original SQL + and what specific change fixed it. This gets retrieved later as context so + make it precise and useful, not generic. + + `database` comes from ctx.deps.database.database_name. + """ + import json + + result = save_confirmed_fix( + database=input.database, + intent=input.intent, + corrected_sql=input.corrected_sql, + error_sql=input.error_sql, + explanation=input.explanation, + ) + return json.dumps(result) + + +class FindSimilarConfirmedFixesInput(BaseModel): + intent: str + database: str + + +# find_similar_confirmed_fixes_tool — registered on both benchmark and webui agents. +def find_similar_confirmed_fixes_tool(input: FindSimilarConfirmedFixesInput) -> str: + """ + Search for user-confirmed SQL fixes for this specific database based on the query intent. + Call this tool to find previously validated solutions that might apply to the current query. + It returns empty if the database knowledge store is empty or does not exist yet. + """ + import json + + fixes = find_similar_confirmed_fixes( + intent=input.intent, database=input.database, n_results=4 + ) + if not fixes: + return "No confirmed fixes found in the knowledge base." + return json.dumps(fixes) + + +# --- webui agent tools --- +webui_agent.tool(name="execute_sql_query", retries=3)(execute_sql_query) +webui_agent.tool(name="validate_query")(validate_query) webui_agent.tool(name="analyze_and_fix_sql")(analyze_and_fix_sql) webui_agent.tool(name="describe_database_schema")(describe_database_schema) +webui_agent.tool_plain(name="get_error_taxonomy_skill")(get_error_taxonomy_skill) +webui_agent.tool_plain(name="save_confirmed_fix_tool")(save_confirmed_fix_tool) +webui_agent.tool_plain(name="find_similar_confirmed_fixes_tool")( + find_similar_confirmed_fixes_tool +) + +# --- benchmark agent tools --- +agent.tool(name="validate_query")(validate_query) +agent.tool_plain(name="get_error_taxonomy_skill")(get_error_taxonomy_skill) +agent.tool_plain(name="find_similar_confirmed_fixes_tool")( + find_similar_confirmed_fixes_tool +) + + +# ============================================================================= +# Skills Instructions +# ============================================================================= + + +@agent.instructions +async def agent_skills_instructions(ctx: RunContext[AgentDeps]) -> str: + return get_db_skill_instructions(ctx.deps.database.database_name) + + +@webui_agent.instructions +async def webui_skills_instructions(ctx: RunContext[AgentDeps]) -> str: + return get_db_skill_instructions(ctx.deps.database.database_name) # ============================================================================= diff --git a/src/ast_parsers/__init__.py b/src/ast_parsers/__init__.py index 838c0d0..63a7bea 100644 --- a/src/ast_parsers/__init__.py +++ b/src/ast_parsers/__init__.py @@ -1,116 +1,62 @@ # -*- coding: utf-8 -*- -"""SQL validation (syntax + optional schema) and ErrorContext from PostgreSQL err.diag.*.""" +""" +ast_parsers — SQL validation and error taxonomy. -from ast_parsers.models import ( - ValidationInput, - ValidationResultOut, - ValidationErrorOut, - QueryMetadataOut, - TagName, - ALL_TAG_NAMES, - ClauseName, - ALL_CLAUSE_NAMES, -) -from ast_parsers.errors import ( - ValidationResult, - ValidationError, - QueryMetadata, - SyntaxErrorTags, - SchemaErrorTags, - LogicalErrorTags, - JoinErrorTags, - AggregationErrorTags, - FilterErrorTags, - SubqueryErrorTags, - SetOperationErrorTags, - StructuralErrorTags, - Diagnostics, - ErrorContext, - TagWithProvenance, - CONFIDENCE_HIGH, - CONFIDENCE_MEDIUM, - CONFIDENCE_LOW, -) -from ast_parsers.validator import ( - validate_syntax, - validate_schema, - validate_query, -) -from ast_parsers.error_codes import ( +Public API +---------- +Main entry point:: + + from ast_parsers import validate + result = validate(sql) # syntax only + result = validate(sql, schema=my_schema) # syntax + schema + +Result types:: + + from ast_parsers import ValidationResult, ValidationError, QueryMetadata + +Error tags:: + + from ast_parsers import ErrorTag + if ErrorTag.TRAILING_DELIMITER in result.tags: ... + +Utilities:: + + from ast_parsers import extract_error_code, get_taxonomy_category, get_category_for_tag +""" + +from ast_parsers.query_analyzer import analyze_query +from ast_parsers.result import QueryMetadata, ValidationError, ValidationResult +from ast_parsers.tags import ( + ErrorTag, + category_for_sqlstate_with_fallback, extract_error_code, - get_taxonomy_category, - get_taxonomy_category_with_fallback, - get_tags_for_category, - get_category_for_tag, - get_tag_for_sqlstate, - POSTGRES_ERROR_CODE_MAP, - TAXONOMY_CATEGORIES, + tag_for_sqlstate, ) -from ast_parsers.query_analyzer import ( - extract_sql_clauses, - calculate_complexity, - generate_pattern_signature, - analyze_query, - count_query_elements, +from ast_parsers.tags import ( + category_for_sqlstate as get_taxonomy_category, ) -from ast_parsers.error_context import ( - build_error_context, - extract_diagnostics, - localize_position, +from ast_parsers.tags import ( + category_for_tag as get_category_for_tag, ) - -__version__ = "0.1.0" +from ast_parsers.validator import validate, validate_with_db __all__ = [ - # Pydantic models (input / output contracts) - "ValidationInput", - "ValidationResultOut", - "ValidationErrorOut", - "QueryMetadataOut", - "TagName", - "ALL_TAG_NAMES", - "ClauseName", - "ALL_CLAUSE_NAMES", - # Core validation + # ── Main entry points ───────────────────────────────────────────────── + "validate", + "validate_with_db", + # ── Result types ────────────────────────────────────────────────────── "ValidationResult", "ValidationError", "QueryMetadata", - "validate_syntax", - "validate_schema", - "validate_query", - # Error context pipeline - "ErrorContext", - "Diagnostics", - "TagWithProvenance", - "build_error_context", - "extract_diagnostics", - "localize_position", - "CONFIDENCE_HIGH", - "CONFIDENCE_MEDIUM", - "CONFIDENCE_LOW", - # Error tags - "SyntaxErrorTags", - "SchemaErrorTags", - "LogicalErrorTags", - "JoinErrorTags", - "AggregationErrorTags", - "FilterErrorTags", - "SubqueryErrorTags", - "SetOperationErrorTags", - "StructuralErrorTags", - # Error codes + # ── Tags ────────────────────────────────────────────────────────────── + "ErrorTag", + # ── Utilities ───────────────────────────────────────────────────────── "extract_error_code", "get_taxonomy_category", - "get_taxonomy_category_with_fallback", - "get_tags_for_category", "get_category_for_tag", - "get_tag_for_sqlstate", - "POSTGRES_ERROR_CODE_MAP", - "TAXONOMY_CATEGORIES", - # Query analysis - "extract_sql_clauses", - "calculate_complexity", - "generate_pattern_signature", + "category_for_sqlstate_with_fallback", + "tag_for_sqlstate", "analyze_query", - "count_query_elements", + # ── Live DB validation ──────────────────────────────────────────────── + # validate_with_db is also in the main entry points section above ] diff --git a/src/ast_parsers/error_codes.py b/src/ast_parsers/error_codes.py deleted file mode 100644 index 59e5498..0000000 --- a/src/ast_parsers/error_codes.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -"""PostgreSQL SQLSTATE to taxonomy mapping and error code extraction.""" - -import re -import json -import os -from typing import Optional, Dict, List, Any - - -def load_error_data() -> Dict[str, Any]: - """Load error data from JSON file.""" - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, "data", "error_data.json") - try: - with open(data_path, "r", encoding="utf-8") as f: - return json.load(f) - except (FileNotFoundError, json.JSONDecodeError): - # Fallback empty structure if file missing - return { - "postgres_error_code_map": {}, - "taxonomy_categories": {}, - "error_patterns": {}, - "postgres_sqlstate_to_tag": {} - } - - -_ERROR_DATA = load_error_data() - -POSTGRES_ERROR_CODE_MAP: Dict[str, str] = _ERROR_DATA["postgres_error_code_map"] -TAXONOMY_CATEGORIES: Dict[str, List[str]] = _ERROR_DATA["taxonomy_categories"] -ERROR_PATTERNS: Dict[str, str] = _ERROR_DATA["error_patterns"] -POSTGRES_SQLSTATE_TO_TAG: Dict[str, str] = _ERROR_DATA["postgres_sqlstate_to_tag"] - - -# Class fallback when exact SQLSTATE unknown (first two chars). -SQLSTATE_CLASS_FALLBACK: Dict[str, str] = { - "42": "semantic", "22": "semantic", "23": "logical", "28": "semantic", - "2B": "semantic", "2D": "logical", "2F": "semantic", "34": "semantic", - "38": "semantic", "39": "semantic", "3B": "logical", "3D": "semantic", - "3F": "semantic", "40": "logical", "44": "logical", "53": "semantic", - "54": "semantic", "55": "semantic", "57": "semantic", "58": "semantic", - "72": "semantic", "0A": "semantic", "XX": "semantic", "F0": "semantic", - "HV": "semantic", "P0": "semantic", -} - - -def extract_error_code(error_message: str) -> Optional[str]: - """Extract SQLSTATE from message; None if not found.""" - sqlstate_pattern = r'(?:SQLSTATE|ERROR)[\s:]*([0-9][0-9A-Z]{4})|\[([0-9][0-9A-Z]{4})\]' - match = re.search(sqlstate_pattern, error_message, re.IGNORECASE) - if match: - return (match.group(1) or match.group(2)).upper() - - error_lower = error_message.lower() - for pattern, code in ERROR_PATTERNS.items(): - if re.search(pattern, error_lower, re.IGNORECASE): - return code - - return None - - -def get_taxonomy_category(error_code: Optional[str]) -> Optional[str]: - """ - Map PostgreSQL error code to taxonomy category. - - Args: - error_code: PostgreSQL SQLSTATE error code (e.g., "42703", "42P01") - - Returns: - Taxonomy category ("syntax", "semantic", "logical", etc.) or None - """ - if error_code is None: - return None - - return POSTGRES_ERROR_CODE_MAP.get(error_code) - - -def get_tags_for_category(category: Optional[str]) -> List[str]: - """Tags for a taxonomy category; [] if unknown.""" - if category is None: - return [] - - return TAXONOMY_CATEGORIES.get(category, []) - - -def get_taxonomy_category_with_fallback(error_code: Optional[str]) -> Optional[str]: - """Map SQLSTATE to category; use class fallback if exact code unknown.""" - if error_code is None: - return None - specific = POSTGRES_ERROR_CODE_MAP.get(error_code) - if specific is not None: - return specific - if len(error_code) >= 2: - return SQLSTATE_CLASS_FALLBACK.get(error_code[:2]) - return None - - -def get_tag_for_sqlstate(sqlstate: Optional[str]) -> Optional[str]: - """Return single best tag for a SQLSTATE, or None.""" - if sqlstate is None: - return None - return POSTGRES_SQLSTATE_TO_TAG.get(sqlstate) - - -# Build reverse lookup map: Tag -> Category -TAG_TO_CATEGORY: Dict[str, str] = {} -for category, tags in TAXONOMY_CATEGORIES.items(): - for tag in tags: - TAG_TO_CATEGORY[tag] = category - - -def get_category_for_tag(tag: str) -> Optional[str]: - """Taxonomy category for a tag, or None.""" - # 1. Direct lookup - if tag in TAG_TO_CATEGORY: - return TAG_TO_CATEGORY[tag] - - # 2. Pattern matching based on category keys - # Optimization: Check if tag starts with any known category + "_" - for category in TAXONOMY_CATEGORIES: - if tag.startswith(category + "_"): - return category - - return None diff --git a/src/ast_parsers/error_context.py b/src/ast_parsers/error_context.py deleted file mode 100644 index 3ef0446..0000000 --- a/src/ast_parsers/error_context.py +++ /dev/null @@ -1,387 +0,0 @@ -# -*- coding: utf-8 -*- -"""Build ErrorContext from PostgreSQL error (err.diag.*). Supports psycopg2/3, asyncpg, pglast.""" - -import re -from typing import Optional, List, Any - -from ast_parsers.errors import ( - Diagnostics, - ErrorContext, - TagWithProvenance, - CONFIDENCE_HIGH, - CONFIDENCE_MEDIUM, - CONFIDENCE_LOW, - SOURCE_PG_DIAG_COLUMN_NAME, - SOURCE_PG_DIAG_TABLE_NAME, - SOURCE_PG_DIAG_CONSTRAINT_NAME, - SOURCE_PG_DIAG_DATATYPE_NAME, - SOURCE_PG_DIAG_SCHEMA_NAME, - SOURCE_PG_DIAG_POSITION, - SOURCE_SQLSTATE, - SOURCE_REGEX, - SOURCE_AST_HEURISTIC, - SchemaErrorTags, - LogicalErrorTags, - JoinErrorTags, - AggregationErrorTags, - FilterErrorTags, - SyntaxErrorTags, -) -from ast_parsers.error_codes import ( - extract_error_code, - get_taxonomy_category_with_fallback, - get_tag_for_sqlstate, - get_tags_for_category, -) - - -def extract_diagnostics(exception: Any) -> Diagnostics: - """err.diag.*-style fields from exception; missing fields None.""" - message_primary = getattr(exception, "pgerror", None) or getattr(exception, "message", None) if exception else None - if message_primary is None and exception is not None: - message_primary = str(exception) - message_detail = message_hint = context = None - position = schema_name = table_name = column_name = datatype_name = constraint_name = None - internal_query = internal_position = None - - if exception is None: - return Diagnostics(message_primary=message_primary) - - inner = getattr(exception, "diag", None) - if inner is not None: - message_primary = _get_attr(inner, "message_primary") or message_primary - message_detail = _get_attr(inner, "message_detail") - message_hint = _get_attr(inner, "message_hint") - context = _get_attr(inner, "context") - position = _get_attr(inner, "statement_position") or _get_attr(inner, "position") - schema_name = _get_attr(inner, "schema_name") - table_name = _get_attr(inner, "table_name") - column_name = _get_attr(inner, "column_name") - datatype_name = _get_attr(inner, "datatype_name") - constraint_name = _get_attr(inner, "constraint_name") - internal_query = _get_attr(inner, "internal_query") - internal_position = _get_attr(inner, "internal_position") - - if hasattr(exception, "get_server_error_message"): - try: - m = exception.get_server_error_message() - if m: - message_primary = m - except Exception: - pass - _detail = getattr(exception, "get_detail", None) or getattr(exception, "get_server_error_detail", None) - if _detail is not None: - try: - v = _detail() - if v is not None: - message_detail = v - except Exception: - pass - for attr, var_name in ( - ("hint", "message_hint"), - ("schema_name", "schema_name"), - ("table_name", "table_name"), - ("column_name", "column_name"), - ("datatype_name", "datatype_name"), - ("constraint_name", "constraint_name"), - ): - getter = getattr(exception, "get_" + attr, None) or getattr(exception, "get_server_error_" + attr, None) - if getter is not None: - try: - v = getter() - if v is not None: - if var_name == "message_hint": - message_hint = v - elif var_name == "schema_name": - schema_name = v - elif var_name == "table_name": - table_name = v - elif var_name == "column_name": - column_name = v - elif var_name == "datatype_name": - datatype_name = v - elif var_name == "constraint_name": - constraint_name = v - except Exception: - pass - - return Diagnostics( - message_primary=message_primary, - message_detail=message_detail, - message_hint=message_hint, - context=context, - position=position, - schema_name=schema_name, - table_name=table_name, - column_name=column_name, - datatype_name=datatype_name, - constraint_name=constraint_name, - internal_query=internal_query, - internal_position=internal_position, - ) - - -def _get_attr(obj: Any, name: str) -> Optional[Any]: - v = getattr(obj, name, None) - if v is not None and (isinstance(v, str) and v.strip() == ""): - return None - return v - - -def _get_sqlstate_from_exception(exception: Any) -> Optional[str]: - if exception is None: - return None - code = getattr(exception, "pgcode", None) or getattr(exception, "sqlstate", None) - if code is not None: - return str(code).strip() - msg = getattr(exception, "pgerror", None) or str(exception) - return extract_error_code(msg) - - -def tags_from_cursor_diagnostics(diagnostics: Optional[Diagnostics]) -> List[TagWithProvenance]: - """Tags from err.diag.* (high confidence).""" - out: List[TagWithProvenance] = [] - if diagnostics is None: - return out - - if diagnostics.column_name is not None: - out.append(TagWithProvenance( - tag=SchemaErrorTags.HALLUCINATION_COLUMN, - source=SOURCE_PG_DIAG_COLUMN_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag=SchemaErrorTags.AMBIGUOUS_COLUMN, - source=SOURCE_PG_DIAG_COLUMN_NAME, - confidence=CONFIDENCE_HIGH, - )) - - if diagnostics.table_name is not None: - out.append(TagWithProvenance( - tag=SchemaErrorTags.HALLUCINATION_TABLE, - source=SOURCE_PG_DIAG_TABLE_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag=JoinErrorTags.MISSING_JOIN, - source=SOURCE_PG_DIAG_TABLE_NAME, - confidence=CONFIDENCE_HIGH, - )) - - if diagnostics.constraint_name is not None: - out.append(TagWithProvenance( - tag=LogicalErrorTags.UNIQUE_VIOLATION, - source=SOURCE_PG_DIAG_CONSTRAINT_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag=LogicalErrorTags.FOREIGN_KEY_VIOLATION, - source=SOURCE_PG_DIAG_CONSTRAINT_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag="schema_incorrect_foreign_key", - source=SOURCE_PG_DIAG_CONSTRAINT_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag=LogicalErrorTags.CHECK_VIOLATION, - source=SOURCE_PG_DIAG_CONSTRAINT_NAME, - confidence=CONFIDENCE_HIGH, - )) - - if diagnostics.datatype_name is not None: - out.append(TagWithProvenance( - tag=SchemaErrorTags.TYPE_MISMATCH, - source=SOURCE_PG_DIAG_DATATYPE_NAME, - confidence=CONFIDENCE_HIGH, - )) - out.append(TagWithProvenance( - tag=FilterErrorTags.TYPE_MISMATCH_WHERE, - source=SOURCE_PG_DIAG_DATATYPE_NAME, - confidence=CONFIDENCE_HIGH, - )) - - if diagnostics.schema_name is not None: - out.append(TagWithProvenance( - tag=SchemaErrorTags.HALLUCINATION_TABLE, - source=SOURCE_PG_DIAG_SCHEMA_NAME, - confidence=CONFIDENCE_HIGH, - )) - - return out - - -def tags_from_sqlstate(sqlstate: Optional[str]) -> List[TagWithProvenance]: - """Tags from SQLSTATE (medium confidence).""" - out: List[TagWithProvenance] = [] - if sqlstate is None: - return out - specific_tag = get_tag_for_sqlstate(sqlstate) - if specific_tag is not None: - out.append(TagWithProvenance(tag=specific_tag, source=SOURCE_SQLSTATE, confidence=CONFIDENCE_MEDIUM)) - return out - category = get_taxonomy_category_with_fallback(sqlstate) - if category is not None: - for tag in get_tags_for_category(category): - out.append(TagWithProvenance(tag=tag, source=SOURCE_SQLSTATE, confidence=CONFIDENCE_MEDIUM)) - return out - - -def tags_from_regex(message: Optional[str]) -> List[TagWithProvenance]: - """Tags from message when SQLSTATE/diag unavailable (low confidence).""" - out: List[TagWithProvenance] = [] - if not message: - return out - code = extract_error_code(message) - if code is not None: - tag = get_tag_for_sqlstate(code) - if tag is not None: - out.append(TagWithProvenance(tag=tag, source=SOURCE_REGEX, confidence=CONFIDENCE_LOW)) - else: - category = get_taxonomy_category_with_fallback(code) - if category is not None: - for t in get_tags_for_category(category): - out.append(TagWithProvenance(tag=t, source=SOURCE_REGEX, confidence=CONFIDENCE_LOW)) - return out - - -def localize_position(sql: str, position: Optional[int]) -> Optional[dict]: - """Return token and context_snippet at position. Keys: token, start, end, context_snippet.""" - if position is None or position < 0 or not sql: - return None - if position >= len(sql): - return {"token": None, "start": position, "end": position, "context_snippet": sql[-50:] if len(sql) > 50 else sql} - # Simple token at position: extend to word boundaries - start = position - while start > 0 and sql[start - 1].isalnum() or sql[start - 1] in "_.": - start -= 1 - end = position - while end < len(sql) and (sql[end].isalnum() or sql[end] in "_."): - end += 1 - token = sql[start:end] if end > start else sql[position:position + 1] - snippet_start = max(0, position - 25) - snippet_end = min(len(sql), position + 25) - return { - "token": token or None, - "start": start, - "end": end, - "context_snippet": sql[snippet_start:snippet_end], - } - - -def tags_from_position(sql: str, position: Optional[int], diagnostics: Optional[Diagnostics]) -> List[TagWithProvenance]: - """Structural/syntax tags from position (e.g. trailing_delimiter, unbalanced_tokens).""" - out: List[TagWithProvenance] = [] - if position is None or not sql: - return out - loc = localize_position(sql, position) - if loc is None: - return out - token = loc.get("token") - snippet = (loc.get("context_snippet") or "").upper() - if "," in snippet and any(kw in snippet for kw in ("FROM", "WHERE", "GROUP", "ORDER", "JOIN", "HAVING", "LIMIT")): - out.append(TagWithProvenance( - tag=SyntaxErrorTags.TRAILING_DELIMITER, - source=SOURCE_PG_DIAG_POSITION, - confidence=CONFIDENCE_MEDIUM, - )) - if snippet.count("(") != snippet.count(")"): - out.append(TagWithProvenance( - tag=SyntaxErrorTags.UNBALANCED_TOKENS, - source=SOURCE_PG_DIAG_POSITION, - confidence=CONFIDENCE_MEDIUM, - )) - if token and re.match(r"^['\"]?[^'\"]*$", token): - out.append(TagWithProvenance( - tag="value_hardcoded_value", - source=SOURCE_PG_DIAG_POSITION, - confidence=CONFIDENCE_LOW, - )) - return out - - -def tags_from_ast_cross_signals( - ast: Any, - diagnostics: Optional[Diagnostics], - sqlstate: Optional[str], -) -> List[TagWithProvenance]: - """Cross-signals: column+subquery, GROUP BY+agg, missing join.""" - out: List[TagWithProvenance] = [] - if ast is None: - return out - - try: - from sqlglot import exp - except ImportError: - return out - if sqlstate == "42803": - has_agg = any(1 for n in ast.walk() if isinstance(n, exp.AggFunc)) - has_group = any(1 for n in ast.walk() if isinstance(n, exp.Group)) - if has_agg and has_group: - out.append(TagWithProvenance( - tag=AggregationErrorTags.MISSING_GROUPBY, - source=SOURCE_AST_HEURISTIC, - confidence=CONFIDENCE_MEDIUM, - )) - out.append(TagWithProvenance( - tag=LogicalErrorTags.GROUPING_ERROR, - source=SOURCE_AST_HEURISTIC, - confidence=CONFIDENCE_MEDIUM, - )) - - # Undefined column 42703 + column might be in subquery only - if sqlstate == "42703" and diagnostics and diagnostics.column_name: - # Heuristic: query has subqueries → possible correlation error - has_subquery = any(1 for n in ast.walk() if isinstance(n, exp.Subquery)) - if has_subquery: - out.append(TagWithProvenance( - tag="subquery_incorrect_correlation", - source=SOURCE_AST_HEURISTIC, - confidence=CONFIDENCE_LOW, - )) - if diagnostics and diagnostics.table_name: - tables_in_ast = [t.name for t in ast.find_all(exp.Table)] - if len(tables_in_ast) >= 2 and diagnostics.table_name not in tables_in_ast: - out.append(TagWithProvenance( - tag=JoinErrorTags.MISSING_JOIN, - source=SOURCE_AST_HEURISTIC, - confidence=CONFIDENCE_MEDIUM, - )) - - return out - - -def build_error_context( - sql: str, - ast: Optional[Any] = None, - error: Optional[Any] = None, -) -> ErrorContext: - """Build ErrorContext from sql, optional ast and error; tags with provenance.""" - diagnostics = extract_diagnostics(error) if error is not None else None - sqlstate = _get_sqlstate_from_exception(error) if error is not None else None - if sqlstate is None and diagnostics and diagnostics.message_primary: - sqlstate = extract_error_code(diagnostics.message_primary) - - tags: List[TagWithProvenance] = [] - tags.extend(tags_from_cursor_diagnostics(diagnostics)) - tags.extend(tags_from_sqlstate(sqlstate)) - if not sqlstate and diagnostics and diagnostics.message_primary: - tags.extend(tags_from_regex(diagnostics.message_primary)) - pos = diagnostics.position if diagnostics else None - tags.extend(tags_from_position(sql, pos, diagnostics)) - tags.extend(tags_from_ast_cross_signals(ast, diagnostics, sqlstate)) - seen: dict = {} - for t in tags: - key = (t.tag, t.source) - if key not in seen or seen[key].confidence < t.confidence: - seen[key] = t - unique_tags = list(seen.values()) - - return ErrorContext( - sql=sql, - ast=ast, - sqlstate=sqlstate, - diagnostics=diagnostics, - tags=unique_tags, - ) diff --git a/src/ast_parsers/errors.py b/src/ast_parsers/errors.py deleted file mode 100644 index 57b002f..0000000 --- a/src/ast_parsers/errors.py +++ /dev/null @@ -1,228 +0,0 @@ -# -*- coding: utf-8 -*- -"""Error types and classes. See README.md.""" - -from dataclasses import dataclass, field -from typing import Optional, List, Any, Dict - - -import json -import os -import sys - -def _load_error_data(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, "data", "error_data.json") - try: - with open(data_path, "r", encoding="utf-8") as f: - return json.load(f) - except FileNotFoundError: - # Fallback/Safety for when file isn't found (e.g. CI without data) - print(f"Warning: {data_path} not found.", file=sys.stderr) - return {"taxonomy_categories": {}} - -_ERROR_DATA = _load_error_data() -_CATEGORIES = _ERROR_DATA.get("taxonomy_categories", {}) - -def _create_tag_class(class_name, category_key, prefix_to_strip, name_overrides=None): - valid_tags = _CATEGORIES.get(category_key, []) - attrs = {} - overrides = name_overrides or {} - - for tag in valid_tags: - if tag in overrides: - attr_name = overrides[tag] - # Heuristic: If tag is exactly "{prefix}error", keep full name (e.g. SYNTAX_ERROR) - # Otherwise strip prefix (e.g. syntax_unbalanced_tokens -> UNBALANCED_TOKENS) - elif tag == f"{prefix_to_strip}error": - attr_name = tag.upper() - elif tag.startswith(prefix_to_strip): - attr_name = tag[len(prefix_to_strip):].upper() - else: - attr_name = tag.upper() - - attrs[attr_name] = tag - - # Create the class dynamically - return type(class_name, (), attrs) - -# Define classes using the dynamic generator -SyntaxErrorTags = _create_tag_class("SyntaxErrorTags", "syntax", "syntax_") -SchemaErrorTags = _create_tag_class( - "SchemaErrorTags", - "semantic", - "schema_", - name_overrides={ - "schema_hallucination_col": "HALLUCINATION_COLUMN", - "schema_ambiguous_col": "AMBIGUOUS_COLUMN" - } -) -LogicalErrorTags = _create_tag_class("LogicalErrorTags", "logical", "logical_") -JoinErrorTags = _create_tag_class("JoinErrorTags", "join_related", "join_") -AggregationErrorTags = _create_tag_class("AggregationErrorTags", "aggregation", "aggregation_") -FilterErrorTags = _create_tag_class("FilterErrorTags", "filter_conditions", "filter_") -SubqueryErrorTags = _create_tag_class("SubqueryErrorTags", "subquery_formulation", "subquery_") -SetOperationErrorTags = _create_tag_class("SetOperationErrorTags", "set_operations", "set_") -StructuralErrorTags = _create_tag_class("StructuralErrorTags", "structural", "structural_") - - -SOURCE_PG_DIAG_COLUMN_NAME = "pg_diag.column_name" -SOURCE_PG_DIAG_TABLE_NAME = "pg_diag.table_name" -SOURCE_PG_DIAG_CONSTRAINT_NAME = "pg_diag.constraint_name" -SOURCE_PG_DIAG_DATATYPE_NAME = "pg_diag.datatype_name" -SOURCE_PG_DIAG_SCHEMA_NAME = "pg_diag.schema_name" -SOURCE_PG_DIAG_POSITION = "pg_diag.position" -SOURCE_SQLSTATE = "sqlstate" -SOURCE_REGEX = "regex" -SOURCE_AST_HEURISTIC = "ast_heuristic" - -CONFIDENCE_HIGH = 0.95 -CONFIDENCE_MEDIUM = 0.7 -CONFIDENCE_LOW = 0.4 - - -@dataclass(frozen=True) -class TagWithProvenance: - """Error tag with source and confidence (0.0–1.0).""" - tag: str - source: str - confidence: float - - def to_dict(self) -> dict: - return {"tag": self.tag, "source": self.source, "confidence": self.confidence} - - -@dataclass -class Diagnostics: - """PostgreSQL err.diag.* fields; missing fields are None.""" - message_primary: Optional[str] = None - message_detail: Optional[str] = None - message_hint: Optional[str] = None - context: Optional[str] = None - position: Optional[int] = None - schema_name: Optional[str] = None - table_name: Optional[str] = None - column_name: Optional[str] = None - datatype_name: Optional[str] = None - constraint_name: Optional[str] = None - internal_query: Optional[str] = None - internal_position: Optional[int] = None - - def to_dict(self) -> Dict[str, Any]: - return { - "message_primary": self.message_primary, - "message_detail": self.message_detail, - "message_hint": self.message_hint, - "context": self.context, - "position": self.position, - "schema_name": self.schema_name, - "table_name": self.table_name, - "column_name": self.column_name, - "datatype_name": self.datatype_name, - "constraint_name": self.constraint_name, - "internal_query": self.internal_query, - "internal_position": self.internal_position, - } - - -@dataclass -class ErrorContext: - """Structured error context: sql, optional ast/sqlstate/diagnostics, tags with provenance.""" - sql: str - ast: Optional[Any] = None - sqlstate: Optional[str] = None - diagnostics: Optional[Diagnostics] = None - tags: List[TagWithProvenance] = field(default_factory=list) - - def to_dict(self) -> dict: - return { - "sql": self.sql, - "sqlstate": self.sqlstate, - "diagnostics": self.diagnostics.to_dict() if self.diagnostics else None, - "tags": [t.to_dict() for t in self.tags], - } - - -@dataclass -class ValidationError: - """One validation error: tag, message, optional location/context/error_code.""" - tag: str - message: str - location: Optional[int] = None - context: Optional[str] = None - error_code: Optional[str] = None - taxonomy_category: Optional[str] = None - affected_clauses: List[str] = field(default_factory=list) - - def to_dict(self) -> dict: - result = { - "tag": self.tag, - "message": self.message, - } - if self.location is not None: - result["location"] = self.location - if self.context is not None: - result["context"] = self.context - if self.error_code is not None: - result["error_code"] = self.error_code - if self.taxonomy_category is not None: - result["taxonomy_category"] = self.taxonomy_category - if self.affected_clauses: - result["affected_clauses"] = self.affected_clauses - return result - - -@dataclass -class QueryMetadata: - """Metadata about a SQL query's structure and complexity.""" - complexity_score: float - pattern_signature: str - clauses_present: List[str] = field(default_factory=list) - num_joins: int = 0 - num_subqueries: int = 0 - num_ctes: int = 0 - num_aggregations: int = 0 - - def to_dict(self) -> dict: - return { - "complexity_score": self.complexity_score, - "pattern_signature": self.pattern_signature, - "clauses_present": self.clauses_present, - "num_joins": self.num_joins, - "num_subqueries": self.num_subqueries, - "num_ctes": self.num_ctes, - "num_aggregations": self.num_aggregations, - } - - -@dataclass -class ValidationResult: - """Validation result: valid flag, errors, optional ast/sql/query_metadata.""" - valid: bool - errors: List[ValidationError] = field(default_factory=list) - ast: Optional[Any] = None # sqlglot.Expression, using Any to avoid import - sql: str = "" - query_metadata: Optional[QueryMetadata] = None - - @property - def tags(self) -> List[str]: - return [e.tag for e in self.errors] - - @property - def error_messages(self) -> List[str]: - return [e.message for e in self.errors] - - def to_dict(self) -> dict: - result = { - "valid": self.valid, - "sql": self.sql, - "errors": [e.to_dict() for e in self.errors], - "tags": self.tags, - } - if self.query_metadata is not None: - result["query_metadata"] = self.query_metadata.to_dict() - return result - - def __repr__(self) -> str: - if self.valid: - return f"ValidationResult(valid=True, sql={self.sql[:50]!r}...)" - return f"ValidationResult(valid=False, tags={self.tags}, sql={self.sql[:50]!r}...)" diff --git a/src/ast_parsers/llm_tool.py b/src/ast_parsers/llm_tool.py deleted file mode 100644 index 6ddecb5..0000000 --- a/src/ast_parsers/llm_tool.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -"""Simplified SQL validation for LLM agent tool calls.""" - -import json -from pathlib import Path -from typing import Dict, List, Optional - -from ast_parsers.validator import validate_syntax, validate_schema -from ast_parsers.models import ValidationErrorOut - -# Path to schema JSON files -SCHEMA_DIR = Path(__file__).parent.parent.parent / "benchmark" / "data" / "schemas" - - -def _load_schema(db_name: str) -> Optional[Dict[str, Dict[str, str]]]: - """Load schema from JSON file if it exists.""" - schema_path = SCHEMA_DIR / f"{db_name}.json" - if schema_path.exists(): - with open(schema_path, "r", encoding="utf-8") as f: - return json.load(f) - return None - - -def validate_sql( - sql: str, - db_name: Optional[str] = None, - dialect: str = "postgres", -) -> List[ValidationErrorOut]: - """Validate SQL syntax and optionally schema, returning only errors. - - Args: - sql: SQL query string to validate. - db_name: Optional database name (e.g., "california_schools_template"). - If provided and schema file exists, validates against schema. - dialect: SQL dialect (default: "postgres"). - - Returns: - List of ValidationErrorOut. Empty list means the SQL is valid. - """ - schema = _load_schema(db_name) if db_name else None - - if schema is not None: - result = validate_schema(sql, schema, dialect=dialect) - else: - result = validate_syntax(sql, dialect=dialect) - - return [ - ValidationErrorOut( - tag=e.tag, - message=e.message, - location=e.location, - context=e.context, - error_code=e.error_code, - taxonomy_category=e.taxonomy_category, - affected_clauses=e.affected_clauses or [], - ) - for e in result.errors - ] diff --git a/src/ast_parsers/models.py b/src/ast_parsers/models.py deleted file mode 100644 index 441c229..0000000 --- a/src/ast_parsers/models.py +++ /dev/null @@ -1,178 +0,0 @@ -# -*- coding: utf-8 -*- -"""Pydantic models for validation API. See README.md.""" - -from typing import Any, Dict, List, Literal, Optional, Tuple, get_args -import json -import os -import sys - -from pydantic import BaseModel, Field - - -def _load_error_data(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, "data", "error_data.json") - try: - with open(data_path, "r", encoding="utf-8") as f: - return json.load(f) - except FileNotFoundError: - print(f"Warning: {data_path} not found.", file=sys.stderr) - return {"taxonomy_categories": {}} - - -def _load_complexity_config(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, "data", "complexity_config.json") - try: - with open(data_path, "r", encoding="utf-8") as f: - return json.load(f) - except FileNotFoundError: - print(f"Warning: {data_path} not found.", file=sys.stderr) - return {} - -_ERROR_DATA = _load_error_data() -_COMPLEXITY_CONFIG = _load_complexity_config() -_CATEGORIES = _ERROR_DATA.get("taxonomy_categories", {}) - -# ----------------------------------------------------------------------------- -# Error Tags (loaded from JSON) -SyntaxTag = str -SemanticTag = str -LogicalTag = str -JoinRelatedTag = str -AggregationTag = str -FilterTag = str -ValueTag = str -SubqueryTag = str -SetOperationTag = str -StructuralTag = str - -# Unified TagName -TagName = str - -# All tag strings the validator can return -_all_tags_list = [] -for tags in _CATEGORIES.values(): - _all_tags_list.extend(tags) -ALL_TAG_NAMES: Tuple[str, ...] = tuple(sorted(_all_tags_list)) - - - -_CLAUSES = _COMPLEXITY_CONFIG.get("clause_complexity_categories", {}) - -# ----------------------------------------------------------------------------- -# Clause set -# ----------------------------------------------------------------------------- - -StandardClause = str -JoinClause = str -SetClause = str -AdvancedClause = str - -# Unified ClauseName -ClauseName = str - -_all_clauses_list = [] -for clauses in _CLAUSES.values(): - _all_clauses_list.extend(clauses) -ALL_CLAUSE_NAMES: Tuple[str, ...] = tuple(sorted(_all_clauses_list)) - - -class ValidationInput(BaseModel): - """Input: query, optional schema, optional ast.""" - - query: str = Field(..., description="SQL query string to validate") - table_schema: Optional[Dict[str, Dict[str, str]]] = Field( - default=None, - alias="schema", - description="Optional schema as {table_name: {column_name: type}}", - ) - ast: Optional[Any] = Field( - default=None, - description="Optional pre-parsed AST (e.g. sqlglot Expression); if omitted, parsed from query", - ) - - model_config = {"extra": "forbid", "populate_by_name": True} - - -# ----------------------------------------------------------------------------- -# Output: what the validation pipeline returns -# ----------------------------------------------------------------------------- - -class ValidationErrorOut(BaseModel): - """A single validation error with a tag from the canonical tag set.""" - - tag: TagName = Field(..., description="Canonical error tag") - message: str = Field(..., description="Human-readable error message") - location: Optional[int] = Field(default=None, description="Character position in SQL if known") - context: Optional[str] = Field(default=None, description="Additional context or raw message") - error_code: Optional[str] = Field(default=None, description="PostgreSQL SQLSTATE if known") - taxonomy_category: Optional[str] = Field(default=None, description="Taxonomy category (e.g. syntax, semantic)") - affected_clauses: List[ClauseName] = Field(default_factory=list, description="Affected SQL clauses (canonical set)") - - model_config = {"extra": "forbid"} - - -class QueryMetadataOut(BaseModel): - """Query structure: complexity, signature, clauses, counts.""" - - complexity_score: float = Field(..., description="Normalized complexity score (0-1)") - pattern_signature: str = Field(..., description="Structural fingerprint (e.g. SELECT-WHERE-JOIN)") - clauses_present: List[ClauseName] = Field(default_factory=list, description="Clauses present in the query (canonical set)") - num_joins: int = Field(default=0, description="Number of JOINs") - num_subqueries: int = Field(default=0, description="Number of subqueries") - num_ctes: int = Field(default=0, description="Number of CTEs") - num_aggregations: int = Field(default=0, description="Number of aggregations") - - model_config = {"extra": "forbid"} - - -class ValidationResultOut(BaseModel): - """Result of SQL validation: valid flag, errors (with tags from the canonical set), sql, optional metadata.""" - - valid: bool = Field(..., description="True if the query passed validation") - errors: List[ValidationErrorOut] = Field(default_factory=list, description="Validation errors if invalid") - sql: str = Field(default="", description="Original SQL that was validated") - tags: List[TagName] = Field(default_factory=list, description="Error tags (same order as errors)") - query_metadata: Optional[QueryMetadataOut] = Field(default=None, description="Structure metadata if analyzed") - - model_config = {"extra": "forbid"} - - @classmethod - def from_validation_result(cls, result: Any) -> "ValidationResultOut": - """From dataclass ValidationResult (ast_parsers.errors).""" - from ast_parsers.errors import ValidationResult as VR - - if not isinstance(result, VR): - raise TypeError("Expected ValidationResult") - errors_out = [ - ValidationErrorOut( - tag=e.tag, # type: ignore[arg-type] - message=e.message, - location=e.location, - context=e.context, - error_code=e.error_code, - taxonomy_category=e.taxonomy_category, - affected_clauses=e.affected_clauses or [], - ) - for e in result.errors - ] - metadata_out = None - if result.query_metadata is not None: - m = result.query_metadata - metadata_out = QueryMetadataOut( - complexity_score=m.complexity_score, - pattern_signature=m.pattern_signature, - clauses_present=m.clauses_present or [], - num_joins=m.num_joins, - num_subqueries=m.num_subqueries, - num_ctes=m.num_ctes, - num_aggregations=m.num_aggregations, - ) - return cls( - valid=result.valid, - errors=errors_out, - sql=result.sql or "", - tags=result.tags or [], - query_metadata=metadata_out, - ) diff --git a/src/ast_parsers/query_analyzer.py b/src/ast_parsers/query_analyzer.py index c4012d5..d056bb3 100644 --- a/src/ast_parsers/query_analyzer.py +++ b/src/ast_parsers/query_analyzer.py @@ -1,361 +1,312 @@ # -*- coding: utf-8 -*- -"""Query structure analysis. See README.md for logic details.""" +""" +Query structure analysis: single-pass AST traversal → QueryMetadata. + +Public API: + analyze_query(ast) -> QueryMetadata + +That's it. One entry point, one exit point. +All clause detection, complexity scoring, and count collection happen inside +a single ast.walk() call. No secondary traversals. +""" + +from __future__ import annotations -from typing import List, Set, Any, Dict, Tuple import hashlib import json import os -import sys -from collections import defaultdict +from functools import lru_cache +from typing import Any, Dict, Set from sqlglot import exp -from ast_parsers.errors import QueryMetadata +from ast_parsers.result import QueryMetadata -# Load complexity configuration -def _load_complexity_config(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, "data", "complexity_config.json") + +@lru_cache(maxsize=1) +def _load_complexity_config() -> dict: + """Load complexity weights/bounds once and cache.""" + data_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data", + "complexity_config.json", + ) try: - with open(data_path, "r", encoding="utf-8") as f: - return json.load(f) - except FileNotFoundError: - print(f"Warning: {data_path} not found.", file=sys.stderr) + with open(data_path, "r", encoding="utf-8") as fh: + return json.load(fh) + except (FileNotFoundError, json.JSONDecodeError): return {} -_COMPLEXITY_CONFIG = _load_complexity_config() -_WEIGHTS = _COMPLEXITY_CONFIG.get("complexity_weights", {}) -_BOUNDS = _COMPLEXITY_CONFIG.get("normalization_bounds", {}) +# Canonical clause ordering for pattern signatures +_CLAUSE_ORDER: list[str] = [ + "WITH", + "CTE", + "SELECT", + "DISTINCT", + "DISTINCT_ON", + "FROM", + "JOIN", + "JOIN_INNER", + "JOIN_LEFT", + "JOIN_RIGHT", + "JOIN_FULL", + "JOIN_CROSS", + "LATERAL", + "WHERE", + "GROUP", + "HAVING", + "WINDOW", + "PARTITION", + "QUALIFY", + "UNION", + "INTERSECT", + "EXCEPT", + "ORDER", + "LIMIT", + "OFFSET", + "TABLESAMPLE", + "VALUES", + "FILTER", + "LOCKING", + "INSERT", + "UPDATE", + "DELETE", + "MERGE", + "RETURNING", +] -def _analyze_ast_single_pass(ast: Any) -> Tuple[Set[str], float, Dict[str, int]]: +def analyze_query(ast: Any) -> QueryMetadata: """ - Single pass AST analysis. See README.md. - - Returns: - (clauses, complexity, counts) + Analyze a sqlglot AST in a single pass and return QueryMetadata. + + This is the *only* public function in this module. Callers that previously + called extract_sql_clauses / calculate_complexity / count_query_elements + separately should instead call this once and read the relevant fields from + the returned QueryMetadata. """ - clauses: Set[str] = set() - # counts: Dict[str, int] = defaultdict(int) <- causing issues with Pyre - counts: Dict[str, int] = {} - - # Initialize all keys to 0 - keys_to_init = [ - 'num_tables', 'num_predicates', 'num_boolean_ops', 'nesting_depth', - 'num_aggregates', 'num_joins', 'num_subqueries', 'joins', 'unions', - 'ctes', 'windows', 'laterals', 'values', 'qualify', 'tablesample', - 'locking', 'subqueries', 'insert', 'update', 'delete', 'merge', - 'returning', 'aggregations', 'case_statements', 'distinct_on', 'filter_agg' - ] - for k in keys_to_init: - counts[k] = 0 - if ast is None: - return clauses, 0.0, counts - - unique_tables = set() - max_nesting_depth = 0 + return QueryMetadata(complexity_score=0.0, pattern_signature="EMPTY") + cfg = _load_complexity_config() + weights: Dict[str, float] = cfg.get("complexity_weights", {}) + bounds: Dict[str, float] = cfg.get("normalization_bounds", {}) - max_nesting_depth = 0 + clauses: Set[str] = set() + unique_tables: Set[str] = set() + counts: Dict[str, int] = { + k: 0 + for k in ( + "num_tables", + "num_predicates", + "num_boolean_ops", + "nesting_depth", + "num_aggregates", + "num_joins", + "num_subqueries", + "ctes", + "unions", + "windows", + "laterals", + "values", + "qualify", + "tablesample", + "locking", + "insert", + "update", + "delete", + "merge", + "returning", + "aggregations", + "case_statements", + "distinct_on", + "filter_agg", + ) + } - # Depth calculation: see README.md for strategy - + # ── Single walk: classify every node ──────────────────────────────────── for node in ast.walk(): - # --- Clauses --- if isinstance(node, exp.Select): clauses.add("SELECT") - # Safe access to args - if hasattr(node, "args") and node.args.get("distinct"): + if node.args.get("distinct"): clauses.add("DISTINCT") - if isinstance(node, exp.From): + # Nesting depth: count Subquery/CTE ancestors above this Select + depth = 0 + curr = node.parent + while curr: + if isinstance(curr, (exp.Subquery, exp.CTE)): + depth += 1 + curr = curr.parent + if depth > counts["nesting_depth"]: + counts["nesting_depth"] = depth + + elif isinstance(node, exp.From): clauses.add("FROM") - if isinstance(node, exp.Where): + + elif isinstance(node, exp.Where): clauses.add("WHERE") - counts['num_predicates'] += 1 - if isinstance(node, exp.Join): + counts["num_predicates"] += 1 + + elif isinstance(node, exp.Join): clauses.add("JOIN") - counts['joins'] += 1 - counts['num_joins'] += 1 - counts['num_predicates'] += 1 - if node.kind: - join_type = node.kind.upper() - if join_type in ["INNER", "LEFT", "RIGHT", "FULL", "CROSS"]: - clauses.add(f"JOIN_{join_type}") - if isinstance(node, exp.Group): + counts["num_joins"] += 1 + counts["num_predicates"] += 1 + kind = (node.kind or "").upper() + if kind in {"INNER", "LEFT", "RIGHT", "FULL", "CROSS"}: + clauses.add(f"JOIN_{kind}") + + elif isinstance(node, exp.Group): clauses.add("GROUP") - if isinstance(node, exp.Order): + + elif isinstance(node, exp.Order): clauses.add("ORDER") - if isinstance(node, exp.Having): + + elif isinstance(node, exp.Having): clauses.add("HAVING") - counts['num_predicates'] += 1 - if isinstance(node, exp.Limit): + counts["num_predicates"] += 1 + + elif isinstance(node, exp.Limit): clauses.add("LIMIT") - if isinstance(node, exp.Offset): + + elif isinstance(node, exp.Offset): clauses.add("OFFSET") - - # --- Tables --- - if isinstance(node, exp.Table): - table_name = node.name - if table_name: - unique_tables.add(table_name) - - # --- Boolean Ops --- - if isinstance(node, (exp.And, exp.Or)): - counts['num_boolean_ops'] += 1 - - if isinstance(node, exp.Union): + + elif isinstance(node, exp.Table): + if node.name: + unique_tables.add(node.name.lower()) + + elif isinstance(node, (exp.And, exp.Or)): + counts["num_boolean_ops"] += 1 + + elif isinstance(node, exp.Union): clauses.add("UNION") - counts['unions'] += 1 - if isinstance(node, exp.Intersect): + counts["unions"] += 1 + + elif isinstance(node, exp.Intersect): clauses.add("INTERSECT") - counts['unions'] += 1 - if isinstance(node, exp.Except): + counts["unions"] += 1 + + elif isinstance(node, exp.Except): clauses.add("EXCEPT") - counts['unions'] += 1 - - if isinstance(node, exp.CTE): + counts["unions"] += 1 + + elif isinstance(node, exp.CTE): clauses.add("CTE") - counts['ctes'] += 1 - if isinstance(node, exp.With): + counts["ctes"] += 1 + + elif isinstance(node, exp.With): clauses.add("WITH") - - if isinstance(node, exp.Distinct) and hasattr(node, "args") and node.args.get("on"): + + elif isinstance(node, exp.Distinct) and node.args.get("on"): clauses.add("DISTINCT_ON") - counts['distinct_on'] += 1 - - # Window / Over - if isinstance(node, (exp.Window, exp.WindowSpec)): + counts["distinct_on"] += 1 + + elif isinstance(node, (exp.Window, exp.WindowSpec)): clauses.add("WINDOW") - counts['windows'] += 1 - - if isinstance(node, exp.Partition): + counts["windows"] += 1 + + elif isinstance(node, exp.Partition): clauses.add("PARTITION") - - if isinstance(node, exp.Filter): + + elif isinstance(node, exp.Filter): clauses.add("FILTER") - counts['filter_agg'] += 1 - - if isinstance(node, exp.Lateral): + counts["filter_agg"] += 1 + + elif isinstance(node, exp.Lateral): clauses.add("LATERAL") - counts['laterals'] += 1 - - if isinstance(node, exp.Values): + counts["laterals"] += 1 + + elif isinstance(node, exp.Values): clauses.add("VALUES") - counts['values'] += 1 - - if isinstance(node, exp.Qualify): + counts["values"] += 1 + + elif isinstance(node, exp.Qualify): clauses.add("QUALIFY") - counts['qualify'] += 1 - - if isinstance(node, exp.TableSample): + counts["qualify"] += 1 + + elif isinstance(node, exp.TableSample): clauses.add("TABLESAMPLE") - counts['tablesample'] += 1 - - if isinstance(node, exp.Lock): + counts["tablesample"] += 1 + + elif isinstance(node, exp.Lock): clauses.add("LOCKING") - counts['locking'] += 1 - - if isinstance(node, exp.Subquery): + counts["locking"] += 1 + + elif isinstance(node, exp.Subquery): clauses.add("SUBQUERY") - counts['subqueries'] += 1 - counts['num_subqueries'] += 1 - - if isinstance(node, exp.Insert): + counts["num_subqueries"] += 1 + + elif isinstance(node, exp.Insert): clauses.add("INSERT") - counts['insert'] += 1 - if isinstance(node, exp.Update): + counts["insert"] += 1 + + elif isinstance(node, exp.Update): clauses.add("UPDATE") - counts['update'] += 1 - if isinstance(node, exp.Delete): + counts["update"] += 1 + + elif isinstance(node, exp.Delete): clauses.add("DELETE") - counts['delete'] += 1 - if isinstance(node, exp.Merge): + counts["delete"] += 1 + + elif isinstance(node, exp.Merge): clauses.add("MERGE") - counts['merge'] += 1 - if isinstance(node, exp.Returning): + counts["merge"] += 1 + + elif isinstance(node, exp.Returning): clauses.add("RETURNING") - counts['returning'] += 1 - - if isinstance(node, exp.AggFunc): - counts['aggregations'] += 1 - counts['num_aggregates'] += 1 - - if isinstance(node, exp.Case): - counts['case_statements'] += 1 - - # Post-loop calculations - counts['num_tables'] = len(unique_tables) - - # Depth calculation (checking all nodes for max depth of subquery nesting) - # Using a fresh walk or just the cached understanding? - # Let's check depth of all SELECTs found in the tree (as they represent query scopes) - if ast: - max_depth = 0 - for node in ast.find_all(exp.Select): - depth = 0 - curr = node.parent - while curr: - if isinstance(curr, (exp.Subquery, exp.CTE)): - depth += 1 - curr = curr.parent - if depth > max_depth: - max_depth = depth - counts['nesting_depth'] = max_depth - - # --- Complexity Calculation (See README.md) --- - - def norm(value, metric_name): - bound = _BOUNDS.get(metric_name, 10.0) - return min(float(value) / float(bound), 1.0) if bound != 0 else 0.0 - - score = 0.0 - score += _WEIGHTS.get("nesting_depth", 0.0) * norm(counts['nesting_depth'], "nesting_depth") - score += _WEIGHTS.get("num_joins", 0.0) * norm(counts['num_joins'], "num_joins") - score += _WEIGHTS.get("num_subqueries", 0.0) * norm(counts['num_subqueries'], "num_subqueries") - score += _WEIGHTS.get("num_predicates", 0.0) * norm(counts['num_predicates'], "num_predicates") - score += _WEIGHTS.get("num_tables", 0.0) * norm(counts['num_tables'], "num_tables") - score += _WEIGHTS.get("num_boolean_ops", 0.0) * norm(counts['num_boolean_ops'], "num_boolean_ops") - score += _WEIGHTS.get("num_aggregates", 0.0) * norm(counts['num_aggregates'], "num_aggregates") - - return clauses, score, counts - - -def extract_sql_clauses(ast: Any) -> List[str]: - """Return sorted list of clause names (SELECT, FROM, WHERE, JOIN, etc.).""" - clauses, _, _ = _analyze_ast_single_pass(ast) - return sorted(list(clauses)) - - -def calculate_complexity(ast: Any) -> float: - """Normalized complexity score (0-1).""" - _, complexity, _ = _analyze_ast_single_pass(ast) - return complexity - - -def count_query_elements(ast: Any) -> dict: - """Count joins, subqueries, ctes, aggregations, etc.""" - _, _, counts = _analyze_ast_single_pass(ast) - - # Ensure all keys are present for API consistency - default_keys = [ - 'joins', 'subqueries', 'ctes', 'aggregations', 'case_statements', - 'unions', 'windows', 'laterals', 'qualify', 'tablesample', - 'locking', 'distinct_on', 'values', 'filter_agg', 'insert', - 'update', 'delete', 'merge', 'returning', - # New keys exposed if needed, or just kept internal? - # Let's expose them if they are useful, but existing API might expect specific keys. - # We will keep the legacy keys populated (joins, subqueries etc) above. - ] - for key in default_keys: - if key not in counts: - counts[key] = 0 - - return counts - - -# ============================================================================= -# Pattern Signature Generation -# ============================================================================= - -# Canonical ordering for pattern signature -CLAUSE_ORDER = [ - "WITH", - "CTE", - "SELECT", - "DISTINCT", - "DISTINCT_ON", - "FROM", - "JOIN", - "JOIN_INNER", - "JOIN_LEFT", - "JOIN_RIGHT", - "JOIN_FULL", - "JOIN_CROSS", - "LATERAL", - "WHERE", - "GROUP", - "HAVING", - "WINDOW", - "PARTITION", - "QUALIFY", - "UNION", - "INTERSECT", - "EXCEPT", - "ORDER", - "LIMIT", - "OFFSET", - "TABLESAMPLE", - "VALUES", - "FILTER", - "LOCKING", - "INSERT", - "UPDATE", - "DELETE", - "MERGE", - "RETURNING", -] + counts["returning"] += 1 -def generate_ordered_pattern_signature(clauses: List[str]) -> str: - """Generate signature with canonical ordering.""" - if not clauses: - return "UNKNOWN" - - ordered = [c for c in CLAUSE_ORDER if c in clauses] - - # Append any clauses not in the strict order (preserving their alphabetical sort) - # to ensure we don't lose information like 'SUBQUERY' or others not in the list - extras = sorted([c for c in clauses if c not in CLAUSE_ORDER]) - if extras: - ordered.extend(extras) - - return "-".join(ordered) if ordered else "UNKNOWN" - - -def generate_pattern_signature(ast: Any, clauses: List[str] = None) -> str: - """Structural signature. See README.md.""" - if clauses is None: - if ast is None: - return "EMPTY" - clauses = extract_sql_clauses(ast) - - if not clauses: - if ast is None: - return "EMPTY" - return "UNKNOWN" - - # Use canonical ordering - signature = generate_ordered_pattern_signature(clauses) - - # For very long signatures, create a hash - if len(signature) > 100: - signature_hash = hashlib.md5(signature.encode()).hexdigest()[:16] - return f"HASH_{signature_hash}" - - return signature + elif isinstance(node, exp.AggFunc): + counts["aggregations"] += 1 + counts["num_aggregates"] += 1 + elif isinstance(node, exp.Case): + counts["case_statements"] += 1 + + counts["num_tables"] = len(unique_tables) + + # ── Complexity score [0, 1] ──────────────────────────────────────────── + def _norm(value: int, key: str) -> float: + bound = float(bounds.get(key, 10.0)) + return min(float(value) / bound, 1.0) if bound > 0 else 0.0 + + raw_score = ( + weights.get("nesting_depth", 0.0) + * _norm(counts["nesting_depth"], "nesting_depth") + + weights.get("num_joins", 0.0) * _norm(counts["num_joins"], "num_joins") + + weights.get("num_subqueries", 0.0) + * _norm(counts["num_subqueries"], "num_subqueries") + + weights.get("num_predicates", 0.0) + * _norm(counts["num_predicates"], "num_predicates") + + weights.get("num_tables", 0.0) * _norm(counts["num_tables"], "num_tables") + + weights.get("num_boolean_ops", 0.0) + * _norm(counts["num_boolean_ops"], "num_boolean_ops") + + weights.get("num_aggregates", 0.0) + * _norm(counts["num_aggregates"], "num_aggregates") + ) + # Normalise by actual weight sum so score stays in [0, 1] even if weights + # don't sum to exactly 1.0. + total_weight = sum(weights.values()) or 1.0 + complexity = raw_score / total_weight + + # ── Pattern signature ──────────────────────────────────────────────────── + ordered = [c for c in _CLAUSE_ORDER if c in clauses] + extras = sorted(c for c in clauses if c not in _CLAUSE_ORDER) + ordered.extend(extras) + signature = "-".join(ordered) if ordered else "UNKNOWN" + + if len(signature) > 100: + h = hashlib.md5(signature.encode()).hexdigest()[:16] + signature = f"HASH_{h}" -def analyze_query(ast: Any) -> QueryMetadata: - """QueryMetadata: complexity, signature, clauses, counts.""" - clauses_set, complexity, counts = _analyze_ast_single_pass(ast) - - clauses = sorted(list(clauses_set)) - # Optimization: Pass pre-computed clauses to avoid re-traversal - signature = generate_pattern_signature(ast, clauses=clauses) - - # Ensure keys exist - joins = counts.get('joins', 0) - subqueries = counts.get('subqueries', 0) - ctes = counts.get('ctes', 0) - aggregations = counts.get('aggregations', 0) - return QueryMetadata( - complexity_score=complexity, + complexity_score=round(complexity, 4), pattern_signature=signature, - clauses_present=clauses, - num_joins=joins, - num_subqueries=subqueries, - num_ctes=ctes, - num_aggregations=aggregations, + clauses_present=sorted(clauses), + tables=sorted(unique_tables), + num_joins=counts["num_joins"], + num_subqueries=counts["num_subqueries"], + num_ctes=counts["ctes"], + num_aggregations=counts["aggregations"], ) diff --git a/src/ast_parsers/result.py b/src/ast_parsers/result.py new file mode 100644 index 0000000..628b5d6 --- /dev/null +++ b/src/ast_parsers/result.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- +""" +Unified Pydantic v2 models for SQL validation results. + +Three types cover the entire public surface: + ValidationError – one error with a canonical ErrorTag + QueryMetadata – structural analysis of the SQL query + ValidationResult – top-level result: valid flag + errors + metadata + +This replaces the previous split between ast_parsers.errors (dataclasses) and +ast_parsers.models (Pydantic mirrors), collapsing six types into three and +eliminating the manual conversion layer. +""" + +from __future__ import annotations + +from typing import Any, Dict, List, Optional + +from pydantic import BaseModel, Field, computed_field + +from ast_parsers.tags import ErrorTag + + +class ValidationError(BaseModel): + """A single validation error with a canonical tag.""" + + tag: ErrorTag + message: str + location: Optional[int] = None + context: Optional[str] = None + error_code: Optional[str] = None + affected_clauses: List[str] = Field(default_factory=list) + + @computed_field # type: ignore[misc] + @property + def taxonomy_category(self) -> str: + """Taxonomy category derived from the tag (no extra field needed).""" + return self.tag.taxonomy_category + + def to_dict(self) -> Dict[str, Any]: + d: Dict[str, Any] = { + "tag": self.tag.value, + "message": self.message, + "taxonomy_category": self.taxonomy_category, + } + if self.location is not None: + d["location"] = self.location + if self.context is not None: + d["context"] = self.context + if self.error_code is not None: + d["error_code"] = self.error_code + if self.affected_clauses: + d["affected_clauses"] = self.affected_clauses + return d + + model_config = {"extra": "forbid"} + + +class QueryMetadata(BaseModel): + """Structural metadata about a SQL query (produced by a single AST pass).""" + + complexity_score: float + pattern_signature: str + clauses_present: List[str] = Field(default_factory=list) + tables: List[str] = Field(default_factory=list) + num_joins: int = 0 + num_subqueries: int = 0 + num_ctes: int = 0 + num_aggregations: int = 0 + + def to_dict(self) -> Dict[str, Any]: + return { + "complexity_score": self.complexity_score, + "pattern_signature": self.pattern_signature, + "clauses_present": self.clauses_present, + "tables": self.tables, + "num_joins": self.num_joins, + "num_subqueries": self.num_subqueries, + "num_ctes": self.num_ctes, + "num_aggregations": self.num_aggregations, + } + + model_config = {"extra": "forbid"} + + +class ValidationResult(BaseModel): + """Complete result of SQL validation: validity, errors, and query metadata.""" + + valid: bool + sql: str = "" + errors: List[ValidationError] = Field(default_factory=list) + query_metadata: Optional[QueryMetadata] = None + + @property + def tags(self) -> List[ErrorTag]: + """Error tags from all errors (in order).""" + return [e.tag for e in self.errors] + + @property + def error_messages(self) -> List[str]: + """Error messages from all errors (in order).""" + return [e.message for e in self.errors] + + def to_dict(self) -> Dict[str, Any]: + result: Dict[str, Any] = { + "valid": self.valid, + "sql": self.sql, + "errors": [e.to_dict() for e in self.errors], + "tags": [t.value for t in self.tags], + } + if self.query_metadata is not None: + result["query_metadata"] = self.query_metadata.to_dict() + return result + + def __repr__(self) -> str: + if self.valid: + return f"ValidationResult(valid=True, sql={self.sql[:50]!r})" + return ( + f"ValidationResult(valid=False, tags={[t.value for t in self.tags]}, " + f"sql={self.sql[:50]!r})" + ) + + model_config = {"extra": "forbid"} diff --git a/src/ast_parsers/tags.py b/src/ast_parsers/tags.py new file mode 100644 index 0000000..47a3187 --- /dev/null +++ b/src/ast_parsers/tags.py @@ -0,0 +1,295 @@ +# -*- coding: utf-8 -*- +""" +All canonical SQL error tags as a single flat Enum, plus SQLSTATE helpers. + +This module is the single source of truth for: + - Every error tag string (ErrorTag enum) + - Taxonomy category for each tag (derived from tag value prefix) + - SQLSTATE → tag / category mappings + - Error-message-pattern → SQLSTATE inference + +No JSON file is needed at runtime for tag lookups. +""" + +from __future__ import annotations + +import re +from enum import Enum +from typing import Optional + +# ─── Tag prefix → taxonomy category ────────────────────────────────────────── +# The convention is that every tag value is "{prefix}_{name}". +# The prefix determines the taxonomy category automatically. +_PREFIX_TO_CATEGORY: dict[str, str] = { + "syntax": "syntax", + "schema": "semantic", + "logical": "logical", + "join": "join_related", + "aggregation": "aggregation", + "filter": "filter_conditions", + "value": "value_representation", + "subquery": "subquery_formulation", + "set": "set_operations", + "structural": "structural", +} + + +class ErrorTag(str, Enum): + """ + All canonical SQL error tags. + + Each member's *value* is the canonical tag string used in ValidationError + and stored in ChromaDB / skill files. Since this class inherits from str, + members compare equal to their string values: + ErrorTag.TRAILING_DELIMITER == "syntax_trailing_delimiter" # True + """ + + # ── Syntax ──────────────────────────────────────────────────────────── + SYNTAX_ERROR = "syntax_error" + UNBALANCED_TOKENS = "syntax_unbalanced_tokens" + TRAILING_DELIMITER = "syntax_trailing_delimiter" + KEYWORD_MISUSE = "syntax_keyword_misuse" + UNTERMINATED_STRING = "syntax_unterminated_string" + INVALID_TOKEN = "syntax_invalid_token" + UNSUPPORTED_DIALECT = "syntax_unsupported_dialect" + INVALID_NAME = "syntax_invalid_name" + INVALID_COLUMN_DEF = "syntax_invalid_column_definition" + + # ── Semantic / schema ───────────────────────────────────────────────── + HALLUCINATION_TABLE = "schema_hallucination_table" + HALLUCINATION_COLUMN = "schema_hallucination_col" + AMBIGUOUS_COLUMN = "schema_ambiguous_col" + TYPE_MISMATCH = "schema_type_mismatch" + SCHEMA_UNKNOWN_ERROR = "schema_unknown_error" + DUPLICATE_OBJECT = "schema_duplicate_object" + UNDEFINED_FUNCTION = "schema_undefined_function" + DATATYPE_MISMATCH = "schema_datatype_mismatch" + INCORRECT_FOREIGN_KEY = "schema_incorrect_foreign_key" + + # ── Logical ─────────────────────────────────────────────────────────── + GROUPING_ERROR = "logical_grouping_error" + LOGICAL_AGGREGATION = "logical_aggregation_error" + WINDOWING_ERROR = "logical_windowing_error" + INTEGRITY_VIOLATION = "logical_integrity_violation" + FOREIGN_KEY_VIOLATION = "logical_foreign_key_violation" + UNIQUE_VIOLATION = "logical_unique_violation" + CHECK_VIOLATION = "logical_check_violation" + + # ── Join ────────────────────────────────────────────────────────────── + MISSING_JOIN = "join_missing_join" + WRONG_JOIN_TYPE = "join_wrong_join_type" + EXTRA_TABLE = "join_extra_table" + JOIN_CONDITION_ERROR = "join_condition_error" + + # ── Aggregation ─────────────────────────────────────────────────────── + MISSING_GROUPBY = "aggregation_missing_groupby" + MISUSE_HAVING = "aggregation_misuse_having" + AGG_ERROR = "aggregation_error" + + # ── Filter conditions ───────────────────────────────────────────────── + INCORRECT_WHERE_COLUMN = "filter_incorrect_where_column" + FILTER_TYPE_MISMATCH = "filter_type_mismatch_where" + MISSING_WHERE = "filter_missing_where" + + # ── Value representation ────────────────────────────────────────────── + HARDCODED_VALUE = "value_hardcoded_value" + VALUE_FORMAT_MISMATCH = "value_format_mismatch" + + # ── Subquery ────────────────────────────────────────────────────────── + UNUSED_SUBQUERY = "subquery_unused_subquery" + INCORRECT_CORRELATION = "subquery_incorrect_correlation" + SUBQUERY_ERROR = "subquery_error" + + # ── Set operations ──────────────────────────────────────────────────── + UNION_ERROR = "set_union_error" + INTERSECTION_ERROR = "set_intersection_error" + EXCEPT_ERROR = "set_except_error" + + # ── Structural ──────────────────────────────────────────────────────── + MISSING_ORDERBY = "structural_missing_orderby" + MISSING_LIMIT = "structural_missing_limit" + STRUCTURAL_ERROR = "structural_error" + + @property + def taxonomy_category(self) -> str: + """Taxonomy category derived from tag value prefix (no lookup needed).""" + prefix = self.value.split("_")[0] + return _PREFIX_TO_CATEGORY.get(prefix, "syntax") + + +# ─── SQLSTATE → category (exact) ───────────────────────────────────────────── +_SQLSTATE_TO_CATEGORY: dict[str, str] = { + "42601": "syntax", + "42602": "syntax", + "42611": "syntax", + "42622": "syntax", + "42702": "semantic", + "42703": "semantic", + "42704": "semantic", + "42710": "semantic", + "42712": "semantic", + "42723": "semantic", + "42725": "semantic", + "42P01": "semantic", + "42P02": "semantic", + "42P03": "semantic", + "42P04": "semantic", + "42P05": "semantic", + "42P06": "semantic", + "42P07": "semantic", + "42803": "logical", + "42809": "logical", + "42830": "logical", + "42P20": "logical", + "42804": "semantic", + "42846": "semantic", + "42883": "semantic", + "42884": "semantic", + "22005": "semantic", + "22007": "semantic", + "22008": "semantic", + "22012": "semantic", + "22023": "semantic", + "22P02": "semantic", + "22P03": "semantic", + "22P04": "semantic", + "23000": "logical", + "23001": "logical", + "23502": "logical", + "23503": "logical", + "23505": "logical", + "23514": "logical", +} + +# SQLSTATE class prefix (first 2 chars) → fallback category +_SQLSTATE_CLASS_FALLBACK: dict[str, str] = { + "42": "semantic", + "22": "semantic", + "23": "logical", + "28": "semantic", + "2B": "semantic", + "2D": "logical", + "2F": "semantic", + "34": "semantic", + "38": "semantic", + "39": "semantic", + "3B": "logical", + "3D": "semantic", + "3F": "semantic", + "40": "logical", + "44": "logical", + "53": "semantic", + "54": "semantic", + "55": "semantic", + "57": "semantic", + "58": "semantic", + "72": "semantic", + "0A": "semantic", + "XX": "semantic", + "F0": "semantic", + "HV": "semantic", + "P0": "semantic", +} + +# Exact SQLSTATE → single best ErrorTag +_SQLSTATE_TO_TAG: dict[str, ErrorTag] = { + "42601": ErrorTag.SYNTAX_ERROR, + "42602": ErrorTag.INVALID_NAME, + "42702": ErrorTag.AMBIGUOUS_COLUMN, + "42703": ErrorTag.HALLUCINATION_COLUMN, + "42704": ErrorTag.SCHEMA_UNKNOWN_ERROR, + "42P01": ErrorTag.HALLUCINATION_TABLE, + "42803": ErrorTag.GROUPING_ERROR, + "42P20": ErrorTag.WINDOWING_ERROR, + "23502": ErrorTag.INTEGRITY_VIOLATION, + "23503": ErrorTag.FOREIGN_KEY_VIOLATION, + "23505": ErrorTag.UNIQUE_VIOLATION, + "23514": ErrorTag.CHECK_VIOLATION, + "42883": ErrorTag.UNDEFINED_FUNCTION, + "42884": ErrorTag.UNDEFINED_FUNCTION, + "42804": ErrorTag.TYPE_MISMATCH, + "22P02": ErrorTag.VALUE_FORMAT_MISMATCH, + "22012": ErrorTag.VALUE_FORMAT_MISMATCH, +} + +# Error message substrings/patterns → SQLSTATE inference +_ERROR_PATTERNS: dict[str, str] = { + r"syntax error": "42601", + r"unterminated quoted string": "42601", + r"column reference .* is ambiguous": "42702", + r"column reference is ambiguous": "42702", + r"column .* does not exist": "42703", + r"undefined column": "42703", + r"table .* does not exist": "42P01", + r"undefined table": "42P01", + r"table name .* specified more than once": "42712", + r"aggregate function .* cannot contain": "42803", + r"must appear in the group by clause": "42803", + r"window function .* cannot contain": "42P20", + r"argument of .* must be type boolean": "42804", + r"invalid hexadecimal": "22P02", + r"invalid input syntax": "22P02", + r"division by zero": "22012", + r"duplicate key": "23505", + r"foreign key violation": "23503", + r"not null violation": "23502", +} + + +# ─── Public helpers ─────────────────────────────────────────────────────────── + + +def extract_error_code(error_message: str) -> Optional[str]: + """Extract a PostgreSQL SQLSTATE code from an error message string. + + Tries direct SQLSTATE patterns first, then falls back to message content. + Returns None if nothing matches. + """ + pattern = r"(?:SQLSTATE|ERROR)[\s:]*([0-9][0-9A-Z]{4})|\[([0-9][0-9A-Z]{4})\]" + match = re.search(pattern, error_message, re.IGNORECASE) + if match: + return (match.group(1) or match.group(2)).upper() + + msg_lower = error_message.lower() + for pat, code in _ERROR_PATTERNS.items(): + if re.search(pat, msg_lower, re.IGNORECASE): + return code + return None + + +def tag_for_sqlstate(code: Optional[str]) -> Optional[ErrorTag]: + """Single best ErrorTag for a SQLSTATE code, or None.""" + if not code: + return None + return _SQLSTATE_TO_TAG.get(code) + + +def category_for_sqlstate(code: Optional[str]) -> Optional[str]: + """Taxonomy category for a SQLSTATE code (exact match only); None if unknown.""" + if not code: + return None + return _SQLSTATE_TO_CATEGORY.get(code) + + +def category_for_sqlstate_with_fallback(code: Optional[str]) -> Optional[str]: + """Taxonomy category for a SQLSTATE code with class-prefix fallback.""" + if not code: + return None + exact = _SQLSTATE_TO_CATEGORY.get(code) + if exact: + return exact + if len(code) >= 2: + return _SQLSTATE_CLASS_FALLBACK.get(code[:2].upper()) + return None + + +def category_for_tag(tag: "str | ErrorTag") -> Optional[str]: + """Taxonomy category for a tag string or ErrorTag member; None if unrecognised.""" + if isinstance(tag, ErrorTag): + return tag.taxonomy_category + try: + return ErrorTag(tag).taxonomy_category + except ValueError: + # Unknown string tag — try prefix heuristic + prefix = tag.split("_")[0] + return _PREFIX_TO_CATEGORY.get(prefix) diff --git a/src/ast_parsers/validator.py b/src/ast_parsers/validator.py index e5a3691..8a095f8 100644 --- a/src/ast_parsers/validator.py +++ b/src/ast_parsers/validator.py @@ -1,400 +1,1002 @@ # -*- coding: utf-8 -*- -"""SQL validation: syntax (sqlglot) and optional schema-aware semantic checks.""" +""" +SQL validation with a single entry point. -from typing import Optional, Dict, Any + result = validate(sql) # syntax only + result = validate(sql, schema=my_schema) # syntax + schema (static) + result = validate_with_db(sql, engine) # syntax + schema + live EXPLAIN + +Both functions collect ALL errors (syntax AND semantic) simultaneously — +a syntax error no longer prevents schema checks from running. +One function in, one ValidationResult out. +Parses exactly once, runs analyze_query exactly once. +""" + +from __future__ import annotations + +import re +from typing import Dict, List, Optional, Set, Tuple + +# Per-engine live-schema cache: str(engine.url) → {table: {col: type}} +_live_schema_cache: Dict[str, Dict[str, Dict[str, str]]] = {} + + +def invalidate_schema_cache(engine) -> None: + """Clear the cached live schema for *engine* so the next + ``validate_with_db`` call re-reflects the DB. + + Call this after running ``preprocess_sql`` or any DDL that changes + the set of tables visible in the database. + """ + key = str(engine.url) + _live_schema_cache.pop(key, None) import sqlglot from sqlglot import exp -from sqlglot.errors import ParseError -from sqlglot.optimizer import optimize - -from ast_parsers.errors import ( - ValidationResult, - ValidationError, - SyntaxErrorTags, - SchemaErrorTags, -) -from ast_parsers.error_codes import ( +from sqlglot.errors import ErrorLevel, ParseError + +from ast_parsers.query_analyzer import analyze_query +from ast_parsers.result import ValidationError, ValidationResult +from ast_parsers.tags import ( + ErrorTag, extract_error_code, - get_taxonomy_category, - get_taxonomy_category_with_fallback, -) -from ast_parsers.query_analyzer import ( - analyze_query, + tag_for_sqlstate, ) -def validate_syntax( +def validate( sql: str, + schema: Optional[Dict[str, Dict[str, str]]] = None, dialect: str = "postgres", ) -> ValidationResult: - """Validate SQL syntax with sqlglot. Invalid syntax => ast/query_metadata usually None.""" - try: - ast = sqlglot.parse_one(sql, read=dialect) + """ + Validate SQL syntax and (optionally) check against a database schema. + + Unlike the previous implementation this function *does not* stop on the + first error. A query with a recoverable syntax problem still goes through + schema validation so you get the full error picture in one call. + + Args: + sql: SQL query string to validate. + schema: Optional ``{table_name: {column_name: type}}`` dict. + When provided, table existence and column references are + checked even when syntax errors are present (as long as a + partial AST can be recovered). + dialect: SQL dialect (default: ``"postgres"``). + + Returns: + ValidationResult with: + - ``valid`` – True when no errors were found. + - ``errors`` – list of ALL ValidationErrors (syntax + semantic). + - ``query_metadata`` – structural metadata (complexity, clauses, …). + """ + # ── 1. Parse (with recovery) ────────────────────────────────────────────── + ast, syntax_errors = _parse_with_recovery(sql, dialect) + + # ── 2. Detect issues sqlglot silently accepts ───────────────────────────── + silent_errors: List[ValidationError] = [] + schema_errors: List[ValidationError] = [] + metadata = None + + if ast is not None: silent_errors = _detect_silent_fixes(sql) - if silent_errors: - result = ValidationResult(valid=False, errors=silent_errors, ast=ast, sql=sql) - result.query_metadata = analyze_query(ast) - return result - - result = ValidationResult(valid=True, ast=ast, sql=sql) - result.query_metadata = analyze_query(ast) - return result - - except ParseError as e: - errors = _classify_syntax_error(sql, e) - result = ValidationResult(valid=False, errors=errors, sql=sql) - try: - ast = sqlglot.parse_one(sql, read=dialect) - result.ast = ast - result.query_metadata = analyze_query(ast) - except ParseError: - pass - return result - - except Exception as e: - # Catch-all for unexpected parsing errors (including tokenization errors) - # Still try to classify the error based on the SQL content - errors = [] - error_message = str(e) - - # Extract error code; use class fallback when specific code unknown - error_code = extract_error_code(error_message) - taxonomy_category = get_taxonomy_category_with_fallback(error_code) or get_taxonomy_category(error_code) - - if "unterminated" in error_message.lower() or _has_unterminated_string(sql): - errors.append(ValidationError( - tag=SyntaxErrorTags.UNTERMINATED_STRING, - message="Unterminated quoted string", - context=error_message, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - else: - errors.append(ValidationError( - tag=SyntaxErrorTags.SYNTAX_ERROR, - message=error_message, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - - return ValidationResult(valid=False, errors=errors, sql=sql) - - -def _detect_silent_fixes(sql: str) -> list: - """Detect issues sqlglot silently fixes (e.g. trailing comma) via pattern match on original SQL.""" - errors = [] - trailing_pos = _find_trailing_delimiter(sql, "") - if trailing_pos is not None: - errors.append(ValidationError( - tag=SyntaxErrorTags.TRAILING_DELIMITER, - message="Trailing comma or delimiter before keyword", - location=trailing_pos, - context=sql[max(0, trailing_pos-10):trailing_pos+15], - )) - return errors + metadata = analyze_query(ast) + if schema is not None: + schema_errors = _check_schema(ast, schema, sql) + + all_errors = syntax_errors + silent_errors + schema_errors + return ValidationResult( + valid=len(all_errors) == 0, + sql=sql, + errors=all_errors, + query_metadata=metadata, + ) + + +def validate_with_db( + sql: str, + engine, # sqlalchemy.engine.Engine — not typed to avoid hard dep at import + schema: Optional[Dict[str, Dict[str, str]]] = None, + dialect: str = "postgres", +) -> ValidationResult: + """ + Full validation pipeline using a live PostgreSQL database. + + Error collection strategy (all run independently, then merged): + + 1. **Syntax** — ``_parse_with_recovery()`` classifies parse errors and + attempts WARN-level recovery to get a partial AST. + 2. **Token schema** — ``_extract_identifiers_from_tokens()`` walks the + sqlglot token stream (never throws on broken SQL) to extract table and + column candidates, then checks them against the live DB schema. This + fires even when the AST is too broken to use. + 3. **AST schema** — ``_check_schema()`` does a precise alias-resolved + column walk when the AST is available. More accurate than the token + check for qualified references. + 4. **EXPLAIN** — ``EXPLAIN {sql}`` on the live DB catches whatever the + above miss (type errors, permission issues, constraint violations) at + the cost of reporting only the *first* server error. + + All four lists are merged and deduplicated. EXPLAIN errors take priority; + AST-schema errors supersede token-schema errors for the same identifier. + + Args: + sql: SQL query string. + engine: SQLAlchemy ``Engine`` connected to the target database. + schema: Ignored — the live DB schema is always used. Kept for + backward compatibility with call sites that pass a JSON schema. + dialect: SQL dialect for the static parser (default: ``"postgres"``). + + Returns: + ValidationResult with ``valid=True`` only when all checks pass. + """ + # ── 1. Syntax + partial AST ─────────────────────────────────────────────── + ast, syntax_errors = _parse_with_recovery(sql, dialect) + silent_errors = _detect_silent_fixes(sql) if ast is not None else [] + metadata = analyze_query(ast) if ast is not None else None + + # ── 2. Live schema from DB (cached per engine URL) ──────────────────────── + live_schema = _get_live_schema(engine) + + # ── 3. Token-stream schema check (always runs, AST-independent) ────────── + table_cands, col_cands = _extract_identifiers_from_tokens(sql) + token_schema_errors = _check_identifiers_against_schema( + table_cands, col_cands, live_schema + ) + + # ── 4. AST schema check (precise, only when AST is good) ───────────────── + ast_schema_errors: List[ValidationError] = [] + if ast is not None: + ast_schema_errors = _check_schema(ast, live_schema, sql) + # Discard noisy token errors — the AST parser understands CTEs, + # subquery aliases, and table aliases; the token scanner does not. + token_schema_errors = [] + + # ── 5. EXPLAIN — DB-native first error ─────────────────────────────────── + db_errors = _explain(sql, engine) + + # ── 6. EXPLAIN-success suppression ──────────────────────────────────────── + # If EXPLAIN says the query is valid, the static schema checks may have + # produced false positives (e.g. CTE-output columns, table-valued + # functions). PostgreSQL is the ground truth — drop schema errors. + # Syntax and silent errors are kept: they flag style issues (trailing + # commas, etc.) that PostgreSQL silently accepts but are still wrong. + if not db_errors: + ast_schema_errors = [] + token_schema_errors = [] + + # ── 7. Cascade suppression ──────────────────────────────────────────────── + # If EXPLAIN flagged a table as missing (SQLSTATE 42P01), suppress any + # AST-level column errors for columns of that same table — they're + # guaranteed downstream noise, not independent errors. + missing_tables_from_explain: Set[str] = set() + for e in db_errors: + if e.error_code == "42P01" and e.context: + # Try to extract the table name from the error message + msg_lower = e.message.lower() if e.message else "" + # Pattern: relation "table_name" does not exist + import re + rel_match = re.search(r'relation "([^"]+)"', msg_lower) + if rel_match: + missing_tables_from_explain.add(rel_match.group(1).lower()) + + if missing_tables_from_explain: + ast_schema_errors = [ + e for e in ast_schema_errors + if not ( + e.tag == ErrorTag.HALLUCINATION_COLUMN + and e.context + and any( + mt in e.context.lower() or mt in (e.message or "").lower() + for mt in missing_tables_from_explain + ) + ) + ] + + # ── 8. Merge, deduplicate by (tag, context) ─────────────────────────────── + # Priority: EXPLAIN > AST-schema > token-schema > syntax > silent + all_errors = _merge_errors( + db_errors, + ast_schema_errors, + token_schema_errors, + syntax_errors, + silent_errors, + ) + + return ValidationResult( + valid=len(all_errors) == 0, + sql=sql, + errors=all_errors, + query_metadata=metadata, + ) + + +# ─── Internal: parsing ──────────────────────────────────────────────────────── + + +def _parse_with_recovery( + sql: str, dialect: str +) -> Tuple[Optional[exp.Expression], List[ValidationError]]: + """ + Try strict parse first. If that fails, collect syntax errors and then + retry with ErrorLevel.WARN to get a partial AST so that schema checks can + still run on the remainder of the query. + + Supports multi-statement SQL (e.g. ``DROP TABLE ...; CREATE TABLE ...``) + by using ``sqlglot.parse()`` which returns a list of ASTs. The first + non-DDL AST is returned for schema checking (DDL like CREATE/DROP doesn't + need column-level validation). + + Returns: (ast_or_None, syntax_errors) + """ + try: + # parse() returns List[Optional[Expression]] + asts = sqlglot.parse(sql, read=dialect, error_level=ErrorLevel.RAISE) + # Pick the best AST for schema checking: prefer SELECT/DML over DDL + best = None + for a in asts: + if a is None: + continue + if best is None: + best = a + # Prefer non-DDL (SELECT, INSERT, UPDATE, DELETE) for schema checks + if not isinstance(a, (exp.Create, exp.Drop, exp.Command)): + best = a + break + return best, [] + except ParseError as exc: + syntax_errors = _classify_parse_error(sql, exc) + except Exception as exc: + syntax_errors = _classify_generic_error(sql, exc) + + # Recovery attempt — get a partial AST even though syntax is broken + try: + asts = sqlglot.parse(sql, read=dialect, error_level=ErrorLevel.WARN) + best = None + for a in asts: + if a is None: + continue + if best is None: + best = a + if not isinstance(a, (exp.Create, exp.Drop, exp.Command)): + best = a + break + ast = best + except Exception: + ast = None + + return ast, syntax_errors + + +# ─── Internal: silent-fix detection ────────────────────────────────────────── + + +def _detect_silent_fixes(sql: str) -> List[ValidationError]: + """Return errors for patterns sqlglot silently accepts but that are wrong.""" + errors: List[ValidationError] = [] + + pos = _find_trailing_delimiter(sql) + if pos is not None: + errors.append( + ValidationError( + tag=ErrorTag.TRAILING_DELIMITER, + message="Trailing comma or delimiter before keyword", + location=pos, + context=sql[max(0, pos - 10) : pos + 15], + ) + ) + return errors # one silent-fix error at a time is enough + if _has_empty_select(sql): - errors.append(ValidationError( - tag=SyntaxErrorTags.KEYWORD_MISUSE, - message="SELECT clause has no columns specified", - )) - return errors + errors.append( + ValidationError( + tag=ErrorTag.KEYWORD_MISUSE, + message="SELECT clause has no columns specified", + ) + ) return errors -def _has_empty_select(sql: str) -> bool: - """Check if SQL has SELECT immediately followed by FROM (no columns).""" - import re - # Match SELECT followed by optional whitespace, then FROM - pattern = r'\bSELECT\s+FROM\b' - return bool(re.search(pattern, sql, re.IGNORECASE)) - - -def _classify_syntax_error(sql: str, error: ParseError) -> list: - """Classify ParseError into one tag from message and SQL context.""" - error_message = str(error) - errors = [] - location = getattr(error, "col", None) - error_code = extract_error_code(error_message) - taxonomy_category = get_taxonomy_category(error_code) - if _has_unbalanced_tokens(sql): - errors.append(ValidationError( - tag=SyntaxErrorTags.UNBALANCED_TOKENS, - message="Unbalanced parentheses or brackets", - location=location, - context=_get_unbalanced_context(sql), - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - return errors - - # 2. Check for trailing delimiters (common LLM error) - trailing_pos = _find_trailing_delimiter(sql, error_message) - if trailing_pos is not None: - errors.append(ValidationError( - tag=SyntaxErrorTags.TRAILING_DELIMITER, - message="Trailing comma or delimiter before keyword", - location=trailing_pos, - context=sql[max(0, trailing_pos-10):trailing_pos+10], - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - if "unterminated" in error_message.lower() or _has_unterminated_string(sql): - errors.append(ValidationError( - tag=SyntaxErrorTags.UNTERMINATED_STRING, - message="Unterminated quoted string", - location=location, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - return errors - - msg_lower = error_message.lower() - if not errors and ("expecting )" in msg_lower or "expecting (" in msg_lower): - errors.append(ValidationError( - tag=SyntaxErrorTags.UNBALANCED_TOKENS, - message=error_message, - location=location, - context="Parser reported expecting parenthesis", - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - if not errors and ("unexpected token" in msg_lower or "invalid expression" in msg_lower): - errors.append(ValidationError( - tag=SyntaxErrorTags.INVALID_TOKEN, - message=error_message, - location=location, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - if not errors and ( - "unknown option" in msg_lower - or "unsupported syntax" in msg_lower - or "falling back to parsing as" in msg_lower - ): - errors.append(ValidationError( - tag=SyntaxErrorTags.UNSUPPORTED_DIALECT, - message=error_message, - location=location, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) - if not errors: - errors.append(ValidationError( - tag=SyntaxErrorTags.KEYWORD_MISUSE, - message=error_message, - location=location, - error_code=error_code, - taxonomy_category=taxonomy_category or "syntax", - )) +# ─── Internal: schema checks ────────────────────────────────────────────────── - return errors +def _check_schema( + ast: exp.Expression, + schema: Dict[str, Dict[str, str]], + sql: str = "", +) -> List[ValidationError]: + """ + Check table and column references against the schema dict. + + Replaces the previous ``sqlglot.optimize()``-based implementation which + lowercased column names before comparison and therefore missed hallucinated + columns whose schema keys contain spaces or mixed-case characters (e.g. + ``"County Code"``). + + This implementation: + * Walks ``exp.Column`` nodes directly — no optimizer involvement. + * Compares names case-insensitively via ``.lower()``. + * Builds an alias map from ``exp.Table`` nodes so qualified references like + ``t1.column_name`` are resolved correctly. + * Reports the enclosing SQL clause for each error via ``_clause_of()``. + """ + errors: List[ValidationError] = [] + + # ── Normalised schema lookup ────────────────────────────────────────────── + # schema_lower: {table_lower -> {col_lower -> original_col_name}} + schema_lower: Dict[str, Dict[str, str]] = { + t.lower(): {c.lower(): c for c in cols} for t, cols in schema.items() + } + + # ── PostgreSQL system schemas — never flag as hallucinated ───────────────── + _PG_SYSTEM_PREFIXES = ("pg_", "information_schema") + + # ── PostgreSQL built-in SRFs and catalog objects used in FROM clauses ────── + _PG_BUILTIN_SRFS = { + # Set-returning functions commonly used in FROM + "generate_series", "unnest", "regexp_split_to_table", + "json_array_elements", "json_array_elements_text", + "jsonb_array_elements", "jsonb_array_elements_text", + "json_each", "json_each_text", "jsonb_each", "jsonb_each_text", + "json_to_record", "jsonb_to_record", "json_to_recordset", "jsonb_to_recordset", + "json_populate_record", "jsonb_populate_record", + "json_populate_recordset", "jsonb_populate_recordset", + "regexp_matches", "string_to_array", "xpath", + "ts_stat", "ts_token_type", "ts_parse", + "aclexplode", "pg_get_keywords", "pg_options_to_table", + # System catalog tables/views + "pg_class", "pg_attribute", "pg_constraint", "pg_namespace", + "pg_index", "pg_type", "pg_am", "pg_tablespace", "pg_stat_activity", + "pg_stat_user_tables", "pg_stat_all_tables", "pg_roles", + "pg_database", "pg_proc", "pg_description", "pg_depend", + "pg_catalog", "pg_tables", "pg_views", "pg_sequences", + } + + # ── Collect CTE aliases so they are never flagged as missing tables ──────── + cte_aliases: Set[str] = set() + for cte_node in ast.find_all(exp.CTE): + if cte_node.alias: + cte_aliases.add(cte_node.alias.lower()) + + # ── Collect subquery aliases (these are also virtual tables) ────────────── + for sq_node in ast.find_all(exp.Subquery): + if sq_node.alias: + cte_aliases.add(sq_node.alias.lower()) + + # ── Alias map: {alias_or_table_lower -> real_table_lower} ───────────────── + # All tables (including those inside CTEs) for resolving qualified refs. + alias_map: Dict[str, str] = {} + # All table/subquery aliases (used to skip whole-row alias refs like + # row_to_json(alias) where sqlglot parses 'alias' as a Column). + all_table_aliases: Set[str] = set() + # Inline column definitions from SRFs and VALUES (e.g. AS j(element)) + # These are dynamically-named columns valid in their scope. + inline_columns: Set[str] = set() + # Tables referenced in the OUTER query only (not inside CTE bodies). + outer_tables: Set[str] = set() + for table_node in ast.find_all(exp.Table): + real = table_node.name.lower() + if real: + alias_map[real] = real + ta = table_node.args.get("alias") + if ta: + alias_map[ta.alias.lower()] = real + all_table_aliases.add(ta.alias.lower()) + # Collect inline column defs: AS j(element, value, ...) + for col_id in ta.args.get("columns") or []: + if isinstance(col_id, exp.Identifier): + inline_columns.add(col_id.name.lower()) + # Track whether this table ref is in the outer query + if real and not table_node.find_ancestor(exp.CTE): + outer_tables.add(real) + # Also include subquery aliases and their inline columns + for sq_node in ast.find_all(exp.Subquery): + ta = sq_node.args.get("alias") + if ta: + all_table_aliases.add(ta.alias.lower()) + for col_id in ta.args.get("columns") or []: + if isinstance(col_id, exp.Identifier): + inline_columns.add(col_id.name.lower()) + + # ── 1. Table existence ──────────────────────────────────────────────────── + missing_tables_lower: Set[str] = set() + for table_node in ast.find_all(exp.Table): + t = table_node.name.lower() + if not t: + continue + # Skip tables inside DDL statements (CREATE FUNCTION, CREATE VIEW, etc.) + if table_node.find_ancestor(exp.Create, exp.Command): + continue + # Skip PostgreSQL system tables / schemas + if any(t.startswith(p) for p in _PG_SYSTEM_PREFIXES): + continue + # Skip PostgreSQL built-in SRFs and catalog objects + if t in _PG_BUILTIN_SRFS: + continue + # Skip if the table's schema qualifier is a system schema + table_db = table_node.args.get("db") + if table_db and isinstance(table_db, exp.Identifier): + if any(table_db.name.lower().startswith(p) for p in _PG_SYSTEM_PREFIXES): + continue + if t not in schema_lower and t not in cte_aliases: + missing_tables_lower.add(t) + errors.append( + ValidationError( + tag=ErrorTag.HALLUCINATION_TABLE, + message=f"Table '{table_node.name}' does not exist in schema", + context=table_node.name, + affected_clauses=["FROM"], + ) + ) + + # ── 2. Column references ────────────────────────────────────────────────── + # Only check unqualified columns against outer-query schema tables. + # CTE/subquery aliases, missing tables, and tables with unknown columns + # (empty dict from CTAS parsing) are excluded. + schema_tables: Set[str] = { + t for t in outer_tables + if t in schema_lower + and t not in missing_tables_lower + and len(schema_lower[t]) > 0 # skip tables with unknown columns + } + + # ── Collect SELECT-level aliases (e.g. `COUNT(x) AS answered`) ──────────── + # These are valid column references in ORDER BY, HAVING, etc. + select_aliases: Set[str] = set() + for select_node in ast.find_all(exp.Select): + for sel_expr in select_node.expressions: + if isinstance(sel_expr, exp.Alias) and sel_expr.alias: + select_aliases.add(sel_expr.alias.lower()) + + for col_node in ast.find_all(exp.Column): + # Skip literal * (e.g. SELECT t.* — sqlglot parses * as Column name) + if col_node.name == "*": + continue + # Skip columns inside CTE definitions — they reference + # CTE-scoped expressions, not base schema columns + if col_node.find_ancestor(exp.CTE): + continue + + col_name: str = col_node.name # bare column string, original case + qualifier: str = col_node.table # syntactic qualifier (alias/table), if any + + col_lower = col_name.lower() + + # Skip references to SELECT-level aliases (e.g. ORDER BY answered) + if col_lower in select_aliases: + continue + + # Skip inline column defs from SRFs/VALUES (e.g. AS j(element)) + if col_lower in inline_columns: + continue + + # Skip template variables (${var}) that sqlglot misparses as columns + if f"${{{col_name}}}" in sql or f"${{{col_lower}}}" in sql: + continue + + # Skip whole-row table alias references (e.g. row_to_json(alias)) + if not qualifier and col_lower in all_table_aliases: + continue + if not qualifier and col_lower in cte_aliases: + continue + + if qualifier: + # Qualified reference: resolve alias → real table + resolved = alias_map.get(qualifier.lower()) + if resolved is None or qualifier.lower() in cte_aliases: + # Unknown qualifier or CTE/subquery alias — skip + continue + if resolved in cte_aliases: + # Resolved table is a CTE — can't validate its columns statically + continue + if resolved in missing_tables_lower: + # Table is already flagged as missing — skip its columns + continue + table_cols = schema_lower.get(resolved, {}) + if not table_cols: + # Table exists but columns are unknown (e.g. CTAS) — skip + continue + if col_lower not in table_cols: + clause = _clause_of(col_node) + errors.append( + ValidationError( + tag=ErrorTag.HALLUCINATION_COLUMN, + message=( + f"Column '{col_name}' does not exist in table " + f"'{resolved}' (referenced as '{qualifier}.{col_name}')" + ), + context=f"{qualifier}.{col_name}", + affected_clauses=[clause] if clause else [], + ) + ) + else: + # Unqualified reference: check against schema tables only + # (not CTE/subquery aliases which aren't in the schema) + if not schema_tables: + # All referenced tables are CTEs/subqueries — can't validate + continue + + found_in = [ + t for t in schema_tables + if col_lower in schema_lower.get(t, {}) + ] + + if not found_in: + clause = _clause_of(col_node) + errors.append( + ValidationError( + tag=ErrorTag.HALLUCINATION_COLUMN, + message=( + f"Column '{col_name}' does not exist in any " + f"referenced table" + ), + context=col_name, + affected_clauses=[clause] if clause else [], + ) + ) + elif len(found_in) > 1: + clause = _clause_of(col_node) + errors.append( + ValidationError( + tag=ErrorTag.AMBIGUOUS_COLUMN, + message=( + f"Column '{col_name}' is ambiguous — exists in " + f"tables: {', '.join(found_in)}" + ), + context=col_name, + affected_clauses=[clause] if clause else [], + ) + ) -def _has_unbalanced_tokens(sql: str) -> bool: - parens = sql.count('(') - sql.count(')') - brackets = sql.count('[') - sql.count(']') - return parens != 0 or brackets != 0 + return errors -def _get_unbalanced_context(sql: str) -> str: - """Describe which parens/brackets are unbalanced.""" - parens_diff = sql.count('(') - sql.count(')') - brackets_diff = sql.count('[') - sql.count(']') - - parts = [] - if parens_diff > 0: - parts.append(f"{parens_diff} unclosed '('") - elif parens_diff < 0: - parts.append(f"{-parens_diff} extra ')'") - - if brackets_diff > 0: - parts.append(f"{brackets_diff} unclosed '['") - elif brackets_diff < 0: - parts.append(f"{-brackets_diff} extra ']'") - - return ", ".join(parts) if parts else "unknown imbalance" - - -def _find_trailing_delimiter(sql: str, error_message: str) -> Optional[int]: - """Return position of trailing comma before keyword (e.g. SELECT a, FROM t).""" - import re - keywords = ['FROM', 'WHERE', 'GROUP', 'ORDER', 'HAVING', 'LIMIT', 'UNION', 'JOIN'] - sql_upper = sql.upper() - for keyword in keywords: - pattern = rf',\s+{re.escape(keyword)}\b' - match = re.search(pattern, sql_upper) - if match: - comma_pos = match.start() - before_comma = sql[:comma_pos].rstrip() - if before_comma and before_comma[-1].isalnum(): - return comma_pos +def _clause_of(node: exp.Expression) -> Optional[str]: + """Walk parent chain to find the name of the enclosing SQL clause.""" + _CLAUSE_MAP = { + exp.Select: "SELECT", + exp.From: "FROM", + exp.Where: "WHERE", + exp.Join: "JOIN", + exp.Having: "HAVING", + exp.Group: "GROUP BY", + exp.Order: "ORDER BY", + } + curr = node.parent + while curr is not None: + for clause_type, name in _CLAUSE_MAP.items(): + if isinstance(curr, clause_type): + return name + curr = curr.parent return None -def _has_unterminated_string(sql: str) -> bool: - """Heuristic: odd quote count. May misclassify with '' or backslash; parser message is primary.""" - single_quotes = sql.count("'") - sql.count("\\'") * 2 - double_quotes = sql.count('"') - sql.count('\\"') * 2 - return single_quotes % 2 != 0 or double_quotes % 2 != 0 +# ─── Internal: live DB validation ──────────────────────────────────────────── + + +def _get_live_schema(engine) -> Dict[str, Dict[str, str]]: + """ + Reflect the full schema from the live database and cache it by engine URL. + + Returns ``{table_name: {column_name: sql_type}}`` — same format as the + JSON schema files so it can be passed to ``_check_schema()`` directly. + """ + key = str(engine.url) + if key not in _live_schema_cache: + from sqlalchemy import MetaData as SAMetaData + + meta = SAMetaData() + meta.reflect(bind=engine) + _live_schema_cache[key] = { + table_name: {col.name: str(col.type) for col in table_obj.columns} + for table_name, table_obj in meta.tables.items() + } + return _live_schema_cache[key] -def validate_schema( +def _extract_identifiers_from_tokens( sql: str, +) -> Tuple[List[str], List[str]]: + """ + Walk the sqlglot token stream (which **never throws** on broken SQL) and + extract: + + * ``table_candidates`` — bare identifiers immediately following a + ``FROM``, ``JOIN``, or ``INTO`` keyword. + * ``col_candidates`` — all double-quoted ``IDENTIFIER`` tokens that are + *not* in a table-name position. Double-quoted tokens in PostgreSQL are + always object names, so false positives are near-zero. + + This is intentionally simple and positional — it is not a full SQL + parser. Its job is to catch hallucinated names when the AST is too + broken to use. + """ + from sqlglot.tokens import Tokenizer as _Tokenizer + from sqlglot.tokens import TokenType + + try: + toks = _Tokenizer().tokenize(sql) + except Exception: + return [], [] + + TABLE_TRIGGERS: Set = { + TokenType.FROM, + TokenType.JOIN, + TokenType.INTO, + } + # Token types to skip between a trigger and the actual table name + SKIP_TYPES: Set = {TokenType.L_PAREN} + + table_candidates: List[str] = [] + table_positions: Set[int] = set() + + i = 0 + while i < len(toks): + tok = toks[i] + if tok.token_type in TABLE_TRIGGERS: + j = i + 1 + while j < len(toks) and toks[j].token_type in SKIP_TYPES: + j += 1 + if j < len(toks) and toks[j].token_type in ( + TokenType.VAR, + TokenType.IDENTIFIER, + ): + table_candidates.append(toks[j].text) + table_positions.add(j) + i += 1 + + # Second pass: double-quoted IDENTIFIER tokens not in table positions + col_candidates: List[str] = [ + toks[idx].text + for idx, tok in enumerate(toks) + if tok.token_type == TokenType.IDENTIFIER and idx not in table_positions + ] + + return table_candidates, col_candidates + + +def _check_identifiers_against_schema( + table_cands: List[str], + col_cands: List[str], schema: Dict[str, Dict[str, str]], - dialect: str = "postgres", -) -> ValidationResult: - """Validate SQL against schema (tables/columns); requires valid syntax first.""" - syntax_result = validate_syntax(sql, dialect=dialect) - if not syntax_result.valid: - # Return syntax errors immediately - can't validate schema on invalid SQL - return syntax_result - - # Get the parsed AST from syntax validation - parsed = syntax_result.ast - if parsed is None: - # This shouldn't happen if syntax_result.valid is True, but handle it - error = ValidationError( - tag=SyntaxErrorTags.SYNTAX_ERROR, - message="Failed to parse SQL for schema validation", - ) - return ValidationResult(valid=False, errors=[error], sql=sql) - - errors = [] - missing_tables = _check_tables_exist(parsed, schema) - for table_name in missing_tables: - error_code = extract_error_code(f"table {table_name} does not exist") - taxonomy_category = get_taxonomy_category(error_code) - errors.append(ValidationError( - tag=SchemaErrorTags.HALLUCINATION_TABLE, - message=f"Table '{table_name}' does not exist in schema", - context=table_name, - error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - affected_clauses=["FROM"], - )) - if missing_tables: - result = ValidationResult(valid=False, errors=errors, ast=parsed, sql=sql) - result.query_metadata = analyze_query(parsed) - return result +) -> List[ValidationError]: + """ + Check token-extracted table and column candidates against the live schema. + + Column candidates are checked against the union of columns in all + *valid* referenced tables. When every referenced table is hallucinated + (nothing valid found) the column check falls back to the full schema so + we still report columns that don't exist anywhere. + """ + errors: List[ValidationError] = [] + schema_lower: Dict[str, Set[str]] = { + t.lower(): {c.lower() for c in cols} for t, cols in schema.items() + } + + valid_tables: Set[str] = set() + for t in table_cands: + if t.lower() in schema_lower: + valid_tables.add(t.lower()) + else: + errors.append( + ValidationError( + tag=ErrorTag.HALLUCINATION_TABLE, + message=f"Table '{t}' does not exist in the database", + context=t, + affected_clauses=["FROM"], + ) + ) + + # If we found valid tables, restrict column search to those; otherwise + # search the whole schema so we don't miss anything. + search_cols: Set[str] = set() + for t in valid_tables if valid_tables else schema_lower.keys(): + search_cols.update(schema_lower.get(t, set())) + + for col in col_cands: + if col.lower() not in search_cols: + errors.append( + ValidationError( + tag=ErrorTag.HALLUCINATION_COLUMN, + message=f"Column '{col}' does not exist in the database", + context=col, + ) + ) + + return errors + + +def _merge_errors(*error_lists: List[ValidationError]) -> List[ValidationError]: + """ + Merge multiple error lists, deduplicating by ``(tag, context_lower)``. + + Lists are processed in order; earlier lists have priority (their entry + wins when two errors share tag + normalised context). + """ + seen: Set[Tuple[ErrorTag, str]] = set() + merged: List[ValidationError] = [] + for lst in error_lists: + for err in lst: + key = (err.tag, (err.context or "").lower()) + if key not in seen: + seen.add(key) + merged.append(err) + return merged + + +def _explain(sql: str, engine) -> List[ValidationError]: + """ + Run a safe 'dry run' on the live database. + Uses EXPLAIN for DML to avoid long execution times, and + BEGIN -> Execute -> ROLLBACK for DDL to validate syntax and schema. + """ try: - optimize( - parsed, - schema=schema, - dialect=dialect, - validate_qualify_columns=True, - ) - except sqlglot.errors.OptimizeError as e: - column_errors = _classify_schema_error(str(e), ast=parsed) - errors.extend(column_errors) - except Exception as e: - # Catch other optimization errors - error_code = extract_error_code(str(e)) - taxonomy_category = get_taxonomy_category(error_code) - errors.append(ValidationError( - tag=SchemaErrorTags.UNKNOWN_ERROR, - message=str(e), - error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - )) - - result = ValidationResult( - valid=len(errors) == 0, - errors=errors, - ast=parsed, - sql=sql, - ) - result.query_metadata = analyze_query(parsed) - return result - - -def _check_tables_exist(parsed: exp.Expression, schema: Dict) -> list: - missing = [] - schema_lower = {k.lower(): v for k, v in schema.items()} - for table in parsed.find_all(exp.Table): - if table.name.lower() not in schema_lower: - missing.append(table.name) - - return missing - - -def _classify_schema_error(error_message: str, ast: Optional[Any] = None) -> list: - """Classify schema/optimize error into one tag; optional ast for affected_clauses.""" - errors = [] - msg_lower = error_message.lower() - error_code = extract_error_code(error_message) - taxonomy_category = get_taxonomy_category(error_code) - affected_clauses = [] - if ast is not None: - try: - from ast_parsers.query_analyzer import extract_sql_clauses - all_clauses = extract_sql_clauses(ast) - if any(c in all_clauses for c in ["WHERE", "JOIN"]): - affected_clauses = [c for c in ["WHERE", "JOIN"] if c in all_clauses] - elif "SELECT" in all_clauses: - affected_clauses = ["SELECT"] - except Exception: - pass - if ("column" in msg_lower and "could not be resolved" in msg_lower) or \ - "unknown column" in msg_lower or \ - ("column" in msg_lower and "not found" in msg_lower): - errors.append(ValidationError( - tag=SchemaErrorTags.HALLUCINATION_COLUMN, - message=error_message, - error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - affected_clauses=affected_clauses, - )) - elif "ambiguous" in msg_lower: - errors.append(ValidationError( - tag=SchemaErrorTags.AMBIGUOUS_COLUMN, - message=error_message, - error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - affected_clauses=affected_clauses, - )) - elif "type" in msg_lower: - errors.append(ValidationError( - tag=SchemaErrorTags.TYPE_MISMATCH, - message=error_message, + from sqlalchemy import text as sa_text + + with engine.connect() as conn: + # Open a transaction so we can safely roll back any execution + trans = conn.begin() + try: + # Set a short timeout so a bad query doesn't hang the benchmark + conn.execute(sa_text("SET statement_timeout = '2s'")) + + # Check what kind of query this is + sql_upper = sql.lstrip().upper() + is_dml = sql_upper.startswith( + ("SELECT", "INSERT", "UPDATE", "DELETE", "WITH", "VALUES") + ) + + if is_dml: + # Fast and safe plan generation + conn.execute(sa_text(f"EXPLAIN {sql}")) + else: + # Actual execution for CREATE, DROP, ALTER, DO, etc. + conn.execute(sa_text(sql)) + finally: + # NEVER commit. Always roll back to keep the DB pristine + # for the next query in the benchmark. + trans.rollback() + return [] + except Exception as exc: + # Extract PostgreSQL SQLSTATE + message when available + orig = getattr(exc, "orig", None) + sqlstate: Optional[str] = None + pg_message: str = str(exc) + + if orig is not None: + sqlstate = getattr(orig, "pgcode", None) + pg_message = getattr(orig, "pgerror", None) or str(exc) + else: + sqlstate = extract_error_code(str(exc)) + + tag = tag_for_sqlstate(sqlstate) or _infer_tag_from_explain_message(pg_message) + + # 57014 = QueryCanceled (statement_timeout). This is infra noise — + # the query is structurally valid but just too slow to EXPLAIN. + if sqlstate == "57014": + return [] + + return [ + ValidationError( + tag=tag, + message=_clean_pg_message(pg_message), + error_code=sqlstate, + context="PostgreSQL EXPLAIN", + ) + ] + + +def _infer_tag_from_explain_message(message: str) -> ErrorTag: + """Heuristic tag mapping when no SQLSTATE is available.""" + msg = message.lower() + if "column" in msg and ("does not exist" in msg or "not found" in msg): + return ErrorTag.HALLUCINATION_COLUMN + if "relation" in msg and "does not exist" in msg: + return ErrorTag.HALLUCINATION_TABLE + if "syntax error" in msg: + return ErrorTag.SYNTAX_ERROR + if "operator does not exist" in msg or "type" in msg: + return ErrorTag.TYPE_MISMATCH + if "ambiguous" in msg: + return ErrorTag.AMBIGUOUS_COLUMN + return ErrorTag.SCHEMA_UNKNOWN_ERROR + + +def _clean_pg_message(message: str) -> str: + """Strip leading ERROR: / DETAIL: boilerplate from a PostgreSQL error string.""" + lines = [] + for line in message.splitlines(): + stripped = re.sub(r"^(ERROR|DETAIL|HINT|CONTEXT):\s*", "", line.strip()) + if stripped: + lines.append(stripped) + return " | ".join(lines) if lines else message + + +# ─── Internal: syntax error classification ─────────────────────────────────── + + +def _classify_parse_error(sql: str, exc: ParseError) -> List[ValidationError]: + """Map a sqlglot ParseError to one or more ValidationErrors.""" + msg = str(exc) + msg_lower = msg.lower() + location = getattr(exc, "col", None) + error_code = extract_error_code(msg) + + if "unterminated" in msg_lower or _has_unterminated_string(sql): + return [ + ValidationError( + tag=ErrorTag.UNTERMINATED_STRING, + message="Unterminated quoted string", + location=location, + context=msg, + error_code=error_code, + ) + ] + + if _has_unbalanced_tokens(sql): + return [ + ValidationError( + tag=ErrorTag.UNBALANCED_TOKENS, + message="Unbalanced parentheses or brackets", + location=location, + context=_describe_imbalance(sql), + error_code=error_code, + ) + ] + + pos = _find_trailing_delimiter(sql) + if pos is not None: + return [ + ValidationError( + tag=ErrorTag.TRAILING_DELIMITER, + message="Trailing comma or delimiter before keyword", + location=pos, + context=sql[max(0, pos - 10) : pos + 10], + error_code=error_code, + ) + ] + + if "expecting )" in msg_lower or "expecting (" in msg_lower: + return [ + ValidationError( + tag=ErrorTag.UNBALANCED_TOKENS, + message=msg, + location=location, + context="Parser reported expecting parenthesis", + error_code=error_code, + ) + ] + + if "unexpected token" in msg_lower or "invalid expression" in msg_lower: + return [ + ValidationError( + tag=ErrorTag.INVALID_TOKEN, + message=msg, + location=location, + error_code=error_code, + ) + ] + + if "unsupported syntax" in msg_lower or "falling back to parsing as" in msg_lower: + return [ + ValidationError( + tag=ErrorTag.UNSUPPORTED_DIALECT, + message=msg, + location=location, + error_code=error_code, + ) + ] + + return [ + ValidationError( + tag=ErrorTag.KEYWORD_MISUSE, + message=msg, + location=location, error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - affected_clauses=affected_clauses, - )) - else: - errors.append(ValidationError( - tag=SchemaErrorTags.UNKNOWN_ERROR, - message=error_message, + ) + ] + + +def _classify_generic_error(sql: str, exc: Exception) -> List[ValidationError]: + """Map unexpected non-ParseError exceptions to ValidationErrors.""" + msg = str(exc) + error_code = extract_error_code(msg) + if "unterminated" in msg.lower() or _has_unterminated_string(sql): + return [ + ValidationError( + tag=ErrorTag.UNTERMINATED_STRING, + message="Unterminated quoted string", + context=msg, + error_code=error_code, + ) + ] + return [ + ValidationError( + tag=ErrorTag.SYNTAX_ERROR, + message=msg, error_code=error_code, - taxonomy_category=taxonomy_category or "semantic", - affected_clauses=affected_clauses, - )) - - return errors + ) + ] -# ============================================================================= -# Combined Validator (Main Entry Point) -# ============================================================================= +# ─── Internal: SQL text helpers ────────────────────────────────────────────── -def validate_query( - sql: str, - schema: Optional[Dict[str, Dict[str, str]]] = None, - dialect: str = "postgres", -) -> ValidationResult: - """Main entry: syntax validation always; schema validation if schema provided.""" - syntax_result = validate_syntax(sql, dialect=dialect) - if not syntax_result.valid: - return syntax_result - if schema is not None: - schema_result = validate_schema(sql, schema, dialect=dialect) - if schema_result.ast is None: - schema_result.ast = syntax_result.ast - if schema_result.query_metadata is None and schema_result.ast is not None: - schema_result.query_metadata = analyze_query(schema_result.ast) - return schema_result - if syntax_result.query_metadata is None and syntax_result.ast is not None: - syntax_result.query_metadata = analyze_query(syntax_result.ast) - - return syntax_result + +def _find_trailing_delimiter(sql: str) -> Optional[int]: + """Return character position of a trailing comma before a keyword, or None.""" + sql_upper = sql.upper() + for kw in ("FROM", "WHERE", "GROUP", "ORDER", "HAVING", "LIMIT", "UNION", "JOIN"): + match = re.search(rf",\s+{re.escape(kw)}\b", sql_upper) + if match: + pos = match.start() + before = sql[:pos].rstrip() + if before and before[-1].isalnum(): + return pos + return None + + +def _has_empty_select(sql: str) -> bool: + return bool(re.search(r"\bSELECT\s+FROM\b", sql, re.IGNORECASE)) + + +def _has_unbalanced_tokens(sql: str) -> bool: + """Count paren/bracket depth while skipping string literals.""" + depth_paren = 0 + depth_bracket = 0 + in_string = False + i = 0 + while i < len(sql): + ch = sql[i] + if in_string: + if ch == "'" and i + 1 < len(sql) and sql[i + 1] == "'": + i += 2 + continue + elif ch == "'": + in_string = False + else: + if ch == "'": + in_string = True + elif ch == "(": + depth_paren += 1 + elif ch == ")": + depth_paren -= 1 + elif ch == "[": + depth_bracket += 1 + elif ch == "]": + depth_bracket -= 1 + i += 1 + return depth_paren != 0 or depth_bracket != 0 + + +def _describe_imbalance(sql: str) -> str: + """Human-readable description of which tokens are unbalanced.""" + p = sql.count("(") - sql.count(")") + b = sql.count("[") - sql.count("]") + parts = [] + if p > 0: + parts.append(f"{p} unclosed '('") + elif p < 0: + parts.append(f"{-p} extra ')'") + if b > 0: + parts.append(f"{b} unclosed '['") + elif b < 0: + parts.append(f"{-b} extra ']'") + return ", ".join(parts) or "unknown imbalance" + + +def _has_unterminated_string(sql: str) -> bool: + """ + Heuristic: track whether we end up inside an open single-quoted string. + Handles SQL-style escaped quotes ('') correctly. + """ + in_string = False + i = 0 + while i < len(sql): + if sql[i] == "'": + if in_string and i + 1 < len(sql) and sql[i + 1] == "'": + i += 2 + continue + in_string = not in_string + i += 1 + return in_string diff --git a/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/length.bin b/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/length.bin deleted file mode 100644 index 56f6225..0000000 Binary files a/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/length.bin and /dev/null differ diff --git a/src/chroma_db/chroma.sqlite3 b/src/chroma_db/chroma.sqlite3 index b7e079a..c430a07 100644 Binary files a/src/chroma_db/chroma.sqlite3 and b/src/chroma_db/chroma.sqlite3 differ diff --git a/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/data_level0.bin b/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/data_level0.bin similarity index 100% rename from src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/data_level0.bin rename to src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/data_level0.bin diff --git a/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/header.bin b/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/header.bin similarity index 100% rename from src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/header.bin rename to src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/header.bin diff --git a/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/length.bin b/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/length.bin new file mode 100644 index 0000000..a67e8fd Binary files /dev/null and b/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/length.bin differ diff --git a/src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/link_lists.bin b/src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/link_lists.bin similarity index 100% rename from src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/link_lists.bin rename to src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/link_lists.bin diff --git a/src/database/README.md b/src/database/README.md index 3f71f60..facc8ad 100644 --- a/src/database/README.md +++ b/src/database/README.md @@ -179,7 +179,7 @@ Custom connection: db = Database( database_name="my_db", host="custom.host.com", - port=5433, + port=5534, user="myuser", password="mypass", ) diff --git a/src/database/database.py b/src/database/database.py index 699fffc..971a9a9 100644 --- a/src/database/database.py +++ b/src/database/database.py @@ -144,7 +144,7 @@ def table_names(self) -> list[str]: return list(self.metadata.tables.keys()) def execute_sql(self, sql_query: str) -> QueryResult: - """Execute a SQL query and return results. Only allows SELECT style queries. + """Execute a SQL query and return results. Blocks DDL statements. Args: sql_query: SQL query string to execute @@ -153,10 +153,41 @@ def execute_sql(self, sql_query: str) -> QueryResult: QueryResult with execution results Raises: - InvalidQueryError: If query is not a SELECT statement + InvalidQueryError: If query is a DDL statement """ - if not sql_query.strip().upper().startswith("SELECT"): - raise InvalidQueryError("Only SELECT style queries are allowed") + _ALLOWED_FIRST_TOKENS = {"SELECT", "WITH", "EXPLAIN"} + _WRITE_KEYWORDS = { + "INSERT", "UPDATE", "DELETE", "MERGE", "UPSERT", + "CREATE", "DROP", "ALTER", "TRUNCATE", "RENAME", + "GRANT", "REVOKE", "VACUUM", "REINDEX", "CLUSTER", + "COPY", "CALL", "DO", + } + + # Strip leading comments (-- and /* */) and whitespace + import re + cleaned = re.sub(r"--[^\n]*", "", sql_query) + cleaned = re.sub(r"/\*.*?\*/", "", cleaned, flags=re.DOTALL) + cleaned = cleaned.strip() + + tokens = cleaned.upper().split() + first_token = tokens[0] if tokens else "" + + if first_token not in _ALLOWED_FIRST_TOKENS: + raise InvalidQueryError( + f"Only SELECT / WITH / EXPLAIN queries are allowed (got {first_token})" + ) + + # Block WITH ... INSERT / UPDATE / DELETE (CTE + DML) + # Use word-boundary matching to avoid false positives on column names + # or string literals (e.g. SELECT comment FROM ..., WHERE x = 'UPDATE') + # Strip string literals before checking + no_strings = re.sub(r"'[^']*'", "''", cleaned) + upper_sql = no_strings.upper() + for kw in _WRITE_KEYWORDS: + if re.search(r"\b" + kw + r"\b", upper_sql): + raise InvalidQueryError( + f"Write operation '{kw}' detected — only read-only queries are allowed" + ) rows = [] error = None diff --git a/src/db_confirmed_fixes/README.md b/src/db_confirmed_fixes/README.md new file mode 100644 index 0000000..c1bb7d3 --- /dev/null +++ b/src/db_confirmed_fixes/README.md @@ -0,0 +1,53 @@ +# DB Confirmed Fixes + +Persistent storage layer for **confirmed SQL fixes** using [ChromaDB](https://www.trychroma.com/). When a user confirms that a corrected SQL query is correct, the fix is embedded and stored so it can be retrieved for future similar queries. + +## How It Works + +Each database gets its own ChromaDB collection under `chroma//`. Fixes are embedded by their **intent** (natural language description) using the `all-MiniLM-L6-v2` sentence-transformer model. + +### Core Modules + +| File | Description | +|---|---| +| `retriever.py` | Save, retrieve, and prune confirmed fixes in ChromaDB | +| `info.py` | One-time seeder — reads `db_confirmed_fixes.json` and populates per-DB ChromaDB instances | +| `db_confirmed_fixes.json` | 50 curated fix entries with db_id mappings from the benchmark dataset | + +### Key Functions (`retriever.py`) + +| Function | Description | +|---|---| +| `save_confirmed_fix()` | Stores a confirmed fix with deduplication (intent similarity ≥ 0.8) | +| `find_similar_confirmed_fixes()` | Retrieves top-N fixes ranked by cosine similarity | +| `prune_confirmed_fixes()` | Tiered cleanup when collection exceeds 500 items | + +### Data Schema + +Each stored fix contains: + +- **`intent`** — Natural language query intent (also used as the embedding document) +- **`corrected_sql`** — The validated correct SQL +- **`error_sql`** — The original broken SQL +- **`explanation`** — 2–4 sentence description of what was wrong and how it was fixed +- **`confirmed_at`** — ISO timestamp +- **`usage_count`** — Tracks how often this fix has been retrieved + +### Integration + +The agent exposes two tools that call into this module: +- `find_similar_confirmed_fixes_tool` — Called early during query fixing to check for prior solutions +- `save_confirmed_fix_tool` — Called after the user explicitly confirms a fix is correct + +## Directory Structure + +``` +db_confirmed_fixes/ +├── __init__.py +├── retriever.py # Core save/retrieve/prune logic +├── info.py # One-time ChromaDB seeder script +├── db_confirmed_fixes.json # Curated fix entries (50 examples) +├── README.md +└── chroma/ # ChromaDB persistent storage (gitignored) + └── / +``` diff --git a/src/db_confirmed_fixes/__init__.py b/src/db_confirmed_fixes/__init__.py new file mode 100644 index 0000000..748c370 --- /dev/null +++ b/src/db_confirmed_fixes/__init__.py @@ -0,0 +1 @@ +# DB Confirmed Fixes package diff --git a/src/db_confirmed_fixes/db_confirmed_fixes.json b/src/db_confirmed_fixes/db_confirmed_fixes.json new file mode 100644 index 0000000..4e8fcc5 --- /dev/null +++ b/src/db_confirmed_fixes/db_confirmed_fixes.json @@ -0,0 +1,402 @@ +[ + { + "instance_id": "PostgreSQL_0", + "db_id": "financial", + "intent": "Find accounts in the transactions table that have made at least 3 transactions where the difference between their highest and lowest transaction amounts exceeds 5000.", + "error_sql": "SELECT account_id, MAX(payments) AS max_payment, MIN(payments) AS min_payment FROM loan GROUP BY account_id HAVING COUNT(account_id) > 2 AND (MAX(payments) - MIN(payments)) > 5000;", + "corrected_sql": "SELECT account_id FROM trans GROUP BY account_id HAVING COUNT(trans_id) > 2 AND (MAX(amount) - MIN(amount)) > 5000;", + "explanation": "The error_sql queries the wrong table (loan instead of trans) and the wrong column (payments instead of amount), so it never touches the transaction records at all. The corrected_sql switches to the trans table and uses the amount column for variance calculation. The HAVING threshold is also updated from > 1 to > 2 to match the 'at least 3 transactions' intent." + }, + { + "instance_id": "PostgreSQL_1", + "db_id": "codebase_community", + "intent": "Extract just the time portion (hours:minutes:seconds) from the creationdate column in the posthistory table, without leading zeros on the hour.", + "error_sql": "SELECT creationdate::time FROM posthistory;", + "corrected_sql": "SELECT to_char(creationdate, 'FMHH24:MI:SS') AS time_only FROM posthistory;", + "explanation": "Casting a timestamptz directly to ::time preserves the full time type with its default formatting, which includes leading zeros on single-digit hours. The corrected_sql uses to_char() with the 'FMHH24:MI:SS' format, where the FM (fill mode) prefix strips leading zeros. The query is also redirected to the posthistory table as intended." + }, + { + "instance_id": "PostgreSQL_2", + "db_id": "financial", + "intent": "Create a trigger that fires when the status column of a loan record is updated, counts loans with status 'B' for the affected account, and updates a loan_summary table with that count.", + "error_sql": "CREATE OR REPLACE FUNCTION total_loans_b() RETURNS TRIGGER AS $$ BEGIN UPDATE loan_summary SET total_loan_count = (SELECT COUNT(CASE WHEN status = 'B' THEN 1 END) FROM loan WHERE loan_summary.account_id = loan.account_id) WHERE account_id = NEW.account_id; RETURN NEW; END; $$ LANGUAGE plpgsql;; CREATE TRIGGER tr_total_loans_b AFTER UPDATE OF status FOR EACH ROW EXECUTE PROCEDURE total_loans_b();", + "corrected_sql": "CREATE OR REPLACE FUNCTION total_loans_b() RETURNS TRIGGER AS $$ BEGIN UPDATE loan_summary SET total_loan_count = (SELECT COUNT(*) FROM loan WHERE loan.account_id = loan_summary.account_id AND loan.status = 'B') WHERE loan_summary.account_id = NEW.account_id; RETURN NEW; END; $$ LANGUAGE plpgsql;; CREATE TRIGGER tr_total_loans_b AFTER UPDATE OF status ON loan FOR EACH ROW EXECUTE PROCEDURE total_loans_b();", + "explanation": "The error_sql uses COUNT(CASE WHEN ...) which counts non-NULL cases but is less clear than a filtered WHERE clause, and critically the CREATE TRIGGER statement is missing the ON loan clause specifying the target table, which will cause a syntax error. The corrected_sql replaces the CASE expression with a direct WHERE status = 'B' filter for clarity and adds ON loan to the trigger definition. Both versions correctly use NEW.account_id to scope the update to only the affected account." + }, + { + "instance_id": "PostgreSQL_3", + "db_id": "student_club", + "intent": "Create a unique index on the event table that prevents duplicate combinations of event_name and event_date, treating NULLs in event_name as non-unique (so multiple rows with NULL event_name are allowed).", + "error_sql": "CREATE UNIQUE INDEX unique_name ON event(event_name, event_date) where event_name is not null; CREATE UNIQUE INDEX unique_name_null ON event((event_name IS NULL), event_date) where event_name is null;", + "corrected_sql": "CREATE UNIQUE INDEX unique_name_date ON event(event_name, event_date) WHERE coalesce(event_name, '') IS DISTINCT FROM '';", + "explanation": "The error_sql creates two separate partial indexes \u2014 one for non-NULL event_name values and one for NULL values \u2014 but the second index still enforces uniqueness on (NULL, event_date) pairs, which means only one NULL event_name per date is allowed. The corrected_sql uses a single index with a COALESCE-based WHERE clause that excludes truly empty/null names, relying on PostgreSQL's standard behavior that NULL values are never considered equal in unique indexes. This allows multiple rows with NULL event_name while still enforcing uniqueness for non-null names." + }, + { + "instance_id": "PostgreSQL_4", + "db_id": "debit_card_specializing", + "intent": "Update the Amount to 200 for all transactions where the Amount is 75, but only for customers who have more than 2 such transactions.", + "error_sql": "UPDATE transactions_1k SET Amount = 200 FROM ( SELECT TransactionID FROM transactions_1k WHERE Amount = 75 ORDER BY TransactionID LIMIT 1 ) AS sub WHERE transactions_1k.TransactionID = sub.TransactionID;", + "corrected_sql": "UPDATE transactions_1k SET Amount = 200 FROM ( SELECT customerid, transactionid FROM transactions_1k WHERE Amount = 75 GROUP BY customerid, transactionid HAVING COUNT(*) OVER (PARTITION BY customerid) > 2 ) AS sub WHERE transactions_1k.TransactionID = sub.transactionid;", + "explanation": "The error_sql selects only TransactionID in the subquery and applies a LIMIT 1, which restricts the update to a single row and ignores the customer-level grouping needed. The corrected_sql selects both customerid and transactionid and uses a window function to count per-customer occurrences, ensuring only customers with more than 2 qualifying transactions are updated. The Amount threshold is also correctly set to 75 \u2192 200 throughout." + }, + { + "instance_id": "PostgreSQL_5", + "db_id": "codebase_community", + "intent": "For each user, count how many of their posts have a score greater than 5, showing the user ID alongside this count.", + "error_sql": "SELECT users.Id, COUNT(posts.Id) as high_scored FROM users LEFT JOIN posts ON users.Id = posts.OwnerUserId GROUP BY users.Id;", + "corrected_sql": "SELECT users.Id, COUNT(posts.Id) FILTER (WHERE score > 5) as high_scored FROM users LEFT JOIN posts ON users.Id = posts.OwnerUserId GROUP BY users.Id;", + "explanation": "The error_sql counts all posts for each user regardless of score, because there is no condition applied to the COUNT aggregate. The corrected_sql adds a FILTER (WHERE score > 5) clause to the COUNT, which restricts the aggregation to only posts meeting the score threshold. This is the idiomatic PostgreSQL way to perform conditional aggregation without a subquery." + }, + { + "instance_id": "PostgreSQL_6", + "db_id": "codebase_community", + "intent": "Drop the posts table if it exists, including all objects that depend on it such as foreign keys from other tables.", + "error_sql": "DROP TABLE IF EXISTS posts;", + "corrected_sql": "DROP TABLE IF EXISTS posts CASCADE;", + "explanation": "DROP TABLE without CASCADE will fail if any other tables have foreign key constraints referencing posts, as is the case in the codebase_community schema where votes and other tables reference posts(id). Adding CASCADE tells PostgreSQL to automatically drop all dependent objects (foreign key constraints, views, etc.) along with the table. The IF EXISTS guard prevents an error if the table doesn't exist." + }, + { + "instance_id": "PostgreSQL_7", + "db_id": "student_club", + "intent": "Build a recursive graph of user relationships using only the ref1 field (not ref2), and return all reachable node pairs as edges.", + "error_sql": "SELECT ARRAY_AGG(DISTINCT u.id) AS ids, ARRAY_AGG(DISTINCT u.username) AS usernames, ARRAY_AGG(DISTINCT u.ref1) AS refs FROM users u GROUP BY u.ref1;", + "corrected_sql": "WITH RECURSIVE nodes AS (SELECT u.id, u.ref1 AS ref FROM users u), edges AS (SELECT n1.id AS from_id, n2.id AS to_id FROM nodes n1 JOIN nodes n2 ON n1.ref = n2.id UNION ALL SELECT e.from_id, n2.id FROM edges e JOIN nodes n2 ON e.to_id = n2.ref) SELECT DISTINCT from_id, to_id FROM edges;", + "explanation": "The error_sql performs a simple GROUP BY on ref1, which only shows direct one-hop relationships and does not traverse multi-level chains. The corrected_sql uses a WITH RECURSIVE CTE to iteratively follow ref1 links from each node until no new edges are found, correctly computing full transitive reachability. The non-recursive approach would miss indirect connections that are more than one level deep." + }, + { + "instance_id": "PostgreSQL_8", + "db_id": "student_club", + "intent": "Find events and the members who attended them, but only for events where attendance count is at least 5, along with each member's name.", + "error_sql": "WITH CTE AS ( SELECT link_to_event, COUNT(link_to_member) AS count FROM attendance GROUP BY link_to_event ) SELECT CTE.link_to_event, member.member_name FROM CTE JOIN attendance ON CTE.link_to_event = attendance.link_to_event JOIN member ON attendance.link_to_member = member.member_id WHERE CTE.count > 5;", + "corrected_sql": "WITH CTE AS ( SELECT link_to_event, COUNT(link_to_member) AS count FROM attendance GROUP BY link_to_event ), CTE2 AS ( SELECT link_to_event, link_to_member FROM attendance WHERE link_to_event IN (SELECT link_to_event FROM CTE WHERE count >= 5) ) SELECT CTE2.link_to_event, member.member_name FROM CTE2 JOIN member ON CTE2.link_to_member = member.member_id;", + "explanation": "The error_sql joins attendance back after the CTE count, which re-introduces duplicate rows for every member at that event (once per attendee multiplied by the CTE join). The corrected_sql uses a second CTE to filter attendance rows to only qualifying events first, then joins to member once cleanly. The threshold is also corrected from > 5 to >= 5 to properly include events with exactly 5 attendees." + }, + { + "instance_id": "PostgreSQL_9", + "db_id": "student_club", + "intent": "Insert a new attendance record for event 'recXYZ123' and member 'recABC456' with attend=1, but only if that combination doesn't already exist.", + "error_sql": "INSERT INTO attendance VALUES ('recXYZ123', 'recABC456', 1)", + "corrected_sql": "INSERT INTO attendance (link_to_event, link_to_member, attend) VALUES ('recXYZ123', 'recABC456', 1) ON CONFLICT (link_to_event, link_to_member) DO NOTHING;", + "explanation": "The error_sql does not name columns explicitly, which will fail if the column order in the table differs from what is assumed, and more critically it has no ON CONFLICT clause so it will throw a duplicate key error if the record already exists. The corrected_sql explicitly names the columns and adds ON CONFLICT (link_to_event, link_to_member) DO NOTHING to silently skip insertion when a duplicate is detected." + }, + { + "instance_id": "PostgreSQL_10", + "db_id": "financial", + "intent": "Change the frequency column in the account table from its current type to varchar(30), preserving existing values.", + "error_sql": "UPDATE account SET frequency__varchar = frequency::varchar(30);", + "corrected_sql": "ALTER TABLE account ALTER COLUMN frequency TYPE varchar(30) USING frequency::varchar;", + "explanation": "The error_sql tries to copy values into a non-existent column (frequency__varchar) rather than actually changing the column's type, which would fail with a column-not-found error. The correct approach is ALTER TABLE ... ALTER COLUMN ... TYPE, which modifies the column's type in place. The USING clause provides the explicit cast expression PostgreSQL needs to convert existing text values to the new varchar(30) type." + }, + { + "instance_id": "PostgreSQL_11", + "db_id": "card_games", + "intent": "Return one representative card row per setCode (the first by id), including all columns.", + "error_sql": "SELECT * FROM cards GROUP BY setCode;", + "corrected_sql": "SELECT t1.* FROM cards t1 JOIN (SELECT min(id) as id FROM cards GROUP BY setCode) t2 ON t1.id = t2.id;", + "explanation": "SELECT * with GROUP BY in PostgreSQL requires all non-aggregated columns to appear in the GROUP BY clause, so the query fails because the other card columns are not included. The corrected_sql finds the minimum id per setCode in a subquery and then joins back to the cards table to retrieve the full row for each representative. This correctly returns one complete row per setCode group." + }, + { + "instance_id": "PostgreSQL_12", + "db_id": "debit_card_specializing", + "intent": "Return all transactions for CustomerID 7 on date '2013-05-15', or if none exist, return all transactions for CustomerID 7 regardless of date.", + "error_sql": "IF SELECT * FROM transactions_1k WHERE CustomerID = 7 AND Date = '2013-05-15' RETURNS NO ROWS THEN SELECT * FROM transactions_1k WHERE CustomerID = 7; END IF;", + "corrected_sql": "SELECT * FROM transactions_1k WHERE CustomerID = 7 AND Date = '2013-05-15' UNION ALL SELECT * FROM transactions_1k WHERE CustomerID = 7 AND NOT EXISTS (SELECT 1 FROM transactions_1k WHERE CustomerID = 7 AND Date = '2013-05-15');", + "explanation": "IF ... THEN ... END IF is PL/pgSQL procedural syntax and cannot be used as a standalone SQL query outside a function body. The corrected_sql uses a UNION ALL approach: the first branch returns matching rows when they exist, and the second branch returns all customer rows only when no date-specific rows exist, achieved via NOT EXISTS. This is valid plain SQL that works in any PostgreSQL context." + }, + { + "instance_id": "PostgreSQL_13", + "db_id": "financial", + "intent": "Dynamically build a SELECT statement string listing all column names from the loan table, aliased as 'l'.", + "error_sql": "SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_name FROM information_schema.columns AS c WHERE c.table_name = 'loan'), ', ') || ' FROM loan AS l'", + "corrected_sql": "SELECT 'SELECT ' || STRING_AGG('l.' || column_name, ', ') || ' FROM loan AS l' FROM information_schema.columns WHERE table_name = 'loan';", + "explanation": "The error_sql uses the alias prefix 'o.' but builds a query aliasing the table as 'l', creating a mismatch between the generated column references and the table alias. The corrected_sql consistently uses 'l.' as the column prefix and uses STRING_AGG instead of ARRAY + array_to_string, which is the more idiomatic PostgreSQL approach for concatenating rows into a string. The corrected query targets the loan table throughout." + }, + { + "instance_id": "PostgreSQL_14", + "db_id": "financial", + "intent": "For each account, return the most recent loan record (by loan_date), combining it with the account's frequency, and picking only one row per account even if loan dates tie.", + "error_sql": "(SELECT account.account_id, account.frequency, l.loan_id, l.date AS loan_date FROM account LEFT JOIN loan l ON account.account_id = l.account_id ORDER BY l.date DESC) LIMIT 1;", + "corrected_sql": "SELECT * FROM (SELECT DISTINCT ON (account_id) account.account_id, account.frequency, l.loan_id, l.date AS loan_date FROM account LEFT JOIN loan l ON account.account_id = l.account_id ORDER BY account_id, l.date DESC NULLS LAST) sub;", + "explanation": "The error_sql applies ORDER BY and LIMIT at the outer level, which returns only a single row across all accounts rather than the most recent loan per account. The corrected_sql uses DISTINCT ON (account_id) with ORDER BY account_id, date DESC to select exactly the most recent loan for each account, with NULLS LAST to handle accounts with no loans gracefully." + }, + { + "instance_id": "PostgreSQL_15", + "db_id": "student_club", + "intent": "For each event in the attendance table, return a JSON array of objects where each object contains the link_to_member and the attend value for that event.", + "error_sql": "SELECT link_to_event, Array_agg(Row_to_json(t)) FROM (SELECT link_to_member, attend FROM attendance t) GROUP BY link_to_event;", + "corrected_sql": "SELECT json_agg(events_array) AS all_events FROM (SELECT json_agg(json_build_object('link_to_event', link_to_event, 'members', members_json)) AS events_array FROM (SELECT link_to_event, json_agg(json_build_object('link_to_member', link_to_member, 'attend', attend)) AS members_json FROM attendance GROUP BY link_to_event) sub) sub2;", + "explanation": "The error_sql attempts to use Row_to_json inside Array_agg but the subquery alias t is defined inside the FROM clause and not visible to the GROUP BY or outer SELECT, causing a scoping error. The corrected_sql properly nests the aggregations: first grouping members per event into a JSON array with json_build_object, then wrapping all events into an outer json_agg. This produces correctly structured nested JSON output." + }, + { + "instance_id": "PostgreSQL_16", + "db_id": "financial", + "intent": "Generate a series of all distinct years (as integers) covered by transaction dates in the trans table.", + "error_sql": "SELECT to_char(generate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') FROM trans;", + "corrected_sql": "SELECT generate_series(EXTRACT(YEAR FROM MIN(date)::timestamptz AT TIME ZONE 'UTC')::int, EXTRACT(YEAR FROM MAX(date)::timestamptz AT TIME ZONE 'UTC')::int) AS year FROM trans;", + "explanation": "The error_sql calls generate_series() with aggregate functions (MIN, MAX) directly as arguments outside any aggregation context, and also has two FROM clauses which is invalid syntax. The corrected_sql first extracts the integer year from MIN and MAX dates using EXTRACT, then passes those integer bounds to generate_series, which correctly produces one integer row per year in the range. This approach also avoids timezone ambiguity by explicitly specifying 'UTC'." + }, + { + "instance_id": "PostgreSQL_17", + "db_id": "financial", + "intent": "For every transaction in the trans table, show all columns plus the maximum transaction amount for that account across all its transactions.", + "error_sql": "SELECT account_id, amount FROM (SELECT account_id, amount, ROW_NUMBER() OVER(PARTITION BY account_id ORDER BY amount DESC) AS rn FROM trans) sub WHERE rn = 1;", + "corrected_sql": "SELECT *, MAX(amount) OVER (PARTITION BY account_id) AS max FROM trans;", + "explanation": "The error_sql returns only the single top-amount row per account (via ROW_NUMBER rn=1), rather than showing the max alongside every transaction row. The corrected_sql uses MAX() as a window function with PARTITION BY account_id, which appends the partition maximum to every row without collapsing the result set. This is the correct approach when the intent is to annotate all rows, not filter to just one per group." + }, + { + "instance_id": "PostgreSQL_18", + "db_id": "financial", + "intent": "Create a client_information table with client_id as a smallserial primary key, and store the phone_number column as a VARCHAR(20) instead of TEXT to enforce a length limit.", + "error_sql": "CREATE TABLE client_information ( client_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), email character varying(100), phone_number TEXT, PRIMARY KEY (client_id) );", + "corrected_sql": "CREATE TABLE client_information ( client_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), email character varying(100), phone_number VARCHAR(20), PRIMARY KEY (client_id) );", + "explanation": "The error_sql declares phone_number as TEXT, which has no length constraint and allows arbitrarily long strings. The corrected_sql changes phone_number to VARCHAR(20), which enforces a maximum length of 20 characters as required by the intent. All other columns and the primary key definition remain identical." + }, + { + "instance_id": "PostgreSQL_19", + "db_id": "card_games", + "intent": "Insert a card record with a known uuid and name, and if the uuid already exists return the existing row's id and name without inserting.", + "error_sql": "INSERT INTO cards(uuid, name) VALUES ('5f8287b1-5bb6-5f4c-ad17-316a40d5bb0c', 'Ancestor''s Chosen') ON CONFLICT DO NOTHING;", + "corrected_sql": "WITH ins AS (INSERT INTO cards (uuid, name) VALUES ('5f8287b1-5bb6-5f4c-ad17-316a40d5bb0c', 'Ancestor''s Chosen') ON CONFLICT (uuid) DO NOTHING RETURNING id, name) SELECT id, name FROM ins UNION ALL SELECT id, name FROM cards WHERE uuid = '5f8287b1-5bb6-5f4c-ad17-316a40d5bb0c' AND NOT EXISTS (SELECT 1 FROM ins);", + "explanation": "The error_sql uses ON CONFLICT DO NOTHING without specifying the conflict target column (uuid), which is required when the table has multiple unique constraints, and it returns nothing on either path. The corrected_sql specifies ON CONFLICT (uuid) explicitly and wraps the INSERT in a CTE with RETURNING so that the inserted row's data is captured; a UNION ALL then fetches the existing row when the INSERT was skipped. This ensures the caller always receives the id and name regardless of whether an insert occurred." + }, + { + "instance_id": "PostgreSQL_20", + "db_id": "financial", + "intent": "Insert a new account record (account_id=999, district_id=5, frequency='POPLATEK TYDNE', date=CURRENT_DATE) and if account_id=999 already exists, update the frequency to 'POPLATEK TYDNE'.", + "error_sql": "INSERT INTO account (account_id, district_id, frequency, date) VALUES (999, 5, 'POPLATEK TYDNE', CURRENT_DATE) ON CONFLICT DO NOTHING;", + "corrected_sql": "INSERT INTO account (account_id, district_id, frequency, date) VALUES (999, 5, 'POPLATEK TYDNE', CURRENT_DATE) ON CONFLICT (account_id) DO UPDATE SET frequency = EXCLUDED.frequency;", + "explanation": "The error_sql uses ON CONFLICT DO NOTHING, which silently skips the insert on a duplicate but does not update the existing row's frequency as required. The corrected_sql specifies the conflict column (account_id) and uses DO UPDATE SET frequency = EXCLUDED.frequency to overwrite the frequency value with the new one when a conflict occurs. EXCLUDED refers to the row that was proposed for insertion." + }, + { + "instance_id": "PostgreSQL_21", + "db_id": "card_games", + "intent": "Find the longest consecutive run of cards with sequential release dates for a given setCode, returning the run length, its start date, and its end date.", + "error_sql": "SELECT COUNT(*) - 1 AS count, MAX(releaseDate), MIN(releaseDate) FROM (SELECT *, date(releaseDate) - row_number() OVER (PARTITION BY setCode ORDER BY releaseDate) AS grp FROM cards WHERE setCode = 'LEA') sub GROUP BY grp ORDER BY count DESC LIMIT 1;", + "corrected_sql": "SELECT (MAX(releaseDate) - MIN(releaseDate)) + 1 AS cnt, MIN(releaseDate) AS date_min, MAX(releaseDate) AS date_max FROM (SELECT releaseDate, date(releaseDate) - row_number() OVER (ORDER BY releaseDate)::int AS grp FROM cards WHERE setCode = 'LEA') sub GROUP BY grp ORDER BY cnt DESC LIMIT 1;", + "explanation": "The error_sql computes COUNT(*) - 1 which is off-by-one (a run of N distinct dates has N rows, not N-1 days), and PARTITIONS by setCode inside the row_number window which disrupts the consecutive grouping when filtering to a single set. The corrected_sql removes the PARTITION BY from the window function (since the query already filters to one setCode) and calculates run length as (MAX - MIN) + 1 in days, which correctly counts the span." + }, + { + "instance_id": "PostgreSQL_22", + "db_id": "card_games", + "intent": "Traverse the collection table's linked list recursively starting from cards that have no previousCardId (i.e., the head of each chain), and return the full path string for each chain.", + "error_sql": "WITH RECURSIVE path_cte AS (SELECT id, nextCardId, id::TEXT AS Path FROM collection WHERE previousCardId IS NULL UNION ALL SELECT c.id, c.nextCardId, path_cte.Path || '->' || c.id::TEXT FROM collection c JOIN path_cte ON c.id = path_cte.nextCardId) SELECT Path FROM path_cte WHERE nextCardId IS NULL;", + "corrected_sql": "WITH RECURSIVE path_cte AS (SELECT id, id::text AS Path, id AS FirstID, 1 AS Lvl FROM collection WHERE previousCardId IS NULL UNION ALL SELECT c.id, path_cte.Path || '->' || c.id::text, path_cte.FirstID, path_cte.Lvl + 1 FROM collection c JOIN path_cte ON c.previousCardId = path_cte.id) SELECT Path FROM path_cte WHERE id NOT IN (SELECT previousCardId FROM collection WHERE previousCardId IS NOT NULL);", + "explanation": "The error_sql joins on c.id = path_cte.nextCardId which traverses forward using the current node's next pointer, but correctly should join on c.previousCardId = path_cte.id to follow the chain from parent to child. The terminal condition also needs to find nodes with no successor, done by checking that id is not referenced as any previousCardId. The corrected_sql fixes the join direction and uses an anti-join subquery to correctly identify chain endpoints." + }, + { + "instance_id": "PostgreSQL_23", + "db_id": "financial", + "intent": "Create a function that takes a date and an optional fiscal year start month (defaulting to 4 for April), and returns which fiscal quarter the date falls in.", + "error_sql": "SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');", + "corrected_sql": "CREATE OR REPLACE FUNCTION what_quarter_is(date_in DATE, start_mon_in INTEGER DEFAULT 4) RETURNS INTEGER LANGUAGE sql AS $$ SELECT (((EXTRACT(MONTH FROM date_in)::int - start_mon_in + 12) % 12) / 3 + 1) $$;", + "explanation": "The error_sql uses EXTRACT(QUARTER ...) which returns calendar quarters (Jan-Mar=Q1) rather than fiscal quarters based on a configurable start month. The corrected_sql creates a reusable function that accepts both the date and the fiscal year start month (defaulting to April), then computes the fiscal quarter using modular arithmetic on the month offset. This correctly handles wrap-around cases where the fiscal year starts mid-calendar-year." + }, + { + "instance_id": "PostgreSQL_24", + "db_id": "codebase_community", + "intent": "List all foreign key relationships in the posts table, showing the referencing column, the referenced table, and the referenced column.", + "error_sql": "SELECT a.attname as base_col, (select r.relname from pg_class r where r.oid = c.confrelid) as ref_table FROM pg_attribute a JOIN pg_constraint c ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid WHERE c.contype = 'f' AND a.attrelid = 'posts'::regclass;", + "corrected_sql": "SELECT a.attname as base_col, (select r.relname from pg_class r where r.oid = c.confrelid) as ref_table, (select a2.attname from pg_attribute a2 where a2.attrelid = c.confrelid and a2.attnum = c.confkey[1]) as ref_col FROM pg_attribute a JOIN pg_constraint c ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid WHERE c.contype = 'f' AND a.attrelid = 'posts'::regclass;", + "explanation": "The error_sql retrieves the referencing column and referenced table but omits the referenced column name, which requires looking up confkey[1] in pg_attribute for the referenced table (confrelid). The corrected_sql adds a correlated subquery that finds the attribute name from pg_attribute where attrelid matches confrelid and attnum matches confkey[1]. This provides the complete three-part foreign key description." + }, + { + "instance_id": "PostgreSQL_25", + "db_id": "financial", + "intent": "For each row in the trans table, carry the last non-null account value forward within each account_id partition, ordered by date.", + "error_sql": "SELECT account, first_value(account ignore nulls) over (partition by account_id order by date rows unbounded following) as next_account FROM trans;", + "corrected_sql": "SELECT account, first_value(account) OVER (PARTITION BY account_id ORDER BY date ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS next_account FROM trans;", + "explanation": "PostgreSQL's window functions do not support the 'IGNORE NULLS' syntax inside first_value(); that syntax is specific to other databases like BigQuery or Snowflake. The corrected_sql removes IGNORE NULLS and uses a frame of ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING to look at the current and subsequent rows, effectively carrying forward the last non-null account value within each partition ordered by date." + }, + { + "instance_id": "PostgreSQL_26", + "db_id": "european_football_2", + "intent": "Join the Team table with Team_Attributes to show each team's api id, short name, and their defencePressure attribute value.", + "error_sql": "SELECT team_api_id, team_short_name FROM Team as data FULL OUTER JOIN (SELECT defencePressure, team_api_id FROM Team_Attributes) attr ON data.team_api_id = attr.team_api_id;", + "corrected_sql": "SELECT t1.team_api_id, t1.team_short_name, t2.defencePressure FROM Team t1 INNER JOIN Team_Attributes t2 ON t1.team_api_id = t2.team_api_id;", + "explanation": "The error_sql uses a FULL OUTER JOIN but then fails to select the defencePressure column from the subquery, so it only returns team_api_id and team_short_name with no attribute data. The corrected_sql switches to an INNER JOIN (since we want teams that have attributes) and explicitly selects t2.defencePressure from the Team_Attributes table. The table alias in the error_sql ('data') is also inconsistent with the column references." + }, + { + "instance_id": "PostgreSQL_27", + "db_id": "financial", + "intent": "Show the monthly transaction count from the trans table alongside the monthly account creation count from the account table, for all months present in either table.", + "error_sql": "WITH one AS ( SELECT date_trunc('month', date) as timeOne, COUNT(*) as trans_count FROM trans ORDER BY timeOne ), two AS ( SELECT date_trunc('month', date) as timeTwo, COUNT(*) as acct_count FROM account ORDER BY timeTwo ) SELECT timeOne, trans_count, acct_count FROM one FULL OUTER JOIN two ON one.timeOne = two.timeTwo;", + "corrected_sql": "WITH months AS ( SELECT date_trunc('month', date) as month, COUNT(*) as count FROM trans GROUP BY 1 UNION ALL SELECT date_trunc('month', date) as month, COUNT(*) as count FROM account GROUP BY 1 ) SELECT month, SUM(CASE WHEN ctid IS NULL THEN 0 ELSE count END) FROM months GROUP BY month ORDER BY month;", + "explanation": "The error_sql is missing GROUP BY clauses in both CTEs \u2014 you cannot ORDER BY an aggregate result without first grouping, so those CTEs will fail. The corrected_sql adds GROUP BY 1 to each CTE's SELECT and uses UNION ALL to combine both monthly counts, then re-aggregates by month. This correctly produces one row per month showing combined activity from both tables." + }, + { + "instance_id": "PostgreSQL_28", + "db_id": "debit_card_specializing", + "intent": "For each customer in transactions_1k, generate one row per 100-unit block of their transaction Amount (so Amount=250 generates 2 rows), and return CustomerID with the generated series value.", + "error_sql": "WITH gen_transactions AS ( SELECT CustomerID, Amount FROM transactions_1k CROSS JOIN LATERAL generate_series(1, CAST(Amount / 100 AS INTEGER)) AS gs ) SELECT CustomerID, gs FROM gen_transactions;", + "corrected_sql": "WITH gen_transactions AS ( SELECT CustomerID, Amount, gs FROM transactions_1k CROSS JOIN LATERAL generate_series(1, GREATEST(1, CAST(Amount / 100 AS INTEGER))) AS gs ) SELECT CustomerID, gs FROM gen_transactions;", + "explanation": "The error_sql passes Amount/100 directly to generate_series without handling cases where Amount < 100, which would result in generate_series(1, 0) producing zero rows and silently dropping those transactions. The corrected_sql wraps the upper bound in GREATEST(1, ...) to ensure at least one row is always generated per transaction. The gs column also needs to be included in the CTE's SELECT list to be accessible in the outer query." + }, + { + "instance_id": "PostgreSQL_29", + "db_id": "card_games", + "intent": "Expand each element from the existing JSONB price array in card_information, and insert those individual elements back as a new aggregated JSONB array in a separate row.", + "error_sql": "INSERT INTO card_information(price) SELECT jsonb_agg(price) FROM (SELECT price FROM card_information) AS subquery; SELECT * FROM card_information;", + "corrected_sql": "INSERT INTO card_information(price) SELECT jsonb_agg(s.elements) FROM (SELECT jsonb_array_elements(price) FROM card_information) AS s(elements); SELECT * FROM card_information;", + "explanation": "The error_sql re-aggregates the raw JSONB arrays themselves (not their elements) using jsonb_agg, producing a JSON array of arrays rather than a flat array of the individual price elements. The corrected_sql first unnests each price array using jsonb_array_elements() to extract individual scalar elements, and then aggregates those elements with jsonb_agg into a single new JSONB array. This correctly flattens and re-packs all price values." + }, + { + "instance_id": "PostgreSQL_30", + "db_id": "financial", + "intent": "For each distinct operation type in the trans table, return one representative row (the most recent by date) joined with the account's frequency.", + "error_sql": "SELECT t.k_symbol, t.operation, t.amount, t.balance, a.frequency FROM trans t INNER JOIN account a ON t.account_id = a.account_id GROUP BY t.operation;", + "corrected_sql": "SELECT t.k_symbol, t.operation, t.amount, t.balance, a.frequency FROM (SELECT DISTINCT ON (t.operation) t.k_symbol, t.operation, t.amount, t.balance, t.account_id FROM trans t ORDER BY t.operation, t.date DESC NULLS LAST) t JOIN account a ON t.account_id = a.account_id;", + "explanation": "The error_sql uses GROUP BY t.operation but selects non-aggregated columns (k_symbol, amount, etc.) that are not in the GROUP BY, which is invalid in PostgreSQL's strict GROUP BY mode. The corrected_sql uses DISTINCT ON (t.operation) with ORDER BY operation, date DESC to select the most recent row per operation, then joins to account for the frequency. This is the idiomatic PostgreSQL pattern for 'first/last row per group'." + }, + { + "instance_id": "PostgreSQL_31", + "db_id": "card_games", + "intent": "For each user, count how many sets of at least 2 consecutive calendar months they have purchase records in.", + "error_sql": "SELECT user_id, COUNT(*) AS num_consecutive_months FROM (SELECT user_id, purchase_date, DATE_TRUNC('month', TO_DATE(purchase_date || '-01','YYYY-MM-DD')) AS month, LAG(DATE_TRUNC('month', TO_DATE(purchase_date || '-01','YYYY-MM-DD'))) OVER (PARTITION BY user_id ORDER BY purchase_date) AS prev_month FROM purchases) sub WHERE month - prev_month = interval '1 month' GROUP BY user_id;", + "corrected_sql": "WITH cte AS (SELECT user_id, TO_DATE(purchase_date || '-01','YYYY-MM-DD') AS date_as_date FROM purchases), ranked AS (SELECT user_id, date_as_date, date_as_date - (ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY date_as_date) * interval '1 month')::interval AS grp FROM cte) SELECT user_id, COUNT(*) AS num_consecutive_runs FROM (SELECT user_id, grp, COUNT(*) AS run_len FROM ranked GROUP BY user_id, grp HAVING COUNT(*) >= 2) sub GROUP BY user_id;", + "explanation": "The error_sql counts individual month transitions (where month - prev_month = 1 month) rather than counting complete consecutive runs of 2+ months, which means a streak of 4 months would count as 3 transitions instead of 1 run. The corrected_sql uses the classic 'date minus row_number' trick to assign all months in a consecutive run to the same group key, then counts groups with at least 2 months. The HAVING COUNT(*) >= 2 threshold correctly filters for runs of length 2 or more." + }, + { + "instance_id": "PostgreSQL_32", + "db_id": "financial", + "intent": "Extract a cleaned card ID from the cardid column by removing the middle segment of a three-part dash-separated ID (e.g., 'ABC-REMOVE-DEF' becomes 'ABC-DEF').", + "error_sql": "WITH tab_with_cardid AS (SELECT split_part(cardid, '-', 1) || '-' || split_part(cardid, '-', 3) AS pure_cardid, type, last_refresh_date FROM card_data) SELECT * FROM tab_with_cardid;", + "corrected_sql": "WITH tab_with_cardid AS (SELECT *, REGEXP_REPLACE(cardid, '([^-]+)-[^-]+-([^-]+)', E'\\\\1-\\\\2') AS pure_cardid FROM card_data) SELECT * FROM tab_with_cardid;", + "explanation": "The error_sql uses split_part which works correctly only when cardid has exactly three segments separated by single dashes; it will silently produce wrong output for IDs with more or fewer segments. The corrected_sql uses REGEXP_REPLACE to capture the first and last non-dash segments with backreferences, which is more robust across different cardid formats. Both approaches remove the middle segment, but the regex solution correctly handles edge cases." + }, + { + "instance_id": "PostgreSQL_33", + "db_id": "european_football_2", + "intent": "For each player, return the record with the most recent date along with their potential_rating at that time.", + "error_sql": "SELECT player_api_id, MAX(date), FIRST(potential) FROM Player_Attributes GROUP BY player_api_id ORDER BY date desc;", + "corrected_sql": "SELECT player_api_id, date, potential FROM Player_Attributes ORDER BY ROW_NUMBER() OVER(PARTITION BY player_api_id ORDER BY date DESC);", + "explanation": "PostgreSQL does not have a FIRST() aggregate function \u2014 this is a common misconception from other databases. The corrected_sql uses ROW_NUMBER() as a window function to rank records per player by date descending, then selects only rank-1 rows (the most recent) by ordering on that rank. The target column is also corrected from overall_rating to potential to match the updated intent." + }, + { + "instance_id": "PostgreSQL_34", + "db_id": "codebase_community", + "intent": "Create a function that returns the reputation values of all users as a set of bigint, handling any values that cannot be cast.", + "error_sql": "SELECT Age::numeric FROM users;", + "corrected_sql": "CREATE OR REPLACE FUNCTION get_user_reputations() RETURNS setof bigint AS $BODY$ DECLARE curr_rep text; BEGIN FOR curr_rep IN SELECT reputation::text FROM users LOOP BEGIN RETURN NEXT curr_rep::bigint; EXCEPTION WHEN others THEN NULL; END; END LOOP; END; $BODY$ LANGUAGE plpgsql;", + "explanation": "The error_sql is a plain SELECT that casts Age to numeric directly, which will raise an error on non-numeric values rather than handling them gracefully, and it targets the wrong column (Age vs reputation). The corrected_sql wraps the logic in a PL/pgSQL function with a BEGIN/EXCEPTION block that catches cast failures for individual rows and skips them, returning the valid reputation values as a set. This robust error handling is the key structural improvement." + }, + { + "instance_id": "PostgreSQL_35", + "db_id": "codebase_community", + "intent": "Create a trigger function and trigger that, after a new user is inserted into the users table, automatically inserts a corresponding row into a profiles table with the user's Id, CreationDate, and Location.", + "error_sql": "begin insert into profiles (Id, CreationDate, Location) select new.Id, new.CreationDate, new.Location from users; end;", + "corrected_sql": "CREATE OR REPLACE FUNCTION profileTrigger() RETURNS TRIGGER AS $profile_table$ begin insert into profiles (id, CreationDate, Location) VALUES (new.id, new.CreationDate, new.Location); RETURN NEW; end; $profile_table$ LANGUAGE plpgsql; CREATE TRIGGER profile_insert_trigger AFTER INSERT ON users FOR EACH ROW EXECUTE PROCEDURE profileTrigger();", + "explanation": "The error_sql is a bare PL/pgSQL block without a function wrapper or trigger definition, and the INSERT uses a SELECT from users which would copy all existing users on every trigger fire instead of just the new row. The corrected_sql wraps the logic in a properly declared RETURNS TRIGGER function using VALUES (new.id, ...) to insert only the triggering row, adds RETURN NEW, and creates an AFTER INSERT trigger on the users table to call this function." + }, + { + "instance_id": "PostgreSQL_36", + "db_id": "card_games", + "intent": "Find all cards that simultaneously satisfy at least 2 of the following 3 conditions: availability='paper', bordercolor='black', rarity='rare'.", + "error_sql": "SELECT * FROM cards WHERE availability = 'paper' AND bordercolor = 'black' AND rarity = 'rare';", + "corrected_sql": "SELECT * FROM cards WHERE 2 <= (CASE WHEN availability = 'paper' THEN 1 ELSE 0 END) + (CASE WHEN bordercolor = 'black' THEN 1 ELSE 0 END) + (CASE WHEN rarity = 'rare' THEN 1 ELSE 0 END);", + "explanation": "The error_sql requires all three conditions to be true simultaneously (AND logic), but the intent is to find cards matching at least 2 of the 3 conditions. The corrected_sql converts each condition to a 0/1 integer using CASE WHEN and sums them, then filters for rows where the sum is >= 2. This correctly returns cards satisfying any two or three of the conditions." + }, + { + "instance_id": "PostgreSQL_37", + "db_id": "student_club", + "intent": "Insert a new event record and then immediately return the newly inserted event_id and event_name using a CTE with RETURNING.", + "error_sql": "insert into event (event_id, event_name, event_date, type, notes, location, status) values ('recNew123', 'Spring Gala', '2024-04-15', 'Social', 'Annual spring event', 'Main Hall', 'Open');", + "corrected_sql": "WITH j AS (INSERT INTO event (event_id, event_name, event_date, type, notes, location, status) VALUES ('recNew123', 'Spring Gala', '2024-04-15', 'Social', 'Annual spring event', 'Main Hall', 'Open') RETURNING event_id, event_name) SELECT event_id, event_name FROM j;", + "explanation": "The error_sql is a plain INSERT with no RETURNING clause, so it produces no result set that the caller can inspect. The corrected_sql wraps the INSERT in a CTE using RETURNING event_id, event_name to capture the inserted values, then SELECTs from the CTE to return them to the caller. This is the standard PostgreSQL pattern for INSERT ... RETURNING used within a composable query." + }, + { + "instance_id": "PostgreSQL_38", + "db_id": "european_football_2", + "intent": "Create a trigger that logs a row to a player_name_audit table whenever the player_name column changes, recording the old name, new name, and change timestamp.", + "error_sql": "CREATE OR REPLACE FUNCTION log_player_name_changes() RETURNS trigger AS $BODY$ BEGIN IF NEW.player_name <> OLD.player_name THEN INSERT INTO player_name_audit (player_api_id, old_name, new_name) VALUES (NEW.player_api_id, OLD.player_name, NEW.player_name); END IF; RETURN NEW; END; $BODY$ LANGUAGE plpgsql; CREATE TRIGGER trg_log_player_name AFTER UPDATE ON Player FOR EACH ROW EXECUTE PROCEDURE log_player_name_changes();", + "corrected_sql": "CREATE OR REPLACE FUNCTION log_player_name_changes() RETURNS trigger AS $BODY$ BEGIN IF NEW.player_name <> OLD.player_name OR (NEW.player_name IS NOT NULL AND OLD.player_name IS NULL) THEN INSERT INTO player_name_audit (player_api_id, old_name, new_name, changed_at) VALUES (NEW.player_api_id, OLD.player_name, NEW.player_name, NOW()); END IF; RETURN NEW; END; $BODY$ LANGUAGE plpgsql; CREATE TRIGGER trg_log_player_name AFTER UPDATE OF player_name ON Player FOR EACH ROW EXECUTE PROCEDURE log_player_name_changes();", + "explanation": "The error_sql uses <> to compare names but this returns NULL (not TRUE) when either name is NULL, silently skipping NULL-to-value transitions. The corrected_sql adds an explicit IS NULL check to handle the case where old_name was NULL and a new name was assigned. The INSERT also adds the changed_at timestamp column to the audit record, and the trigger is tightened to fire only on UPDATE OF player_name rather than any update to the row." + }, + { + "instance_id": "PostgreSQL_39", + "db_id": "codebase_community", + "intent": "Find all users in preference_tag whose tag array contains both 'python' and 'machine_learning' as substrings of any tag element.", + "error_sql": "SELECT DISTINCT userid, tag FROM preference_tag WHERE tag @> (ARRAY['python', 'machine_learning']::VARCHAR[]);", + "corrected_sql": "SELECT t.userid, t.tag FROM preference_tag t WHERE NOT EXISTS (SELECT FROM unnest('{%python%, %machine_learning%}'::text[]) AS pattern WHERE NOT EXISTS (SELECT FROM unnest(t.tag) AS elem WHERE elem LIKE pattern));", + "explanation": "The @> array containment operator requires exact element matches, so 'python' would not match a tag like 'python3' or 'python-dev'. The corrected_sql uses NOT EXISTS with unnest and LIKE to check that every required pattern has at least one matching element in the user's tag array, enabling substring matching. This correctly finds users whose tags contain 'python' and 'machine_learning' as substrings rather than exact values." + }, + { + "instance_id": "PostgreSQL_40", + "db_id": "financial", + "intent": "Select all rows from account_info where the JSONB condition column contains a rootcompanyid of 12 inside the nested conditions structure.", + "error_sql": "SELECT * FROM account_info WHERE ((condition->0->>'conditions')::json->>'rootcompanyid')::json->>'$in' = '[12]';", + "corrected_sql": "SELECT * FROM account_info WHERE condition::jsonb @> '[{\"conditions\": {\"rootcompanyid\": {\"$in\": [12]}}}]';", + "explanation": "The error_sql uses repeated ->> text extraction and re-casts, which is fragile and only works if the exact JSON structure matches at every level without any type mismatches. The corrected_sql uses the @> (contains) JSONB operator, which checks that the condition column's JSONB value includes the specified nested structure anywhere in the array, and uses integer 12 rather than the string '[12]' to correctly match the numeric value." + }, + { + "instance_id": "PostgreSQL_41", + "db_id": "superhero", + "intent": "Create a unique constraint on hero_power that prevents duplicate (hero_id, power_id) pairs but only for rows where the 'is_primary' column is TRUE.", + "error_sql": "ALTER TABLE hero_power ADD CONSTRAINT unique_primary_hero_power UNIQUE (hero_id, power_id);", + "corrected_sql": "CREATE UNIQUE INDEX idx_hero_power_primary ON hero_power (hero_id, power_id) WHERE is_primary = TRUE;", + "explanation": "A standard UNIQUE constraint applies to all rows in the table, so it would prevent any two rows with the same (hero_id, power_id) regardless of is_primary, which is too restrictive. The corrected_sql uses a partial unique index with WHERE is_primary = TRUE, which enforces uniqueness only among rows where is_primary is true while allowing duplicate (hero_id, power_id) combinations when is_primary is false. Partial indexes are the PostgreSQL mechanism for conditional uniqueness." + }, + { + "instance_id": "PostgreSQL_42", + "db_id": "toxicology", + "intent": "Find distinct users who placed an order in the 'premium' segment to 'Boston' OR in the 'budget' segment to 'Chicago', but not users who appear in both groups.", + "error_sql": "SELECT DISTINCT(user_id), email FROM orders o WHERE (o.segment = 'premium' AND o.destination = 'Boston') OR (o.segment = 'budget' AND o.destination = 'Chicago');", + "corrected_sql": "SELECT DISTINCT o1.user_id, o1.email FROM orders o1 WHERE (o1.segment = 'premium' AND o1.destination = 'Boston') OR (o1.segment = 'budget' AND o1.destination = 'Chicago') AND NOT EXISTS (SELECT 1 FROM orders o2 WHERE o2.user_id = o1.user_id AND o2.segment = 'premium' AND o2.destination = 'Boston') OR NOT EXISTS (SELECT 1 FROM orders o3 WHERE o3.user_id = o1.user_id AND o3.segment = 'budget' AND o3.destination = 'Chicago');", + "explanation": "The error_sql returns users appearing in either group including those in both, but the intent requires exclusive OR (XOR) \u2014 users in one group but not both. The corrected_sql adds NOT EXISTS checks to exclude users who appear in both the premium-Boston and budget-Chicago groups, effectively implementing set difference. The DISTINCT is also applied properly to deduplicate the final result." + }, + { + "instance_id": "PostgreSQL_43", + "db_id": "formula_1", + "intent": "Sort version strings like '2.10.3-release' in ascending semantic order (major, minor, patch as integers), not lexicographically.", + "error_sql": "SELECT version FROM cars ORDER BY SUBSTRING(version, '^[0-9]+') DESC, SUBSTRING(version, '[0-9]+\\.[0-9]+\\.([0-9]+)-') DESC;", + "corrected_sql": "SELECT version FROM cars ORDER BY CAST(SUBSTRING(version FROM '^[0-9]+') AS INTEGER) ASC, CAST(SUBSTRING(version FROM '[0-9]+\\.([0-9]+)') AS INTEGER) ASC, CAST(SUBSTRING(version FROM '[0-9]+\\.[0-9]+\\.([0-9]+)') AS INTEGER) ASC;", + "explanation": "The error_sql sorts the SUBSTRING results as text strings, so '10' sorts before '9' lexicographically even though 10 > 9 numerically, producing incorrect semantic version order. The corrected_sql wraps each SUBSTRING in CAST(... AS INTEGER) to force numeric comparison for each version component. The sort direction is also changed to ASC to match the ascending order requested in the intent." + }, + { + "instance_id": "PostgreSQL_44", + "db_id": "formula_1", + "intent": "For each driver, calculate their total championship points across all races in the 2009 season only.", + "error_sql": "SELECT r.driverId, ((SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId) - (SELECT COALESCE(SUM(r2.points), 0) FROM results r2 WHERE r2.raceId = races.raceId - 1)) AS points_diff FROM results r JOIN races ON r.raceId = races.raceId;", + "corrected_sql": "SELECT d.driverId, COALESCE(SUM(r.points), 0) AS total_points FROM drivers d LEFT JOIN results r ON d.driverId = r.driverId LEFT JOIN races ra ON r.raceId = ra.raceId AND ra.year = 2009 GROUP BY d.driverId ORDER BY total_points DESC;", + "explanation": "The error_sql calculates point differentials between consecutive races rather than total season points, and uses correlated subqueries that reference outer aliases incorrectly causing ambiguous column errors. The corrected_sql uses a straightforward LEFT JOIN from drivers through results to races, filters to year=2009 in the JOIN condition (so drivers with no 2009 races still appear with 0 points), and sums points per driver using a simple GROUP BY." + }, + { + "instance_id": "PostgreSQL_45", + "db_id": "superhero", + "intent": "Show, for each race type (alignment), the total number of superheroes and the breakdown by race, returning alignment, race, and counts.", + "error_sql": "select count(S.id), A.alignment, count(R.race), R.race from superhero S, alignment A, race R where S.alignment_id=A.id and S.race_id=R.id GROUP BY A.alignment;", + "corrected_sql": "SELECT sqA.alignment_count AS total_by_alignment, A.alignment AS alignment, R.race AS race, COUNT(S.id) AS race_count FROM superhero S JOIN alignment A ON S.alignment_id = A.id JOIN race R ON S.race_id = R.id JOIN (SELECT alignment_id, COUNT(*) AS alignment_count FROM superhero GROUP BY alignment_id) sqA ON sqA.alignment_id = S.alignment_id GROUP BY A.alignment, R.race, sqA.alignment_count ORDER BY A.alignment, race_count DESC;", + "explanation": "The error_sql groups only by A.alignment, but then selects R.race and count(S.id) which are not in the GROUP BY, causing an aggregation error. The corrected_sql groups by both A.alignment and R.race and joins a subquery that pre-computes the per-alignment total (alignment_count) so that value can be displayed alongside each race breakdown row. The result correctly shows alignment totals and per-race counts in the same output." + }, + { + "instance_id": "PostgreSQL_46", + "db_id": "formula_1", + "intent": "For each row in results, show the driverId, points, and a running array of all driverIds ordered by points descending (most points first).", + "error_sql": "select driverId, points, lead(driverId) over (order by points desc) as lead_driver, array_agg(driverId) over (order by points desc) as running_drivers from results;", + "corrected_sql": "select driverId, points, array_agg(driverId) over (order by points desc) as running_drivers, array_agg(driverId) over (order by points desc rows between unbounded preceding and current row) as cumulative_drivers from results;", + "explanation": "The error_sql includes a lead() window function but the intent only asks for array_agg running totals, making lead() irrelevant and distracting. More critically, the default window frame for array_agg with ORDER BY is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which can include tied rows in unexpected ways. The corrected_sql uses an explicit ROWS frame to ensure a strict running accumulation and removes the extraneous lead() call, providing clear running arrays ordered by points descending." + }, + { + "instance_id": "PostgreSQL_47", + "db_id": "formula_1", + "intent": "For each race, divide pit stop records into groups of 3, and for each group return the raceId, group number, and the average pit stop duration in that group.", + "error_sql": "SELECT raceId, MAX(time::time) AS end_time, MIN(time::time) AS start_time, (MAX(time::time) - MIN(time::time)) AS duration FROM pitstops GROUP BY raceId;", + "corrected_sql": "WITH cte AS (SELECT *, CEIL((ROW_NUMBER() OVER (PARTITION BY raceId ORDER BY stop)) / 3.0) AS grp FROM pitstops) SELECT raceId, grp, AVG(EXTRACT(EPOCH FROM duration::interval)) AS avg_duration_seconds FROM cte GROUP BY raceId, grp ORDER BY raceId, grp;", + "explanation": "The error_sql casts the time column directly to ::time and computes MAX - MIN per race, which gives total race time span rather than grouping pit stops into buckets of 3. The corrected_sql uses ROW_NUMBER() partitioned by raceId and divided by 3 (with CEIL) to assign each pit stop to a group of 3, then aggregates the duration per group. This correctly implements the 'groups of 3 pit stops' bucketing." + }, + { + "instance_id": "PostgreSQL_48", + "db_id": "toxicology", + "intent": "For each unique label in the molecule table, aggregate all associated atom IDs into a JSON array, and return a single JSON object mapping each label to its atom array.", + "error_sql": "select label, JSON_AGG(JSON_BUILD_OBJECT(atom.molecule_id, atom.atom_id)) AS groupedAtoms FROM molecule JOIN atom ON molecule.molecule_id = atom.molecule_id GROUP BY label;", + "corrected_sql": "SELECT json_object_agg(label, groupedAtoms) AS atoms_by_label FROM (SELECT label, json_agg(json_build_object('molecule_id', atom.molecule_id, 'atom_id', atom.atom_id)) AS groupedAtoms FROM molecule JOIN atom ON molecule.molecule_id = atom.molecule_id GROUP BY label) sub;", + "explanation": "The error_sql returns one row per label with a JSON array, but the intent is a single JSON object with labels as keys mapping to their atom arrays. The corrected_sql wraps the per-label aggregation in a subquery and applies json_object_agg(label, groupedAtoms) in the outer query to collapse all label-to-array pairs into one JSON object. The json_build_object call is also fixed to use named keys ('molecule_id', 'atom_id') instead of using molecule_id as a dynamic key." + }, + { + "instance_id": "PostgreSQL_49", + "db_id": "toxicology", + "intent": "For each molecule, count the number of distinct chlorine ('cl') atoms and fluorine ('f') atoms separately, returning molecule_id, cl_atoms count, and f_atoms count.", + "error_sql": "SELECT molecule_id, COALESCE(SUM(CASE WHEN element = 'cl' THEN 1 ELSE 0 END), 0) cl_atoms, COALESCE(SUM(CASE WHEN element = 'f' THEN 1 ELSE 0 END), 0) f_atoms FROM atom GROUP BY molecule_id;", + "corrected_sql": "SELECT molecule_id, COUNT(DISTINCT CASE WHEN element = 'cl' THEN atom_id END) AS cl_atoms, COUNT(DISTINCT CASE WHEN element = 'f' THEN atom_id END) AS f_atoms FROM atom GROUP BY molecule_id;", + "explanation": "The error_sql uses SUM(CASE WHEN ...) which counts total occurrences of each element including duplicates, whereas the intent requires distinct atom counts per element. The corrected_sql uses COUNT(DISTINCT CASE WHEN element = 'cl' THEN atom_id END) to count only unique atom_ids matching each element type, ensuring duplicate atom records do not inflate the counts. The element targets are also updated from 'na' to 'cl' and from 'c' to 'f' to match the new intent." + } +] \ No newline at end of file diff --git a/src/db_confirmed_fixes/info.py b/src/db_confirmed_fixes/info.py new file mode 100644 index 0000000..1104251 --- /dev/null +++ b/src/db_confirmed_fixes/info.py @@ -0,0 +1,127 @@ +""" +Seed db_confirmed_fixes.json into per-database ChromaDB instances. + +Run: + python -m src.db_confirmed_fixes.info + +Reads db_confirmed_fixes.json, groups entries by db_id, and upserts each +entry into a database-specific ChromaDB collection under chroma//. +The intent field is embedded as the document; all other fields are stored +as metadata. +""" + +import hashlib +import json +import re +from collections import defaultdict +from datetime import datetime, timezone +from pathlib import Path + +import chromadb +from chromadb.utils import embedding_functions + +# --------------------------------------------------------------------------- +# Configuration (mirrors store.py constants) +# --------------------------------------------------------------------------- + +COLLECTION_NAME = "db_confirmed_fixes" +EMBEDDING_MODEL = "all-MiniLM-L6-v2" +CHROMA_BASE_PATH = Path(__file__).parent / "chroma" +DATA_FILE = Path(__file__).parent / "db_confirmed_fixes.json" + + +def _get_chroma_collection(database_name: str) -> chromadb.Collection: + """ + Create (or open) a ChromaDB persistent collection for the given database. + """ + sanitized_db_name = re.sub(r"[^a-zA-Z0-9_\-]", "_", database_name) + db_path = CHROMA_BASE_PATH / sanitized_db_name + db_path.mkdir(parents=True, exist_ok=True) + + client = chromadb.PersistentClient(path=str(db_path)) + emb_fn = embedding_functions.SentenceTransformerEmbeddingFunction( + model_name=EMBEDDING_MODEL + ) + + collection = client.get_or_create_collection( + name=COLLECTION_NAME, + embedding_function=emb_fn, + metadata={"hnsw:space": "cosine"}, + ) + return collection + + +def seed_confirmed_fixes() -> dict[str, int]: + """ + Read db_confirmed_fixes.json and upsert all entries into per-database + ChromaDB collections. + + Returns a dict of {db_id: count_seeded}. + """ + with open(DATA_FILE, "r", encoding="utf-8") as f: + entries = json.load(f) + + # Group by db_id + by_db: dict[str, list[dict]] = defaultdict(list) + for entry in entries: + by_db[entry["db_id"]].append(entry) + + confirmed_at = datetime.now(timezone.utc).isoformat() + summary: dict[str, int] = {} + + for db_id, db_entries in sorted(by_db.items()): + collection = _get_chroma_collection(db_id) + + documents = [] + metadatas = [] + ids = [] + + for entry in db_entries: + intent = entry["intent"] + corrected_sql = entry["corrected_sql"] + error_sql = entry["error_sql"] + explanation = entry["explanation"] + + # Deterministic ID from db + intent + corrected_sql + doc_id = hashlib.sha256( + f"{db_id}::{intent}::{corrected_sql}".encode("utf-8") + ).hexdigest()[:16] + + metadata = { + "intent": intent, + "corrected_sql": corrected_sql, + "error_sql": error_sql, + "explanation": explanation, + "confirmed_at": confirmed_at, + "usage_count": 0, + } + + documents.append(intent) + metadatas.append(metadata) + ids.append(doc_id) + + # Batch upsert all entries for this database at once + collection.upsert( + documents=documents, + metadatas=metadatas, + ids=ids, + ) + + summary[db_id] = len(db_entries) + print(f" ✓ {db_id}: {len(db_entries)} entries seeded") + + return summary + + +def main(): + print(f"Reading confirmed fixes from {DATA_FILE}") + print(f"ChromaDB base path: {CHROMA_BASE_PATH}\n") + + summary = seed_confirmed_fixes() + + total = sum(summary.values()) + print(f"\nDone! Seeded {total} entries across {len(summary)} databases.") + + +if __name__ == "__main__": + main() diff --git a/src/db_confirmed_fixes/retriever.py b/src/db_confirmed_fixes/retriever.py new file mode 100644 index 0000000..f921fda --- /dev/null +++ b/src/db_confirmed_fixes/retriever.py @@ -0,0 +1,310 @@ +import hashlib +import re +from datetime import datetime, timezone +from pathlib import Path +from typing import Any, Dict, List, Optional + +import chromadb + +# --------------------------------------------------------------------------- +# Configuration +# --------------------------------------------------------------------------- + +COLLECTION_NAME = "db_confirmed_fixes" +EMBEDDING_MODEL = "all-MiniLM-L6-v2" +CHROMA_BASE_PATH = Path(__file__).parent / "chroma" + +# --------------------------------------------------------------------------- +# Global Cache for Collections +# --------------------------------------------------------------------------- + +_COLLECTION_CACHE: Dict[str, chromadb.Collection] = {} + + +# --------------------------------------------------------------------------- +# Functions +# --------------------------------------------------------------------------- + + +def _get_collection(database_name: str) -> chromadb.Collection: + """ + Lazily initializes and caches a ChromaDB persistent client for the given database. + """ + if database_name in _COLLECTION_CACHE: + return _COLLECTION_CACHE[database_name] + + # Sanitize database name for directory use + sanitized_db_name = re.sub(r"[^a-zA-Z0-9_\-]", "_", database_name) + db_path = CHROMA_BASE_PATH / sanitized_db_name + + # Create directory if it doesn't exist + db_path.mkdir(parents=True, exist_ok=True) + + client = chromadb.PersistentClient(path=str(db_path)) + + # We rely on ChromaDB's default embedding function, which under the hood + # uses sentence-transformers all-MiniLM-L6-v2. Thus, passing nothing defaults to it. + # To be explicit and handle it exactly as search_similar_query does: + from chromadb.utils import embedding_functions + + # Initialize the specific model + emb_fn = embedding_functions.SentenceTransformerEmbeddingFunction( + model_name=EMBEDDING_MODEL + ) + + collection = client.get_or_create_collection( + name=COLLECTION_NAME, + embedding_function=emb_fn, + metadata={"hnsw:space": "cosine"} + ) + + _COLLECTION_CACHE[database_name] = collection + return collection + + +def save_confirmed_fix( + *, + database: str, + intent: str, + corrected_sql: str, + error_sql: str, + explanation: str, + confirmed_at: Optional[str] = None, +) -> Dict[str, Any]: + """ + Saves a confirmed SQL fix to the database-specific ChromaDB store. + Deduplicates using intent similarity threshold of 0.8. + Returns {"status": "saved", "id": doc_id} or {"status": "duplicate", "matched_id": id}. + """ + collection = _get_collection(database) + + # 1. Deduplication Gate + # Ask for top 5 most similar items by intent embedding + results = None + try: + fetch_count = min(5, collection.count()) + if fetch_count > 0: + results = collection.query( + query_texts=[intent], + n_results=fetch_count, + include=["documents", "metadatas", "distances"], + ) + except Exception: + # Ignore query errors on an empty or freshly-created collection + pass + + if results and results["documents"] and results["documents"][0]: + docs = results["documents"][0] + metas = results["metadatas"][0] + dists = results["distances"][0] + ids = results["ids"][0] + + for doc, meta, dist, doc_id in zip(docs, metas, dists, ids): + similarity = 1.0 - dist + # Deduplicate directly on intent semantic distance >= 0.8 + if similarity >= 0.8: + return {"status": "duplicate", "matched_id": doc_id} + + # 2. Save Item + doc_id = hashlib.sha256( + f"{database}::{intent}::{corrected_sql}".encode("utf-8") + ).hexdigest()[:16] + + if not confirmed_at: + confirmed_at = datetime.now(timezone.utc).isoformat() + + metadata = { + "intent": intent, + "corrected_sql": corrected_sql, + "error_sql": error_sql, + "explanation": explanation, + "confirmed_at": confirmed_at, + "usage_count": 0, + } + + import logging + logger = logging.getLogger("db_skills_benchmark") + logger.debug(f"ChromaDB Upsert -> Intent: {intent[:50]}... | Explanation: {explanation[:50]}...") + + collection.upsert( + documents=[intent], + metadatas=[metadata], + ids=[doc_id], + ) + + # 3. Prune if needed + try: + count = collection.count() + if count > 500: + prune_confirmed_fixes(database, max_items=500) + except Exception: + pass + + return {"status": "saved", "id": doc_id} + + +def find_similar_confirmed_fixes( + intent: str, database: str, n_results: int = 4 +) -> List[Dict[str, Any]]: + """ + Query the collection for the top candidates by intent similarity. + """ + try: + collection = _get_collection(database) + + # Check if collection is empty + if collection.count() == 0: + return [] + + results = collection.query( + query_texts=[intent], + n_results=min(n_results, collection.count()), + include=["documents", "metadatas", "distances"], + ) + + if not results or not results["documents"] or not results["documents"][0]: + return [] + + docs = results["documents"][0] + metas = results["metadatas"][0] + dists = results["distances"][0] + ids = results["ids"][0] + + candidates = [] + ids_to_increment = [] + metadatas_to_update = [] + + for doc, meta, dist, doc_id in zip(docs, metas, dists, ids): + similarity = 1.0 - dist + candidates.append( + { + "intent": doc, + "error_sql": meta.get("error_sql", ""), + "corrected_sql": meta.get("corrected_sql", ""), + "explanation": meta.get("explanation", ""), + "similarity": round(similarity, 4), + } + ) + # Queue usage_count increment for this candidate + current_count = int(meta.get("usage_count", 0)) + updated_meta = dict(meta) + updated_meta["usage_count"] = current_count + 1 + ids_to_increment.append(doc_id) + metadatas_to_update.append(updated_meta) + + # Best-effort increment usage_count + if ids_to_increment: + try: + collection.update( + ids=ids_to_increment, + metadatas=metadatas_to_update + ) + except Exception: + pass + + return candidates + + except Exception: + # Wrap all in try/except and return safe defaults (empty list) + return [] + + +def prune_confirmed_fixes(database: str, max_items: int = 500) -> int: + """ + Deletes items according to tiers to bring count down to max_items. + Returns number of items deleted. + """ + try: + collection = _get_collection(database) + count = collection.count() + + if count <= max_items: + return 0 + + # Need to fetch everything to sort by age + # This could be memory intensive for huge collections, + # but max_items is small (~500) so it's fine. + results = collection.get(include=["metadatas"]) + if not results or not results["metadatas"]: + return 0 + + ids = results["ids"] + metas = results["metadatas"] + + now = datetime.now(timezone.utc) + + items = [] + for doc_id, meta in zip(ids, metas): + usage_count = int(meta.get("usage_count", 0)) + confirmed_at_str = meta.get("confirmed_at", "") + + age_days = 0.0 + if confirmed_at_str: + try: + # Parse ISO format. Handle Z explicitly if needed. + if confirmed_at_str.endswith("Z"): + confirmed_at_str = confirmed_at_str[:-1] + "+00:00" + + confirmed_at = datetime.fromisoformat(confirmed_at_str) + + # Ensure timezone awareness + if confirmed_at.tzinfo is None: + confirmed_at = confirmed_at.replace(tzinfo=timezone.utc) + + delta = now - confirmed_at + age_days = delta.total_seconds() / (24 * 3600) + except Exception: + # Treat ambiguous age as 0 + pass + + items.append({ + "id": doc_id, + "usage_count": usage_count, + "age_days": age_days, + }) + + # Priority 1: usage_count == 0 AND age_days >= 30 + tier_1 = [item for item in items if item["usage_count"] == 0 and item["age_days"] >= 30] + # Priority 2: usage_count == 0 AND age_days >= 7 + tier_2 = [item for item in items if item["usage_count"] == 0 and item["age_days"] >= 7] + # Priority 3: usage_count == 1 AND age_days >= 90 + tier_3 = [item for item in items if item["usage_count"] == 1 and item["age_days"] >= 90] + + # Order of deletion + seen_ids = set() + candidates = [] + + # Add tier 1 (sort older first) + tier_1.sort(key=lambda x: x["age_days"], reverse=True) + for item in tier_1: + if item["id"] not in seen_ids: + candidates.append(item) + seen_ids.add(item["id"]) + + # Add tier 2 (sort older first, exclude already in list) + tier_2.sort(key=lambda x: x["age_days"], reverse=True) + for item in tier_2: + if item["id"] not in seen_ids: + candidates.append(item) + seen_ids.add(item["id"]) + + # Add tier 3 (sort older first, exclude already in list) + tier_3.sort(key=lambda x: x["age_days"], reverse=True) + for item in tier_3: + if item["id"] not in seen_ids: + candidates.append(item) + seen_ids.add(item["id"]) + + to_delete_count = count - max_items + actual_delete_count = min(to_delete_count, len(candidates)) + + if actual_delete_count > 0: + ids_to_delete = [item["id"] for item in candidates[:actual_delete_count]] + collection.delete(ids=ids_to_delete) + return actual_delete_count + + return 0 + + except Exception: + # Wrap in try/except, return safe default + return 0 diff --git a/src/error_taxonomy/__init__.py b/src/error_taxonomy/__init__.py new file mode 100644 index 0000000..8e0959f --- /dev/null +++ b/src/error_taxonomy/__init__.py @@ -0,0 +1 @@ +# Error taxonomy package diff --git a/src/error_taxonomy/aggregation.md b/src/error_taxonomy/aggregation.md new file mode 100644 index 0000000..b1014f6 --- /dev/null +++ b/src/error_taxonomy/aggregation.md @@ -0,0 +1,109 @@ +# Skill: aggregation + +## Description +Covers errors related to aggregate functions (COUNT, SUM, AVG, MIN, +MAX): using aggregates without a required GROUP BY clause, missing +columns in GROUP BY, misusing HAVING in place of WHERE, and using +HAVING without GROUP BY. + +## Core Approaches + +### Approach 1: Aggregation Without GROUP BY +**When to use:** Tag is `aggregation_agg_no_groupby`. An aggregate +function is applied with non-aggregated columns in SELECT but no +GROUP BY is present. +**Steps:** +1. Identify all non-aggregated columns in the SELECT list. +2. Add a GROUP BY clause listing every non-aggregated column. + +**Example fix:** +```sql +-- Before (department is non-aggregated, no GROUP BY) +SELECT department, COUNT(*) FROM employees + +-- After +SELECT department, COUNT(*) FROM employees GROUP BY department +``` + +### Approach 2: Missing Column in GROUP BY +**When to use:** Tag is `aggregation_groupby_missing_col`. GROUP BY +exists but not all non-aggregated SELECT columns are listed in it. +**Steps:** +1. List every column in SELECT that is not inside an aggregate. +2. Add any missing columns to the GROUP BY clause. + +**Example fix:** +```sql +-- Before (location missing from GROUP BY) +SELECT department, location, COUNT(*) +FROM employees +GROUP BY department + +-- After +SELECT department, location, COUNT(*) +FROM employees +GROUP BY department, location +``` + +### Approach 3: HAVING Without GROUP BY +**When to use:** Tag is `aggregation_having_without_groupby`. HAVING +is used but there is no GROUP BY clause. +**Steps:** +1. Determine whether the intent requires grouping. +2. If yes: add the missing GROUP BY clause. +3. If no (simple scalar filter): replace HAVING with WHERE. + +**Example fix:** +```sql +-- Before (HAVING used without GROUP BY) +SELECT department, COUNT(*) FROM employees +HAVING COUNT(*) > 5 + +-- After +SELECT department, COUNT(*) FROM employees +GROUP BY department +HAVING COUNT(*) > 5 +``` + +### Approach 4: HAVING vs. WHERE Confusion +**When to use:** Tag is `aggregation_having_vs_where`. The condition +filters on a non-aggregated column but is placed in HAVING instead +of WHERE. +**Steps:** +1. Check whether the condition involves an aggregate function or a + plain column. +2. Move plain-column conditions to WHERE; keep aggregate conditions + in HAVING. + +**Example fix:** +```sql +-- Before (status is a plain column, not an aggregate) +SELECT department, COUNT(*) +FROM employees +GROUP BY department +HAVING status = 'active' + +-- After +SELECT department, COUNT(*) +FROM employees +WHERE status = 'active' +GROUP BY department +``` + +## Learned Examples + + + +### Example 1 — 2026-02-18 +**Original (broken):** +```sql +SELECT School FROM schools GROUP BY School HAVING COUNT() > 1 ORDER BY COUNT() DESC; +``` +**Fixed:** +```sql +SELECT school FROM schools WHERE county IN ('Alameda', 'Contra Costa') AND school IS NOT NULL GROUP BY school HAVING COUNT(DISTINCT county) = 2; +``` +**Approach used:** Used WHERE IN with GROUP BY and HAVING COUNT(DISTINCT ...) = N to find entities associated with multiple specific categories. + +--- + diff --git a/src/error_taxonomy/filter_conditions.md b/src/error_taxonomy/filter_conditions.md new file mode 100644 index 0000000..cbc1ddb --- /dev/null +++ b/src/error_taxonomy/filter_conditions.md @@ -0,0 +1,67 @@ +# Skill: filter + +## Description +Covers errors in WHERE clause conditions: missing WHERE clauses that +the question implies, conditions that reference the wrong column, and +type mismatches between a column's data type and the comparison value. + +## Core Approaches + +### Approach 1: Missing WHERE Clause +**When to use:** Tag is `filter_missing_where`. The natural language +question implies a filter (e.g. "find active users", "orders from +2023") but the SQL has no WHERE clause. +**Steps:** +1. Identify the filter condition from the question intent. +2. Determine the correct column and value from the schema. +3. Add the WHERE clause. + +**Example fix:** +```sql +-- Before (question asked for active users only) +SELECT * FROM users + +-- After +SELECT * FROM users WHERE status = 'active' +``` + +### Approach 2: Condition on Wrong Column +**When to use:** Tag is `filter_condition_wrong_col`. The WHERE +clause filters on a column that is not the right one for this +question's intent. +**Steps:** +1. Re-read the question to identify which attribute is being + filtered. +2. Find the correct column in the schema. +3. Replace the wrong column name in the WHERE condition. + +**Example fix:** +```sql +-- Before (filtering by name instead of email) +SELECT * FROM users WHERE name = 'alice@example.com' + +-- After +SELECT * FROM users WHERE email = 'alice@example.com' +``` + +### Approach 3: Type Mismatch in WHERE +**When to use:** Tag is `filter_condition_type_mismatch`. The +comparison value's type does not match the column's data type (e.g. +comparing an integer column to a quoted string). +**Steps:** +1. Check the column's data type via `describe_database_schema`. +2. Remove quotes if the column is numeric, or add quotes if it is + text. +3. For dates, ensure the value uses ISO-8601 format `'YYYY-MM-DD'`. + +**Example fix:** +```sql +-- Before (user_id is INTEGER, not VARCHAR) +SELECT * FROM orders WHERE user_id = '42' + +-- After +SELECT * FROM orders WHERE user_id = 42 +``` + +## Learned Examples + diff --git a/src/error_taxonomy/generic_skills.py b/src/error_taxonomy/generic_skills.py new file mode 100644 index 0000000..9f921e7 --- /dev/null +++ b/src/error_taxonomy/generic_skills.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +""" +Generic skills for SQL error taxonomy retrieval and feedback-loop updates. + +Skill files live in src/error_taxonomy/{category}.md, where {category} +is the taxonomy_category value from a ValidationError (e.g. "join_related", +"syntax", "aggregation", "semantic"). + +Skill file names match taxonomy categories 1-to-1, so adding a new category +only requires: + 1. Adding the new tags to ErrorTag in ast_parsers/tags.py + 2. Creating src/error_taxonomy/{new_category}.md +""" + +from __future__ import annotations + +from pathlib import Path + +SKILLS_DIR = Path(__file__).parent + + +def get_error_taxonomy_skill(error_category: str) -> str: + """ + Return the markdown skill file for the given taxonomy category. + + Args: + error_category: Taxonomy category string from ValidationError.taxonomy_category + (e.g. ``"join_related"``, ``"syntax"``, ``"aggregation"``). + + Returns: + Full markdown text of the skill file, or a short fallback message when + no skill file exists for that category. + """ + skill_path = SKILLS_DIR / f"{error_category}.md" + if not skill_path.exists(): + return ( + f"No skill file found for category '{error_category}'. " + "Use general SQL debugging approach." + ) + return skill_path.read_text(encoding="utf-8") + + diff --git a/src/error_taxonomy/join_related.md b/src/error_taxonomy/join_related.md new file mode 100644 index 0000000..9f9d136 --- /dev/null +++ b/src/error_taxonomy/join_related.md @@ -0,0 +1,91 @@ +# Skill: join + +## Description +Covers errors in JOIN construction: missing JOIN conditions (causing +a cross join), wrong join type (INNER vs. LEFT vs. RIGHT), extra +tables included in FROM/JOIN that are never used, or incorrect +column names used in ON conditions. + +## Core Approaches + +### Approach 1: Missing JOIN Condition +**When to use:** Tag is `join_missing_join`. Two tables appear in the +FROM clause but no ON condition links them, producing a cartesian +product. +**Steps:** +1. Identify the foreign key relationship between the two tables using + `describe_database_schema`. +2. Add an explicit JOIN ... ON clause with the correct key columns. + +**Example fix:** +```sql +-- Before (cross join between orders and users) +SELECT * FROM orders, users WHERE orders.status = 'active' + +-- After +SELECT * FROM orders +JOIN users ON orders.user_id = users.id +WHERE orders.status = 'active' +``` + +### Approach 2: Wrong Join Type +**When to use:** Tag is `join_wrong_type`. The query uses INNER JOIN +but some rows are missing because they have no match in the right +table (should be LEFT JOIN), or vice versa. +**Steps:** +1. Determine if all rows from the left table should appear regardless + of a match in the right table. +2. Switch INNER JOIN → LEFT JOIN (or RIGHT JOIN) as appropriate. + +**Example fix:** +```sql +-- Before (customers with no orders are excluded) +SELECT c.name, o.total +FROM customers +INNER JOIN orders o ON c.id = o.customer_id + +-- After +SELECT c.name, o.total +FROM customers c +LEFT JOIN orders o ON c.id = o.customer_id +``` + +### Approach 3: Unused Table in FROM/JOIN +**When to use:** Tag is `join_extra_table`. A table is listed in FROM +or JOIN but none of its columns appear anywhere in the query. +**Steps:** +1. Remove the unused table from the FROM/JOIN clause. +2. Remove any associated ON condition that referenced only that table. + +**Example fix:** +```sql +-- Before (categories table is unused) +SELECT p.name, p.price +FROM products p +JOIN categories c ON p.category_id = c.id +JOIN inventory i ON p.id = i.product_id + +-- After (if inventory is also unused) +SELECT p.name, p.price +FROM products p +JOIN categories c ON p.category_id = c.id +``` + +### Approach 4: Incorrect Column in ON Condition +**When to use:** Tag is `join_incorrect_col`. The ON clause uses a +column that does not exist on one of the joined tables. +**Steps:** +1. Inspect both tables' schemas. +2. Correct the column name(s) in the ON condition. + +**Example fix:** +```sql +-- Before (orders has no column "uid"; correct is "user_id") +SELECT * FROM orders JOIN users ON orders.uid = users.id + +-- After +SELECT * FROM orders JOIN users ON orders.user_id = users.id +``` + +## Learned Examples + diff --git a/src/error_taxonomy/logical.md b/src/error_taxonomy/logical.md new file mode 100644 index 0000000..14a8bd5 --- /dev/null +++ b/src/error_taxonomy/logical.md @@ -0,0 +1,107 @@ +# Skill: others + +## Description +Covers logical and runtime errors that do not fit the other +categories: constraint violations (unique, foreign key, NOT NULL, +check), grouping/window function errors, missing ORDER BY when the +question implies ranked output, missing LIMIT, and unsupported +function calls. + +## Core Approaches + +### Approach 1: Missing ORDER BY +**When to use:** Tag is `others_order_by_missing`. The question asks +for "top N", "most recent", "ranked", or "sorted" results but no +ORDER BY is present. +**Steps:** +1. Identify the column and direction implied by the question + (e.g. "most recent" → `ORDER BY created_at DESC`). +2. Add the ORDER BY clause before any LIMIT. + +**Example fix:** +```sql +-- Before (no ordering for "most recent 5 orders") +SELECT * FROM orders LIMIT 5 + +-- After +SELECT * FROM orders ORDER BY created_at DESC LIMIT 5 +``` + +### Approach 2: Missing LIMIT +**When to use:** Tag is `others_limit_missing`. The question asks for +"the top 1", "the single highest", or a specific count of rows but +no LIMIT is present. +**Steps:** +1. Determine how many rows the question expects. +2. Add `LIMIT N` after ORDER BY. + +**Example fix:** +```sql +-- Before (question asked for the single most expensive product) +SELECT name, price FROM products ORDER BY price DESC + +-- After +SELECT name, price FROM products ORDER BY price DESC LIMIT 1 +``` + +### Approach 3: Duplicate Columns in SELECT +**When to use:** Tag is `others_duplicate_select`. The same column or +expression appears more than once in the SELECT list. +**Steps:** +1. Identify duplicated columns. +2. Remove all but one occurrence, or alias them if both are truly + needed for different purposes. + +**Example fix:** +```sql +-- Before +SELECT id, name, name FROM users + +-- After +SELECT id, name FROM users +``` + +### Approach 4: Unsupported Function +**When to use:** Tag is `others_unsupported_function`. A function is +called that does not exist in PostgreSQL (e.g. MySQL-specific +functions like `GROUP_CONCAT`, `IFNULL`, `NOW()` used as `SYSDATE`). +**Steps:** +1. Identify the PostgreSQL equivalent: + - `GROUP_CONCAT` → `STRING_AGG` + - `IFNULL` → `COALESCE` + - `SYSDATE` → `NOW()` + - `DATE_FORMAT` → `TO_CHAR` +2. Rewrite the expression using the correct function. + +**Example fix:** +```sql +-- Before (GROUP_CONCAT is MySQL-specific) +SELECT department, GROUP_CONCAT(name) FROM employees GROUP BY department + +-- After +SELECT department, STRING_AGG(name, ',') FROM employees GROUP BY department +``` + +### Approach 5: Incorrect Foreign Key Relationship +**When to use:** Tag is `others_incorrect_foreign_key_relationship`. +The query joins tables along an incorrect relationship path (e.g. +joining A→C directly when the actual path is A→B→C). +**Steps:** +1. Use `describe_database_schema` to trace the actual foreign key + relationships. +2. Add the intermediate join table(s) to traverse the correct path. + +**Example fix:** +```sql +-- Before (orders does not link directly to products; needs order_items) +SELECT p.name FROM orders o +JOIN products p ON o.id = p.order_id + +-- After +SELECT p.name FROM orders o +JOIN order_items oi ON o.id = oi.order_id +JOIN products p ON oi.product_id = p.id +``` + +## Learned Examples + diff --git a/src/error_taxonomy/semantic.md b/src/error_taxonomy/semantic.md new file mode 100644 index 0000000..94d333d --- /dev/null +++ b/src/error_taxonomy/semantic.md @@ -0,0 +1,85 @@ +# Skill: schema_link + +## Description +Covers errors where the query references tables, columns, or +functions that do not exist in the database schema, or where column +references are ambiguous across multiple joined tables. Corresponds +to PostgreSQL SQLSTATE class 42 (undefined/ambiguous object) errors. + +## Core Approaches + +### Approach 1: Hallucinated Table Name +**When to use:** Tag is `schema_hallucination_table`. PostgreSQL +reports a table does not exist. +**Steps:** +1. Call `describe_database_schema` to list available tables. +2. Find the closest matching table name (check for plural/singular, + underscores vs. spaces, abbreviated names). +3. Replace the non-existent table name with the correct one. + +**Example fix:** +```sql +-- Before (table "user" does not exist, correct name is "users") +SELECT * FROM user WHERE id = 1 + +-- After +SELECT * FROM users WHERE id = 1 +``` + +### Approach 2: Hallucinated Column Name +**When to use:** Tag is `schema_hallucination_col`. A column +referenced in SELECT, WHERE, JOIN, or GROUP BY does not exist on the +table. +**Steps:** +1. Call `describe_database_schema` for the relevant table(s). +2. Find the closest matching column (check abbreviations, different + naming conventions, correct table). +3. Replace the non-existent column with the correct one. + +**Example fix:** +```sql +-- Before ("username" does not exist, correct column is "user_name") +SELECT username FROM users WHERE id = 1 + +-- After +SELECT user_name FROM users WHERE id = 1 +``` + +### Approach 3: Ambiguous Column Reference +**When to use:** Tag is `schema_ambiguous_col`. Multiple joined +tables have a column with the same name and the query does not +qualify it. +**Steps:** +1. Identify all tables in the FROM/JOIN clause. +2. Determine which table the ambiguous column belongs to for this + query's intent. +3. Prefix the column with the correct table name or alias. + +**Example fix:** +```sql +-- Before ("id" is ambiguous between orders and users) +SELECT id FROM orders JOIN users ON orders.user_id = users.id + +-- After +SELECT orders.id FROM orders JOIN users ON orders.user_id = users.id +``` + +### Approach 4: Incorrect Foreign Key Column +**When to use:** Tag is `schema_incorrect_foreign_key`. The column +used for a join or foreign key reference does not match the actual +key column name. +**Steps:** +1. Inspect both tables' schemas to find the actual key columns. +2. Correct the join condition to use the right columns. + +**Example fix:** +```sql +-- Before (orders.customer does not exist; correct is orders.user_id) +SELECT * FROM orders JOIN users ON orders.customer = users.id + +-- After +SELECT * FROM orders JOIN users ON orders.user_id = users.id +``` + +## Learned Examples + diff --git a/src/error_taxonomy/set_operations.md b/src/error_taxonomy/set_operations.md new file mode 100644 index 0000000..6911c1b --- /dev/null +++ b/src/error_taxonomy/set_operations.md @@ -0,0 +1,96 @@ +# Skill: set_op + +## Description +Covers errors involving set operations: UNION, INTERSECT, and EXCEPT. +Common mistakes include using comma-separated queries instead of +UNION, column count or type mismatches between operands, and using +the wrong set operator for the intended logic. + +## Core Approaches + +### Approach 1: Missing UNION Operator +**When to use:** Tag is `set_op_union_missing`. Two SELECT statements +are written as if their results should be combined, but no UNION +(or UNION ALL) operator connects them. +**Steps:** +1. Identify the two SELECT blocks that should be unioned. +2. Insert `UNION` (for distinct rows) or `UNION ALL` (to keep + duplicates) between them. + +**Example fix:** +```sql +-- Before (two SELECTs with no connecting operator) +SELECT id, name FROM customers WHERE region = 'North' +SELECT id, name FROM customers WHERE region = 'South' + +-- After +SELECT id, name FROM customers WHERE region = 'North' +UNION +SELECT id, name FROM customers WHERE region = 'South' +``` + +### Approach 2: Missing INTERSECT +**When to use:** Tag is `set_op_intersect_missing`. The question asks +for rows that appear in both result sets, but the SQL uses UNION or +a join instead. +**Steps:** +1. Replace UNION with INTERSECT. +2. Ensure both SELECT branches have the same number of columns and + compatible types. + +**Example fix:** +```sql +-- Before (should find customers who are also suppliers) +SELECT id FROM customers +UNION +SELECT id FROM suppliers + +-- After +SELECT id FROM customers +INTERSECT +SELECT id FROM suppliers +``` + +### Approach 3: Missing EXCEPT +**When to use:** Tag is `set_op_except_missing`. The question asks +for rows in the first set that are not in the second, but the SQL +uses NOT IN or LEFT JOIN ... IS NULL instead of EXCEPT. +**Steps:** +1. Replace the NOT IN subquery or anti-join with EXCEPT. +2. Confirm column count and types match across both branches. + +**Example fix:** +```sql +-- Before (verbose NOT IN approach) +SELECT id FROM customers +WHERE id NOT IN (SELECT customer_id FROM orders) + +-- After (idiomatic set operation) +SELECT id FROM customers +EXCEPT +SELECT customer_id FROM orders +``` + +### Approach 4: Column Count or Type Mismatch in Set Operation +**When to use:** PostgreSQL raises an error that the number of +columns or their types differ between the operands. +**Steps:** +1. Count the columns in each SELECT branch. +2. Align them by adding NULL casts for missing columns or casting + mismatched types: `NULL::integer`, `NULL::text`, etc. + +**Example fix:** +```sql +-- Before (left branch has 3 columns, right has 2) +SELECT id, name, email FROM customers +UNION +SELECT id, name FROM suppliers + +-- After +SELECT id, name, email FROM customers +UNION +SELECT id, name, NULL::text FROM suppliers +``` + +## Learned Examples + diff --git a/src/error_taxonomy/structural.md b/src/error_taxonomy/structural.md new file mode 100644 index 0000000..eb9b4d4 --- /dev/null +++ b/src/error_taxonomy/structural.md @@ -0,0 +1,67 @@ +# Skill: select + +## Description +Covers errors in the SELECT clause itself: selecting incorrect or +extra columns that do not match the question intent, selecting +columns in the wrong order when a specific order is expected, and +selecting too many or too few values relative to what the question +asks for. + +## Core Approaches + +### Approach 1: Incorrect or Extra Columns Selected +**When to use:** Tag is `select_incorrect_extra_values`. The SELECT +list includes columns the question did not ask for, or omits columns +it did ask for. +**Steps:** +1. Re-read the question to determine the exact output columns + expected. +2. Remove columns not asked for; add columns that are missing. +3. Check the schema to confirm all selected columns exist. + +**Example fix:** +```sql +-- Before (question asked only for name and email, not phone) +SELECT name, email, phone FROM users WHERE active = TRUE + +-- After +SELECT name, email FROM users WHERE active = TRUE +``` + +### Approach 2: Columns Selected in Wrong Order +**When to use:** Tag is `select_incorrect_order`. The question +specifies an output order (e.g. "return name then salary") but the +SELECT list has them reversed. +**Steps:** +1. Map the expected output order from the question. +2. Reorder the columns in the SELECT list to match. + +**Example fix:** +```sql +-- Before (question asked for name then salary) +SELECT salary, name FROM employees ORDER BY name + +-- After +SELECT name, salary FROM employees ORDER BY name +``` + +### Approach 3: Missing Alias for Computed Column +**When to use:** A computed expression in SELECT has no alias, making +the output column name unclear or causing downstream reference +errors. +**Steps:** +1. Add an AS alias to every computed expression or aggregate. + +**Example fix:** +```sql +-- Before +SELECT department, COUNT(*), AVG(salary) FROM employees GROUP BY department + +-- After +SELECT department, COUNT(*) AS employee_count, AVG(salary) AS avg_salary +FROM employees +GROUP BY department +``` + +## Learned Examples + diff --git a/src/error_taxonomy/subquery_formulation.md b/src/error_taxonomy/subquery_formulation.md new file mode 100644 index 0000000..aaab03b --- /dev/null +++ b/src/error_taxonomy/subquery_formulation.md @@ -0,0 +1,90 @@ +# Skill: subquery + +## Description +Covers errors in subquery construction: subqueries that are written +but their result is never referenced, subqueries that are needed but +missing, and correlation errors where an inner subquery references an +outer alias incorrectly. + +## Core Approaches + +### Approach 1: Unused Subquery +**When to use:** Tag is `subquery_unused_subquery`. A subquery +appears in the FROM clause or CTE but its alias is never used +elsewhere in the query. +**Steps:** +1. Check whether the subquery result is referenced in the outer + SELECT, WHERE, JOIN, or GROUP BY. +2. If not needed: remove the entire subquery. +3. If needed: add the alias reference where the subquery's output + should be consumed. + +**Example fix:** +```sql +-- Before (subquery result "recent" never used) +SELECT u.name FROM users u, + (SELECT id FROM orders WHERE created_at > NOW() - INTERVAL '7 days') recent + +-- After +SELECT u.name +FROM users u +WHERE u.id IN ( + SELECT user_id FROM orders + WHERE created_at > NOW() - INTERVAL '7 days' +) +``` + +### Approach 2: Missing Subquery +**When to use:** Tag is `subquery_missing`. The question implies a +multi-step or filtered aggregation that needs a subquery but the SQL +attempts it in a single flat query. +**Steps:** +1. Identify the intermediate result that must be computed first. +2. Write an inner subquery or CTE that produces that result. +3. Reference it in the outer query. + +**Example fix:** +```sql +-- Before (cannot filter on aggregate directly without subquery) +SELECT department, avg_salary +FROM employees +WHERE AVG(salary) > 70000 +GROUP BY department + +-- After +SELECT department, avg_salary +FROM ( + SELECT department, AVG(salary) AS avg_salary + FROM employees + GROUP BY department +) dept_avgs +WHERE avg_salary > 70000 +``` + +### Approach 3: Subquery Correlation Error +**When to use:** Tag is `subquery_correlation_error`. The inner +subquery references an outer alias that is not in scope, or the +correlation column name is wrong. +**Steps:** +1. Identify the outer table alias the inner query is trying to + reference. +2. Confirm the alias is defined in the outer FROM/JOIN clause. +3. Correct the column or alias name in the inner subquery's WHERE. + +**Example fix:** +```sql +-- Before (outer alias "o" not defined at the subquery level) +SELECT * FROM orders +WHERE amount > ( + SELECT AVG(amount) FROM orders WHERE user_id = o.user_id +) + +-- After +SELECT * FROM orders o +WHERE amount > ( + SELECT AVG(amount) FROM orders WHERE user_id = o.user_id +) +``` + +## Learned Examples + diff --git a/src/error_taxonomy/syntax.md b/src/error_taxonomy/syntax.md new file mode 100644 index 0000000..72bf82e --- /dev/null +++ b/src/error_taxonomy/syntax.md @@ -0,0 +1,81 @@ +# Skill: syntax + +## Description +Covers malformed SQL such as misspelled keywords, missing or extra +commas, unbalanced parentheses, trailing delimiters, unterminated +string literals, and incorrect clause ordering. These are caught by +the sqlglot AST parser before the query reaches PostgreSQL. + +## Core Approaches + +### Approach 1: Keyword Typo Correction +**When to use:** Tag is `syntax_error`, `syntax_keyword_misuse`, or +`syntax_invalid_token`. The keyword itself is misspelled or wrong. +**Steps:** +1. Identify the misspelled keyword (e.g. `SELCT`, `FORM`, `WHER`, + `GORUP BY`). +2. Replace with the correct spelling. +3. Re-validate with `validate_query`. + +**Example fix:** +```sql +-- Before +SELCT name FORM users WHER id = 1 + +-- After +SELECT name FROM users WHERE id = 1 +``` + +### Approach 2: Trailing Delimiter Removal +**When to use:** Tag is `syntax_trailing_delimiter`. A comma appears +immediately before a clause keyword. +**Steps:** +1. Find the trailing comma preceding `FROM`, `WHERE`, `GROUP BY`, + `ORDER BY`, or `HAVING`. +2. Remove the comma. + +**Example fix:** +```sql +-- Before +SELECT name, age, FROM users + +-- After +SELECT name, age FROM users +``` + +### Approach 3: Unbalanced Parentheses +**When to use:** Tag is `syntax_unbalanced_tokens`. Opening and +closing parentheses counts do not match. +**Steps:** +1. Count `(` and `)` in the query. +2. Locate the clause where the mismatch first occurs. +3. Add or remove the missing parenthesis. + +**Example fix:** +```sql +-- Before +SELECT * FROM users WHERE (id = 1 AND name = 'Alice' + +-- After +SELECT * FROM users WHERE (id = 1 AND name = 'Alice') +``` + +### Approach 4: Unterminated String Literal +**When to use:** Tag is `syntax_unterminated_string`. A single-quote +is opened but never closed, or an odd number of single quotes exists. +**Steps:** +1. Find the unclosed string literal. +2. Add the missing closing single quote. +3. If the string itself needs a literal quote, escape it as `''`. + +**Example fix:** +```sql +-- Before +SELECT * FROM users WHERE name = 'O'Brien' + +-- After +SELECT * FROM users WHERE name = 'O''Brien' +``` + +## Learned Examples + diff --git a/src/error_taxonomy/value_representation.md b/src/error_taxonomy/value_representation.md new file mode 100644 index 0000000..8b60f8d --- /dev/null +++ b/src/error_taxonomy/value_representation.md @@ -0,0 +1,51 @@ +# Skill: value + +## Description +Covers errors where a hardcoded literal is used instead of a column +reference where a column was intended, or where the format of a +literal value is incompatible with the column's data type (e.g. wrong +date format, integer vs. string quoting). + +## Core Approaches + +### Approach 1: Hardcoded Literal Instead of Column +**When to use:** Tag is `value_hardcoded_value`. A SELECT list or +expression contains a constant string or number where a column name +was clearly intended. +**Steps:** +1. Identify the literal that should be a column reference. +2. Check the table schema to confirm the correct column name. +3. Replace the literal with the column reference. + +**Example fix:** +```sql +-- Before ('active' hardcoded where a column reference was intended) +SELECT id, 'active' FROM users + +-- After +SELECT id, status FROM users +``` + +### Approach 2: Value Format Incompatible With Column Type +**When to use:** Tag is `value_format_wrong`. The literal's format +does not match what PostgreSQL expects for that column type. +**Steps:** +1. Determine the column's PostgreSQL data type. +2. Reformat the literal to match: + - Dates: `'YYYY-MM-DD'` + - Timestamps: `'YYYY-MM-DD HH:MM:SS'` + - Booleans: `TRUE` / `FALSE` (no quotes) + - Integers: no quotes + - UUIDs: `'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'` + +**Example fix:** +```sql +-- Before (date in wrong format for PostgreSQL) +SELECT * FROM events WHERE event_date = '05/14/2023' + +-- After +SELECT * FROM events WHERE event_date = '2023-05-14' +``` + +## Learned Examples + diff --git a/src/query_intent_vectordb/embed_query_intent.py b/src/query_intent_vectordb/embed_query_intent.py index b444b1e..40adab8 100644 --- a/src/query_intent_vectordb/embed_query_intent.py +++ b/src/query_intent_vectordb/embed_query_intent.py @@ -33,7 +33,10 @@ def embed_and_store() -> None: path=str(CHROMA_PATH) ) - collection = client.get_or_create_collection(COLLECTION_NAME) + collection = client.get_or_create_collection( + name=COLLECTION_NAME, + metadata={"hnsw:space": "cosine"} + ) documents: list[str] = [] metadatas: list[dict] = [] diff --git a/src/query_intent_vectordb/query_intent_metadata.jsonl b/src/query_intent_vectordb/query_intent_metadata.jsonl index 9185167..413e971 100644 --- a/src/query_intent_vectordb/query_intent_metadata.jsonl +++ b/src/query_intent_vectordb/query_intent_metadata.jsonl @@ -1,500 +1,500 @@ -{"db_id": "debit_card_specializing", "intent": "What is the ratio of customers who pay in EUR against customers who pay in CZK?", "sql": "SELECT CAST(SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END), 0) FROM customers", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "In 2012, who had the least consumption in LAM?", "sql": "SELECT T1.CustomerID FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM' AND SUBSTR(T2.Date, 1, 4) = '2012' GROUP BY T1.CustomerID ORDER BY SUM(T2.Consumption) ASC NULLS FIRST LIMIT 1", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What was the average monthly consumption of customers in SME for the year 2013?", "sql": "SELECT AVG(T2.Consumption) / NULLIF(12, 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What was the difference in gas consumption between CZK-paying customers and EUR-paying customers in 2012?", "sql": "SELECT SUM(CASE WHEN T1.Currency = 'CZK' THEN CAST(T2.Consumption AS float) ELSE 0 END) -SUM(CASE WHEN T1.Currency = 'EUR' THEN CAST(T2.Consumption AS float) ELSE 0 END) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE substring(T2.Date, 1, 4) = '2012'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Which year recorded the most consumption of gas paid in CZK?", "sql": "SELECT SUBSTR(T2.Date, 1, 4) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' GROUP BY SUBSTR(T2.Date, 1, 4) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What was the gas consumption peak month for SME customers in 2013?", "sql": "SELECT SUBSTR(T2.Date, 5, 2) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME' GROUP BY SUBSTR(T2.Date, 5, 2) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What is the difference in the annual average consumption of the customers with the least amount of consumption paid in CZK for 2013 between SME and LAM, LAM and KAM, and KAM and SME?", "sql": "SELECT CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' AND T2.Consumption = (SELECT MIN(Consumption) FROM yearmonth) AND T2.Date::text BETWEEN '201301' AND '201312'", "complexity_score": 0.20800000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 13, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Which of the three segments\u2014SME, LAM and KAM\u2014has the biggest and lowest percentage increases in consumption paid in EUR between 2012 and 2013?", "sql": "SELECT CAST((SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID", "complexity_score": 0.189, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 9, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "How much did customer 6 consume in total between August and November 2013?", "sql": "SELECT SUM(Consumption) FROM yearmonth WHERE CustomerID = 6 AND Date BETWEEN '201308' AND '201311'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "How many more \"discount\" gas stations does the Czech Republic have compared to Slovakia?", "sql": "SELECT SUM(CASE WHEN Country = 'CZE' THEN 1 ELSE 0 END) - SUM(CASE WHEN Country = 'SVK' THEN 1 ELSE 0 END) FROM gasstations WHERE Segment = 'Discount'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Is it true that more SMEs pay in Czech koruna than in euros? If so, how many more?", "sql": "SELECT SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END) - SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) FROM customers WHERE Segment = 'SME'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "How many percent of LAM customer consumed more than 46.73?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Consumption > 46.73 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "In February 2012, what percentage of customers consumed more than 528.3?", "sql": "SELECT CAST(SUM(CASE WHEN Consumption > 528.3 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(CustomerID), 0) FROM yearmonth WHERE Date = '201202'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What is the highest monthly consumption in the year 2012?", "sql": "SELECT SUM(CAST(Consumption AS float)) FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2012' GROUP BY SUBSTR(Date, 5, 2) ORDER BY SUM(Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Please list the product description of the products consumed in September, 2013.", "sql": "SELECT T3.Description FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Date = '201309'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Please list the countries of the gas stations with transactions taken place in June, 2013.", "sql": "SELECT DISTINCT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN yearmonth AS T3 ON T1.CustomerID = T3.CustomerID WHERE T3.Date = '201306'", "complexity_score": 0.087, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Among the customers who paid in euro, how many of them have a monthly consumption of over 1000?", "sql": "SELECT COUNT(*) FROM yearmonth AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.Currency = 'EUR' AND T1.Consumption > 1000.00", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Please list the product descriptions of the transactions taken place in the gas stations in the Czech Republic.", "sql": "SELECT DISTINCT T3.Description FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Country = 'CZE'", "complexity_score": 0.087, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Please list the disparate time of the transactions taken place in the gas stations from chain no. 11.", "sql": "SELECT DISTINCT T1.Time FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.ChainID = 11", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Among the transactions made in the gas stations in the Czech Republic, how many of them are taken place after 2012/1/1?", "sql": "SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.Country = 'CZE' AND TO_CHAR(CAST(T1.Date AS TIMESTAMP), 'YYYY') >= '2012'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What kind of currency did the customer paid at 16:25:00 in 2012/8/24?", "sql": "SELECT DISTINCT T3.Currency FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN customers AS T3 ON T1.CustomerID = T3.CustomerID WHERE T1.Date = '2012-08-24' AND T1.Time = '16:25:00'", "complexity_score": 0.097, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What segment did the customer have at 2012/8/23 21:20:00?", "sql": "SELECT T2.Segment FROM transactions_1k AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.date = '2012-08-23' AND T1.time = '21:20:00'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "For all the transactions happened during 8:00-9:00 in 2012/8/26, how many happened in CZE?", "sql": "SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-26' AND T1.Time BETWEEN '08:00:00' AND '09:00:00' AND T2.Country = 'CZE'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What's the nationality of the customer who spent 548.4 in 2012/8/24?", "sql": "SELECT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-24' AND T1.Price = '548.4'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What is the percentage of the customers who used EUR in 2012/8/25?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Currency = 'EUR' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.CustomerID), 0) FROM transactions_1k AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Date = '2012-08-25'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "For the customer who paid 634.8 in 2012/8/25, what was the consumption decrease rate from Year 2012 to 2013?", "sql": "SELECT CAST(SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2012' THEN Consumption ELSE 0 END) - SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2013' THEN Consumption ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2012' THEN Consumption ELSE 0 END), 0) FROM yearmonth WHERE CustomerID = (SELECT T1.CustomerID FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-25' AND T1.Price = 1513.12 )", "complexity_score": 0.17300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What is the percentage of \"premium\" against the overall segment in Country = \"SVK\"?", "sql": "SELECT CAST(SUM(CASE WHEN Country = 'SVK' AND Segment = 'Premium' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Country = 'SVK' THEN 1 ELSE 0 END), 0) FROM gasstations", "complexity_score": 0.032, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "What is the amount spent by customer \"38508\" at the gas stations? How much had the customer spent in January 2012?", "sql": "SELECT SUM(T1.Price ), SUM(CASE WHEN T3.Date = '201201' THEN T1.Price ELSE 0 END) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN yearmonth AS T3 ON T1.CustomerID = T3.CustomerID WHERE T1.CustomerID = '38508'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "Who is the top spending customer and how much is the average price per single item purchased by this customer? What currency was being used?", "sql": "SELECT T2.CustomerID, SUM(T2.Price / NULLIF(T2.Amount, 0)), T1.Currency FROM customers AS T1 INNER JOIN transactions_1k AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.CustomerID = (SELECT CustomerID FROM yearmonth ORDER BY Consumption DESC NULLS LAST LIMIT 1) GROUP BY T2.CustomerID, T1.Currency", "complexity_score": 0.14400000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "debit_card_specializing", "intent": "For all the people who paid more than 29.00 per unit of product id No.5. Give their consumption status in the August of 2012.", "sql": "SELECT T2.Consumption FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Price / NULLIF(T1.Amount, 0) > 29.00 AND T1.ProductID = 5 AND T2.Date = '201208'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What's Angela Sanders's major?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.first_name = 'Angela' AND T1.last_name = 'Sanders'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Among the students from the Student_Club who attended the event \"Women's Soccer\", how many of them want a T-shirt that's in medium size?", "sql": "SELECT COUNT(T1.event_id) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event INNER JOIN member AS T3 ON T2.link_to_member = T3.member_id WHERE T1.event_name = 'Women''s Soccer' AND T3.t_shirt_size = 'Medium'", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Among the events attended by more than 10 members of the Student_Club, how many of them are meetings?", "sql": "SELECT COUNT(DISTINCT T1.event_id) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event WHERE T1.type = 'Meeting' GROUP BY T1.event_id HAVING COUNT(T2.link_to_event) > 10", "complexity_score": 0.07100000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List all the names of events that had an attendance of over 20 students but were not fundraisers.", "sql": "SELECT T1.event_name FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event GROUP BY T1.event_id HAVING COUNT(T2.link_to_event) > 20 EXCEPT SELECT T1.event_name FROM event AS T1 WHERE T1.type = 'Fundraiser'", "complexity_score": 0.065, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-EXCEPT", "clauses_present": ["EXCEPT", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What is the amount of the funds that the Vice President received?", "sql": "SELECT T2.amount FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Vice President'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List the full name of the Student_Club members that grew up in Illinois state.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN zip_code AS T2 ON T1.zip = T2.zip_code WHERE T2.state = 'Illinois'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Was each expense in October Meeting on October 8, 2019 approved?", "sql": "SELECT T3.approved FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' AND T1.event_date LIKE '2019-10-08%'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Calculate the total average cost that Elijah Allen spent in the events on September and October.", "sql": "SELECT AVG(T2.cost) FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.last_name = 'Allen' AND T1.first_name = 'Elijah' AND (SUBSTR(T2.expense_date, 6, 2) = '09' OR SUBSTR(T2.expense_date, 6, 2) = '10')", "complexity_score": 0.08800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Calculate the difference of the total amount spent in all events by the Student_Club in year 2019 and 2020.", "sql": "SELECT SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2019' THEN T2.spent ELSE 0 END) - SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2020' THEN T2.spent ELSE 0 END) AS num FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What was the notes of the fundraising on 2019/9/14?", "sql": "SELECT notes FROM income WHERE source = 'Fundraising' AND date_received = '2019-09-14'", "complexity_score": 0.027000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Tell the phone number of \"Carlo Jacobs\".", "sql": "SELECT phone FROM member WHERE first_name = 'Carlo' AND last_name = 'Jacobs'", "complexity_score": 0.027000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What is the status of the event which bought \"Post Cards, Posters\" on 2019/8/20?", "sql": "SELECT T1.event_status FROM budget AS T1 INNER JOIN expense AS T2 ON T1.budget_id = T2.link_to_budget WHERE T2.expense_description = 'Post Cards, Posters' AND T2.expense_date = '2019-08-20'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What was Brent Thomason's major?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.first_name = 'Brent' AND T1.last_name = 'Thomason'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "For all the club members from \"Business\" major, how many of them wear medium size t-shirt?", "sql": "SELECT COUNT(T1.member_id) FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T2.major_name = 'Business' AND T1.t_shirt_size = 'Medium'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Which department was the President of the club in?", "sql": "SELECT T2.department FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.position = 'President'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "State the date Connor Hilton paid his/her dues.", "sql": "SELECT T2.date_received FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Connor' AND T1.last_name = 'Hilton' AND T2.source = 'Dues'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "How many times was the budget in Advertisement for \"Yearly Kickoff\" meeting more than \"October Meeting\"?", "sql": "SELECT CAST(SUM(CASE WHEN T2.event_name = 'Yearly Kickoff' THEN T1.amount ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN T2.event_name = 'October Meeting' THEN T1.amount ELSE 0 END), 0) FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' AND T2.type = 'Meeting'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What is the total cost of the pizzas for all the events?", "sql": "SELECT SUM(cost) FROM expense WHERE expense_description = 'Pizza'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "How many cities are there in Orange County, Virginia?", "sql": "SELECT COUNT(city) FROM zip_code WHERE county = 'Orange County' AND state = 'Virginia'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What does the person with the phone number \"809-555-3360\" major in?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.phone = '809-555-3360'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "How many members attended the \"Women's Soccer\" event?", "sql": "SELECT COUNT(T2.link_to_member) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'Women''s Soccer'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List all the members of the \"School of Applied Sciences, Technology and Education\" department.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T2.department = 'School of Applied Sciences, Technology and Education'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Among all the closed events, which event has the highest spend-to-budget ratio?", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T2.status = 'Closed' ORDER BY T1.spent / NULLIF(T1.amount, 0) DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What is the highest amount of budget spend for an event?", "sql": "SELECT MAX(spent) FROM budget", "complexity_score": 0.016, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What is the total amount of money spent for food?", "sql": "SELECT SUM(spent) FROM budget WHERE category = 'Food'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List the name of students that have attended more than 7 events.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN attendance AS T2 ON T1.member_id = T2.link_to_member GROUP BY T1.member_id, T1.first_name, T1.last_name HAVING COUNT(T2.link_to_event) > 7", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Which student has been entrusted to manage the budget for the Yearly Kickoff?", "sql": "SELECT T4.first_name, T4.last_name FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget INNER JOIN member AS T4 ON T3.link_to_member = T4.member_id WHERE T1.event_name = 'Yearly Kickoff'", "complexity_score": 0.12200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Which event has the lowest cost?", "sql": "SELECT T1.event_name FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget ORDER BY T3.cost NULLS FIRST LIMIT 1", "complexity_score": 0.08, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Based on the total cost for all event, what is the percentage of cost for Yearly Kickoff event?", "sql": "SELECT CAST(SUM(CASE WHEN T1.event_name = 'Yearly Kickoff' THEN T3.cost ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(T3.cost), 0) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget", "complexity_score": 0.092, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Indicate the top source of funds received in September 2019 based on their amount.", "sql": "SELECT source FROM income WHERE date_received BETWEEN '2019-09-01' AND '2019-09-30' ORDER BY source DESC NULLS LAST LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "How many members of the Student_Club have major in 'Physics Teaching'?", "sql": "SELECT COUNT(T2.member_id) FROM major AS T1 INNER JOIN member AS T2 ON T1.major_id = T2.link_to_major WHERE T1.major_name = 'Physics Teaching'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Name the event with the highest amount spent on advertisement.", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' ORDER BY T1.spent DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Did Maya Mclean attend the 'Women's Soccer' event?", "sql": "SELECT CASE WHEN T3.event_name = 'Women''s Soccer' THEN 'YES' END AS result FROM member AS T1 INNER JOIN attendance AS T2 ON T1.member_id = T2.link_to_member INNER JOIN event AS T3 ON T2.link_to_event = T3.event_id WHERE T1.first_name = 'Maya' AND T1.last_name = 'Mclean'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Indicate the cost of posters for 'September Speaker' event.", "sql": "SELECT T3.cost FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'September Speaker' AND T3.expense_description = 'Posters'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Indicate the name of the closed event whose cost has exceeded the budget the most.", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T2.event_id = T1.link_to_event WHERE T1.event_status = 'Closed' AND T1.remaining < 0 ORDER BY T1.remaining NULLS FIRST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Identify the type of expenses and their total value approved for 'October Meeting' event.", "sql": "SELECT T1.type, SUM(T3.cost) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' GROUP BY T1.type", "complexity_score": 0.093, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Calculate the amount budgeted for 'April Speaker' event. List all the budgeted categories for said event in an ascending order based on their amount budgeted.", "sql": "SELECT T2.category, SUM(T2.amount) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'April Speaker' GROUP BY T2.category ORDER BY SUM(T2.amount) ASC", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Mention the total expense used on 8/20/2019.", "sql": "SELECT SUM(cost) FROM expense WHERE expense_date = '2019-08-20'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List out the full name and total cost that member id \"rec4BLdZHS2Blfp4v\" incurred?", "sql": "SELECT T1.first_name, T1.last_name, SUM(T2.cost) FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.member_id = 'rec4BLdZHS2Blfp4v' GROUP BY T1.first_name, T1.last_name", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "State what kind of expenses that Sacha Harrison incurred?", "sql": "SELECT T2.expense_description FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Sacha' AND T1.last_name = 'Harrison'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "State the category of events were held at MU 215.", "sql": "SELECT DISTINCT T2.category FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.location = 'MU 215'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List the last name of members with a major in environmental engineering and include its department and college name.", "sql": "SELECT T2.last_name, T1.department, T1.college FROM major AS T1 INNER JOIN member AS T2 ON T1.major_id = T2.link_to_major WHERE T2.position = 'Member' AND T1.major_name = 'Environmental Engineering'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "What are the budget category of the events located at MU 215 and a guest speaker type with a 0 budget spent?", "sql": "SELECT DISTINCT T2.category, T1.type FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.location = 'MU 215' AND T2.spent = 0 AND T1.type = 'Guest Speaker'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Among the members with t-shirt size of medium, what is the percentage of the amount 50 received by the Student_Club?", "sql": "SELECT CAST(SUM(CASE WHEN T2.amount = 50 THEN 1.0 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.income_id), 0) FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Member' AND T1.t_shirt_size = 'Medium'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "List the names of closed event as \"game\" that was closed from 3/15/2019 to 3/20/2020.", "sql": "SELECT DISTINCT event_name FROM event WHERE type = 'Game' AND DATE(SUBSTR(event_date, 1, 10)) BETWEEN '2019-03-15' AND '2020-03-20' AND status = 'Closed'", "complexity_score": 0.037000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Give the full name and contact number of members who had to spend more than average on each expense.", "sql": "SELECT DISTINCT T3.first_name, T3.last_name, T3.phone FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member WHERE T1.cost > (SELECT AVG(T1.cost) FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member)", "complexity_score": 0.219, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 4, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Write the full name of the member who spent money for water, veggie tray and supplies and include the cost of it.", "sql": "SELECT T2.first_name, T2.last_name, T1.cost FROM expense AS T1 INNER JOIN member AS T2 ON T1.link_to_member = T2.member_id WHERE T1.expense_description = 'Water, Veggie tray, supplies'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "student_club", "intent": "Write the full names of students who received funds on the date of 9/9/2019 and include the amount received.", "sql": "SELECT DISTINCT T3.first_name, T3.last_name, T4.amount FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event INNER JOIN member AS T3 ON T3.member_id = T2.link_to_member INNER JOIN income AS T4 ON T4.link_to_member = T3.member_id WHERE T4.date_received = '2019-09-09'", "complexity_score": 0.12200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Are there more in-patient or outpatient who were male? What is the deviation in percentage?", "sql": "SELECT CAST(SUM(CASE WHEN Admission = '+' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE SEX = 'M'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the percentage of female patient were born after 1930?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') > '1930' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM Patient WHERE SEX = 'F'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the ratio of outpatient to inpatient followed up treatment among all the 'SLE' diagnosed patient?", "sql": "SELECT SUM(CASE WHEN Admission = '+' THEN 1.0 ELSE 0 END) / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE Diagnosis = 'SLE'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the disease patient '30609' diagnosed with. List all the date of laboratory tests done for this patient.", "sql": "SELECT T1.Diagnosis, T2.Date FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID = 30609", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "List the patient ID, sex and birthday of patient with LDH beyond normal range.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.LDH > 500", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "State the ID and age of patient with positive degree of coagulation.", "sql": "SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.RVVT = '+'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For patients with severe degree of thrombosis, list their ID, sex and disease the patient is diagnosed with.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.Thrombosis = 2", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many female patients who came at the hospital in 1997 was immediately followed at the outpatient clinic?", "sql": "SELECT COUNT(*) FROM Patient WHERE TO_CHAR(CAST(Description AS TIMESTAMP), 'YYYY') = '1997' AND SEX = 'F' AND Admission = '-'", "complexity_score": 0.043000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many of the patients with the most serious thrombosis cases examined in 1997 are women?", "sql": "SELECT COUNT(*) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND TO_CHAR(CAST(T2.\"Examination Date\" AS TIMESTAMP), 'YYYY') = '1997' AND T2.Thrombosis = 1", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What are the symptoms observed by the youngest patient to ever did a medical examination? Identify their diagnosis.", "sql": "SELECT T2.Symptoms, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE NOT T2.Symptoms IS NULL ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "The oldest SJS patient's medical laboratory work was completed on what date, and what age was the patient when they initially arrived at the hospital?", "sql": "SELECT T1.Date, EXTRACT(YEAR FROM T2.\"First Date\") - EXTRACT(YEAR FROM T2.Birthday) AS Age, T2.Birthday FROM Laboratory AS T1 INNER JOIN Patient AS T2 ON T1.ID = T2.ID WHERE T2.Diagnosis = 'SJS' AND T2.Birthday IS NOT NULL ORDER BY T2.Birthday ASC LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the ratio of male to female patients among all those with abnormal uric acid counts?", "sql": "SELECT CAST(SUM(CASE WHEN T2.UA <= 8.0 AND T1.SEX = 'M' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN T2.UA <= 6.5 AND T1.SEX = 'F' THEN 1 ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID", "complexity_score": 0.077, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many underage patients were examined during the course of the three-year period from 1990 to 1993?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE EXTRACT(YEAR FROM T2.\"Examination Date\") BETWEEN 1990 AND 1993 AND EXTRACT(YEAR FROM T2.\"Examination Date\") - EXTRACT(YEAR FROM T1.Birthday) < 18", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How old was the patient who had the highest hemoglobin count at the time of the examination, and what is the doctor's diagnosis?", "sql": "SELECT EXTRACT(YEAR FROM T2.Date) - EXTRACT(YEAR FROM T1.Birthday) AS age_difference, T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.HGB IS NOT NULL ORDER BY T2.HGB DESC LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For the patient who was diagnosed with SLE on 1994/2/19, what was his/her anti-Cardiolipin antibody concentration status on 1993/11/12?", "sql": "SELECT \"aCL IgA\", \"aCL IgG\", \"aCL IgM\" FROM Examination WHERE ID IN (SELECT ID FROM Patient WHERE Diagnosis = 'SLE' AND Description = '1994-02-19') AND \"Examination Date\" = '1993-11-12'", "complexity_score": 0.13, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For the patient who was born on 1959/2/18, what is the decrease rate for his/her total cholesterol from November to December in 1981?", "sql": "SELECT CAST((SUM(CASE WHEN T2.date::text LIKE '1981-11-%' THEN T2.\"T-CHO\" ELSE 0 END) - SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2.\"T-CHO\" ELSE 0 END)) AS REAL) / NULLIF(SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2.\"T-CHO\" ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Birthday = '1959-02-18'", "complexity_score": 0.07, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many patients who were examined between 1987/7/6 and 1996/1/31 had a GPT level greater than 30 and an ALB level less than 4? List them by their ID.", "sql": "SELECT DISTINCT ID FROM Laboratory WHERE Date BETWEEN '1987-07-06' AND '1996-01-31' AND GPT > 30 AND ALB < 4", "complexity_score": 0.037000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What number of patients with a degree of thrombosis level 2 and ANA pattern of only S, have a level of anti-Cardiolip in antibody (IgM) 20% higher than average?", "sql": "SELECT COUNT(*) FROM Examination WHERE Thrombosis = 2 AND \"ANA Pattern\" = 'S' AND \"aCL IgM\" > (SELECT AVG(\"aCL IgM\") * 1.2 FROM Examination WHERE Thrombosis = 2 AND \"ANA Pattern\" = 'S')", "complexity_score": 0.14200000000000002, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "List all patients who were followed up at the outpatient clinic who underwent a laboratory test in October 1991 and had a total blood bilirubin level within the normal range.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Admission = '-' AND T2.\"T-BIL\" < 2.0 AND T2.Date::text LIKE '1991-10-%'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the average blood albumin level for female patients with a PLT greater than 400 who have been diagnosed with SLE?", "sql": "SELECT AVG(T2.ALB) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT > 400 AND T1.Diagnosis = 'SLE' AND T1.SEX = 'F'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many female patients were given an APS diagnosis?", "sql": "SELECT COUNT(ID) FROM Patient WHERE SEX = 'F' AND Diagnosis = 'APS'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What percentage of patients who were born in 1980 and were diagnosed with RA are women?", "sql": "SELECT CAST(SUM(CASE WHEN SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(ID), 0) FROM Patient WHERE Diagnosis = 'RA' AND TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') = '1980'", "complexity_score": 0.03900000000000001, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Was the patient with the number 57266's uric acid within a normal range?", "sql": "SELECT CASE WHEN (T1.SEX = 'F' AND T2.UA > 6.5) OR (T1.SEX = 'M' AND T2.UA > 8.0) THEN TRUE ELSE FALSE END FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID = 57266", "complexity_score": 0.082, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Provide IDs for male patients with ALT glutamic pylvic transaminase (GPT) that have history of ALT glutamic pylvic transaminase (GPT) exceed the normal range.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'M' AND T2.GPT >= 60", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Please provide the diagnosis of patients with ALT glutamic pylvic transaminase beyond the normal range by ascending order of their date of birth.", "sql": "SELECT DISTINCT ON (T1.Birthday) T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GPT > 60 ORDER BY T1.Birthday ASC", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["DISTINCT", "DISTINCT_ON", "FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Provide all ID, sex and birthday of patients whose urea nitrogen (UN) just within the borderline of passing?", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.UN = 29", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "List and group all patients by sex for total bilirubin (T-BIL) level not within the normal range.", "sql": "SELECT T1.ID, T1.SEX FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.\"T-BIL\" >= 2.0 GROUP BY T1.SEX,T1.ID", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What is the average age of the male patient with high cholesterol?", "sql": "SELECT AVG(EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM T1.Birthday)) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.\"T-CHO\" >= 250 AND T1.SEX = 'M'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For all patients with triglyceride (TG) level beyond the normal range, how many are age more than 50 years?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.TG >= 200 AND EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) > 50", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For patient born between 1936-1956, how many male patients have creatinine phosphokinase beyond the normal range?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE TO_CHAR(CAST(T1.Birthday AS TIMESTAMP), 'YYYY') BETWEEN '1936' AND '1956' AND T1.SEX = 'M' AND T2.CPK >= 250", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Provide ID, sex and age of patient who has blood glucose (GLU) not within normal range but with total cholesterol(T-CHO) within normal range.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GLU >= 180 AND T2.\"T-CHO\" < 250", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "What are the patient's diagnosis for those who has lower red blood blood cell? State their ID and age.", "sql": "SELECT DISTINCT T1.Diagnosis, T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.RBC < 3.5", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients who were diagnosed with SLE, who is the oldest with normal hemoglobin level. Provide the ID and sex.", "sql": "SELECT T1.ID, T1.SEX FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Diagnosis = 'SLE' AND T2.HGB > 10 AND T2.HGB < 17 ORDER BY T1.Birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Name the ID and age of patient with two or more laboratory examinations which show their hematoclit level exceeded the normal range.", "sql": "SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID IN (SELECT ID FROM Laboratory WHERE HCT >= 52 GROUP BY ID HAVING COUNT(ID) >= 2)", "complexity_score": 0.14800000000000002, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For patients with abnormal platelet level, state the number of patients with lower than normal range. How is it compare to the number of patients with higher than normal range?", "sql": "SELECT SUM(CASE WHEN T2.PLT <= 100 THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.PLT >= 400 THEN 1 ELSE 0 END) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For laboratory examinations take in 1984, list all patients below 50 years old with normal platelet level.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT BETWEEN 100 AND 400 AND EXTRACT(YEAR FROM T2.Date) - EXTRACT(YEAR FROM T1.Birthday) < 50 AND EXTRACT(YEAR FROM T2.Date) = 1984", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For all patients who are older than 55 years old, what is the percentage of female who has abnormal prothrombin time (PT)?", "sql": "SELECT CAST(SUM(CASE WHEN T2.PT >= 14 AND T1.SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(CASE WHEN T2.PT >= 14 THEN 1 ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) > 55", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the male patients who have a normal level of white blood cells, how many of them have an abnormal fibrinogen level?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.FG <= 150 OR T2.FG >= 450 AND T2.WBC > 3.5 AND T2.WBC < 9.0 AND T1.SEX = 'M'", "complexity_score": 0.09800000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many patients with an Ig G higher than normal?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE T2.IGG >= 2000", "complexity_score": 0.093, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients with a normal Ig G level, how many of them have symptoms?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE T2.IGG BETWEEN 900 AND 2000 AND NOT T3.Symptoms IS NULL", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many patients with a normal Ig A level came to the hospital after 1990/1/1?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.IGA BETWEEN 80 AND 500 AND TO_CHAR(CAST(T1.\"First Date\" AS TIMESTAMP), 'YYYY') > '1990'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For the patients with an abnormal Ig M level, what is the most common disease they are diagnosed with?", "sql": "SELECT T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE NOT T2.IGM BETWEEN 40 AND 400 GROUP BY T1.Diagnosis ORDER BY COUNT(T1.Diagnosis) DESC NULLS LAST LIMIT 1", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many patients with a abnormal C-reactive protein don't have their data recorded?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE (T2.CRP = '+') AND T1.Description IS NULL", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients whose creatinine level is abnormal, how many of them aren't 70 yet?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CRE >= 1.5 AND EXTRACT(YEAR FROM AGE(CURRENT_DATE, T1.Birthday)) < 70", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "How many patients have a normal level of anti-ribonuclear protein and have been admitted to the hospital?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.RNP = 'negative' OR T2.RNP = '0' AND T1.Admission = '+'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients with normal anti-SM, how many of them does not have thrombosis?", "sql": "SELECT COUNT(T1.ID) FROM Examination AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.SM IN ('negative', '0') AND T1.Thrombosis = 0", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients who has a normal anti-scl70, how many of them are female and does not have any symptom?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE (T2.SC170 = 'negative' OR T2.SC170 = '0') AND T1.SEX = 'F' AND T3.Symptoms IS NULL", "complexity_score": 0.123, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients who has a normal level of anti-centromere and a normal level of anti-SSB, how many of them are male?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CENTROMEA IN ('negative', '0') AND T2.SSB IN ('negative', '0') AND T1.SEX = 'M'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "Among the patients who have an abnormal level of glutamic oxaloacetic transaminase, when was the youngest of them born?", "sql": "SELECT T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GOT >= 60 ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "thrombosis_prediction", "intent": "For the patients with a normal range of creatinine phosphokinase, how many of them have a positive measure of degree of coagulation?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T1.ID = T3.ID WHERE T2.CPK < 250 AND (T3.KCT = '+' OR T3.RVVT = '+' OR T3.LAC = '+')", "complexity_score": 0.123, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Give the name of the league had the most goals in the 2016 season?", "sql": "SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' GROUP BY t2.name ORDER BY SUM(t1.home_team_goal + t1.away_team_goal) DESC NULLS LAST LIMIT 1", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "In Scotland Premier League, which away team won the most during the 2010 season?", "sql": "SELECT teamInfo.team_long_name FROM League AS leagueData INNER JOIN Match AS matchData ON leagueData.id = matchData.league_id INNER JOIN Team AS teamInfo ON matchData.away_team_api_id = teamInfo.team_api_id WHERE leagueData.name = 'Scotland Premier League' AND matchData.season = '2009/2010' AND matchData.away_team_goal - matchData.home_team_goal > 0 GROUP BY teamInfo.team_long_name, matchData.away_team_api_id ORDER BY COUNT(*) DESC LIMIT 1", "complexity_score": 0.113, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What are the speed in which attacks are put together of the top 4 teams with the highest build Up Play Speed?", "sql": "SELECT t1.buildUpPlaySpeed FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id ORDER BY t1.buildUpPlaySpeed ASC NULLS FIRST LIMIT 4", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Give the name of the league had the most matches end as draw in the 2016 season?", "sql": "SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' AND t1.home_team_goal = t1.away_team_goal GROUP BY t2.name ORDER BY COUNT(t1.id) DESC NULLS LAST LIMIT 1", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "At present, calculate for the player's age who have a sprint speed of no less than 97 between 2013 to 2015.", "sql": "SELECT DISTINCT EXTRACT(YEAR FROM AGE(NOW(), t2.birthday::timestamp)) + (CASE WHEN EXTRACT(MONTH FROM AGE(NOW(), t2.birthday::timestamp)) > 0 OR EXTRACT(DAY FROM AGE(NOW(), t2.birthday::timestamp)) > 0 THEN 1 ELSE 0 END) AS age FROM Player_Attributes AS t1 INNER JOIN Player AS t2 ON t1.player_api_id = t2.player_api_id WHERE EXTRACT(YEAR FROM t1.date::date) BETWEEN 2013 AND 2015 AND t1.sprint_speed >= 97", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Give the name of the league with the highest matches of all time and how many matches were played in the said league.", "sql": "SELECT t2.name, t1.max_count FROM League AS t2 JOIN (SELECT league_id, MAX(cnt) AS max_count FROM (SELECT league_id, COUNT(id) AS cnt FROM Match GROUP BY league_id) AS subquery GROUP BY league_id ORDER BY MAX(cnt) DESC LIMIT 1) AS t1 ON t1.league_id = t2.id", "complexity_score": 0.215, "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "LIMIT", "ORDER", "SELECT", "SUBQUERY"], "num_joins": 1, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Give the team_fifa_api_id of teams with more than 50 but less than 60 build-up play speed.", "sql": "SELECT DISTINCT team_fifa_api_id FROM Team_Attributes WHERE buildUpPlaySpeed > 50 AND buildUpPlaySpeed < 60", "complexity_score": 0.027000000000000003, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "List the long name of teams with above-average build-up play passing in 2012.", "sql": "SELECT DISTINCT t4.team_long_name FROM Team_Attributes AS t3 INNER JOIN Team AS t4 ON t3.team_api_id = t4.team_api_id WHERE SUBSTR(t3.\"date\", 1, 4) = '2012' AND t3.buildUpPlayPassing > (SELECT CAST(SUM(t2.buildUpPlayPassing) AS REAL) / NULLIF(COUNT(t1.id), 0) FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') = '2012')", "complexity_score": 0.18200000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Calculate the percentage of players who prefer left foot, who were born between 1987 and 1992.", "sql": "SELECT CAST(COUNT(CASE WHEN t2.preferred_foot = 'left' THEN t1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(t1.id), 0) AS percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t1.birthday, 1, 4) BETWEEN '1987' AND '1992'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Find the average number of long-shot done by Ahmed Samir Farag.", "sql": "SELECT CAST(SUM(t2.long_shots) AS REAL) / NULLIF(COUNT(t2.\"date\"), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Ahmed Samir Farag'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "List the top 10 players' names whose heights are above 180 in descending order of average heading accuracy.", "sql": "SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 180 GROUP BY t1.id ORDER BY CAST(SUM(t2.heading_accuracy) AS REAL) / NULLIF(COUNT(t2.\"player_fifa_api_id\"), 0) DESC NULLS LAST LIMIT 10", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "List the name of leagues in which the average goals by the home team is higher than the away team in the 2009/2010 season.", "sql": "SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2009/2010' GROUP BY t1.name HAVING (CAST(SUM(t2.home_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) - (CAST(SUM(t2.away_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) > 0", "complexity_score": 0.083, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "List the football players with a birthyear of 1970 and a birthmonth of October.", "sql": "SELECT player_name FROM Player WHERE SUBSTR(birthday, 1, 7) = '1970-10'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What is the overall rating of the football player Gabriel Tamas in year 2011?", "sql": "SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Gabriel Tamas' AND TO_CHAR(CAST(t2.date AS TIMESTAMP), 'YYYY') = '2011'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Calculate the average home team goal in the 2010/2011 season in the country of Poland.", "sql": "SELECT CAST(SUM(t2.home_team_goal) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Country AS t1 INNER JOIN Match AS t2 ON t1.id = t2.country_id WHERE t1.name = 'Poland' AND t2.season = '2010/2011'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Who has the highest average finishing rate between the highest and shortest football player?", "sql": "SELECT A FROM (SELECT AVG(finishing) AS result, 'Max' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MAX(height) FROM Player) UNION SELECT AVG(finishing) AS result, 'Min' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MIN(height) FROM Player)) AS subquery ORDER BY result DESC LIMIT 1", "complexity_score": 0.29200000000000004, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "UNION", "WHERE"], "num_joins": 2, "num_subqueries": 3, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "From 2010 to 2015, what was the average overall rating of players who are higher than 170?", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 170 AND TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') >= '2010' AND TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') <= '2015'", "complexity_score": 0.084, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What is the difference of the average ball control score between Abdou Diallo and Aaron Appindangoye\n?", "sql": "SELECT CAST(SUM(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.ball_control ELSE 0 END) AS REAL) / NULLIF(COUNT(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.id ELSE NULL END), 0) - CAST(SUM(CASE WHEN t1.player_name = 'Aaron Appindangoye' THEN t2.ball_control ELSE 0 END) AS REAL) / NULLIF(COUNT(CASE WHEN t1.player_name = 'Aaron Appindangoye' THEN t2.id ELSE NULL END), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.069, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Which player is older, Aaron Lennon or Abdelaziz Barrada?", "sql": "SELECT player_name FROM Player WHERE player_name IN ('Aaron Lennon', 'Abdelaziz Barrada') ORDER BY birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Which player is the tallest?", "sql": "SELECT player_name FROM Player ORDER BY height DESC NULLS LAST LIMIT 1", "complexity_score": 0.010000000000000002, "pattern_signature": "SELECT-FROM-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Among the players whose preferred foot was the left foot when attacking, how many of them would remain in his position when the team attacked?", "sql": "SELECT COUNT(player_api_id) FROM Player_Attributes WHERE preferred_foot = 'left' AND attacking_work_rate = 'low'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Among the players born before the year 1986, how many of them would remain in his position and defense while the team attacked?", "sql": "SELECT COUNT(DISTINCT t1.player_name) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE TO_CHAR(CAST(t1.birthday AS TIMESTAMP), 'YYYY') < '1986' AND t2.defensive_work_rate = 'high'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Please list the names of the players whose volley score and dribbling score are over 70.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.volleys > 70 AND t2.dribbling > 70", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "How many matches were held in the Belgium Jupiler League in April, 2009?", "sql": "SELECT COUNT(t2.id) FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t1.name = 'Belgium Jupiler League' AND SUBSTR(t2.\"date\", 1, 7) = '2009-04'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Give the name of the league had the most matches in the 2008/2009 season?", "sql": "SELECT t1.name FROM League AS t1 JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2008/2009' GROUP BY t1.name HAVING COUNT(t2.id) = (SELECT MAX(match_count) FROM (SELECT COUNT(t2.id) AS match_count FROM Match AS t2 WHERE t2.season = '2008/2009' GROUP BY t2.league_id) AS subquery)", "complexity_score": 0.23600000000000002, "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "How much higher in percentage is Ariel Borysiuk's overall rating than that of Paulin Puel?", "sql": "SELECT (SUM(CASE WHEN t1.player_name = 'Ariel Borysiuk' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.063, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Calculate the average overall rating of Pietro Marino.", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Pietro Marino'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What is Ajax's highest chance creation passing score and what is it classified as?", "sql": "SELECT t2.chanceCreationPassing, t2.chanceCreationPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Ajax' ORDER BY t2.chanceCreationPassing DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "For the players who had a 77 points overall rating on 2016/6/23, who was the oldest? Give the name of the player.", "sql": "SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2016-06-23' AND t2.overall_rating = 77 ORDER BY t1.birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What was the overall rating for Aaron Mooy on 2016/2/4?", "sql": "SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2016-02-04' AND t1.player_name = 'Aaron Mooy'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "How was Francesco Migliore's attacking work rate on 2015/5/1?", "sql": "SELECT t2.attacking_work_rate FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.\"date\" LIKE '2015-05-01%' AND t1.player_name = 'Francesco Migliore'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "When was the first time did Kevin Constant have his highest crossing score? Give the date.", "sql": "SELECT \"date\" FROM (SELECT t2.crossing, t2.\"date\" FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE t1.player_name = 'Kevin Constant' ORDER BY t2.crossing DESC) AS subquery ORDER BY \"date\" DESC LIMIT 1", "complexity_score": 0.128, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Tell the build Up play passing class for \"FC Lorient\" on 2010/2/22.", "sql": "SELECT t2.buildUpPlayPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'FC Lorient' AND t2.\"date\" LIKE '2010-02-22%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "For the team \"Hannover 96\", what was its defence aggression class on 2015/9/10?", "sql": "SELECT t2.defenceAggressionClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Hannover 96' AND t2.\"date\" LIKE '2015-09-10%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What was the average overall rating for Marko Arnautovic from 2007/2/22 to 2016/4/21?", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE t1.player_name = 'Marko Arnautovic' AND SUBSTR(t2.\"date\", 1, 10) BETWEEN '2007-02-22' AND '2016-04-21'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What percentage is Landon Donovan's overall rating higher than Jordan Bowery on 2013/7/12?", "sql": "SELECT (SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Jordan Bowery' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END), 0) AS LvsJ_percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2013-07-12'", "complexity_score": 0.07, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "List down most tallest players' name.", "sql": "SELECT player_name FROM (SELECT player_name, height, DENSE_RANK() OVER (ORDER BY height DESC) AS rank FROM Player) AS subquery WHERE rank = 1", "complexity_score": 0.09900000000000003, "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", "clauses_present": ["FROM", "ORDER", "SELECT", "SUBQUERY", "WHERE", "WINDOW"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "State the name of the most strongest player.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.overall_rating = (SELECT MAX(overall_rating) FROM Player_Attributes)", "complexity_score": 0.134, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Who are the players that tend to be attacking when their mates were doing attack moves? List down their name.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.attacking_work_rate = 'high'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What are the short name of team who played safe while creating chance of passing?", "sql": "SELECT DISTINCT t1.team_short_name FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.chanceCreationPassingClass = 'Safe'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "How many football players born after the 1990s have the first name \"Aaron\"?", "sql": "SELECT COUNT(id) FROM Player WHERE birthday > '1990' AND player_name LIKE 'Aaron%'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What is the difference between players 6 and 23's jumping scores?", "sql": "SELECT SUM(CASE WHEN t1.id = 6 THEN t1.jumping ELSE 0 END) - SUM(CASE WHEN t1.id = 23 THEN t1.jumping ELSE 0 END) FROM Player_Attributes AS t1", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Please provide top four football players' IDs who are among the lowest potential players and prefer to use the right foot when attacking.", "sql": "SELECT id FROM Player_Attributes WHERE preferred_foot = 'right' ORDER BY potential ASC NULLS LAST LIMIT 4", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "How many players had the highest potential score for crossing that preferred to use their left foots while attacking?", "sql": "SELECT COUNT(t1.id) FROM Player_Attributes AS t1 WHERE t1.preferred_foot = 'left' AND t1.crossing = (SELECT MAX(crossing) FROM Player_Attributes)", "complexity_score": 0.11500000000000003, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What was the final score for the match on September 24, 2008, in the Belgian Jupiler League between the home team and the away team?", "sql": "SELECT t2.home_team_goal, t2.away_team_goal FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t1.name = 'Belgium Jupiler League' AND t2.\"date\" LIKE '2008-09-24%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Does the KSV Cercle Brugge team have a slow, balanced or fast speed class?", "sql": "SELECT DISTINCT t1.buildUpPlaySpeedClass FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.team_long_name = 'KSV Cercle Brugge'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Please state the finishing rate and curve score of the player who has the heaviest weight.", "sql": "SELECT id, finishing, curve FROM Player_Attributes WHERE player_api_id = (SELECT player_api_id FROM Player ORDER BY weight DESC NULLS LAST LIMIT 1) LIMIT 1", "complexity_score": 0.10300000000000002, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Which top 4 leagues had the most games in the 2015-2016 season?", "sql": "SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2015/2016' GROUP BY t1.name ORDER BY COUNT(t2.id) DESC NULLS LAST LIMIT 4", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Please provide the full name of the away team that scored the most goals.", "sql": "SELECT t2.team_long_name FROM Match AS t1 INNER JOIN Team AS t2 ON t1.away_team_api_id = t2.team_api_id ORDER BY t1.away_team_goal DESC NULLS LAST LIMIT 1", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "Please name one player whose overall strength is the greatest.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.overall_rating = (SELECT MAX(overall_rating) FROM Player_Attributes)", "complexity_score": 0.134, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "european_football_2", "intent": "What is the percentage of players that are under 180 cm who have an overall strength of more than 70?", "sql": "SELECT CAST(COUNT(CASE WHEN t2.overall_rating > 70 AND t1.height < 180 THEN t1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(t1.id), 0) AS percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.067, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please list the reference names of the drivers who are eliminated in the first period in race number 20.", "sql": "SELECT T2.driverRef FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 20 ORDER BY T1.q1 DESC NULLS LAST LIMIT 5", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the surname of the driver with the best lap time in race number 19 in the second qualifying period?", "sql": "SELECT T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 19 ORDER BY T1.q2 ASC NULLS FIRST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please give the name of the race held on the circuits in Germany.", "sql": "SELECT DISTINCT T2.name FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T1.country = 'Germany'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the coordinates location of the circuits for Australian grand prix?", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Australian Grand Prix'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Give the coordinate position for Abu Dhabi Grand Prix.", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Abu Dhabi Grand Prix'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What's Bruno Senna's Q1 result in the qualifying race No. 354?", "sql": "SELECT T1.q1 FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 354 AND T2.forename = 'Bruno' AND T2.surname = 'Senna'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is his number of the driver who finished 0:01:54 in the Q3 of qualifying race No.903?", "sql": "SELECT T2.number FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 903 AND T1.q3 LIKE '1:54%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For the Bahrain Grand Prix in 2007, how many drivers not finished the game?", "sql": "SELECT COUNT(T3.driverId) FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T1.year = 2007 AND T1.name = 'Bahrain Grand Prix' AND T2.time IS NULL", "complexity_score": 0.113, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For all the drivers who finished the game in race No. 592, who is the oldest?", "sql": "SELECT T1.forename, T1.surname FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T2.raceId = 592 AND NOT T2.time IS NULL AND NOT T1.dob IS NULL ORDER BY T1.dob ASC NULLS FIRST LIMIT 1", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Who was the player that got the lap time of 0:01:27 in the race No. 161? Show his introduction website.", "sql": "SELECT DISTINCT T2.forename, T2.surname, T2.url FROM lapTimes AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 161 AND T1.time LIKE '1:27%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Where is Malaysian Grand Prix held? Give the location coordinates.", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Malaysian Grand Prix'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For the constructor which got the highest point in the race No. 9 , what is its introduction website?", "sql": "SELECT T2.url FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T2.constructorId = T1.constructorId WHERE T1.raceId = 9 ORDER BY T1.points DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "In the race No. 45, for the driver who had the Q3 time as 0:01:33, what is his abbreviated code?", "sql": "SELECT T2.code FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 45 AND T1.q3 LIKE '1:33%'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Show me the season page of year when the race No. 901 took place.", "sql": "SELECT T2.url FROM races AS T1 INNER JOIN seasons AS T2 ON T2.year = T1.year WHERE T1.raceId = 901", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For all the drivers who finished the game in race No. 872, who is the youngest?", "sql": "SELECT T1.forename, T1.surname FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T2.raceId = 872 AND NOT T2.time IS NULL ORDER BY T1.dob DESC NULLS LAST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For the driver who set the fastest lap speed, what is his nationality?", "sql": "SELECT T1.nationality FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId ORDER BY CAST(T2.fastestLapSpeed AS DOUBLE PRECISION) DESC NULLS LAST LIMIT 1", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Paul di Resta was in the No. 853 race, what percent faster did he finish in the 853rd race than the next race for the fastest lap speed?", "sql": "SELECT (SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END) - SUM(CASE WHEN T2.raceId = 854 THEN T2.fastestLapSpeed::numeric ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END), 0) FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T1.forename = 'Paul' AND T1.surname = 'di Resta'", "complexity_score": 0.08, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "For the drivers who took part in the race in 1983/7/16, what's their race completion rate?", "sql": "SELECT CAST(COUNT(CASE WHEN NOT T2.time IS NULL THEN T2.driverId END) AS REAL) * 100 / NULLIF(COUNT(T2.driverId), 0) FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId WHERE T1.date = '1983-07-16'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "List the names of all races that occurred in the earliest recorded year and month.", "sql": "SELECT name FROM races WHERE TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') = (SELECT TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') FROM races ORDER BY date ASC NULLS FIRST LIMIT 1) AND TO_CHAR(CAST(date AS TIMESTAMP), 'MM') = (SELECT TO_CHAR(CAST(date AS TIMESTAMP), 'MM') FROM races ORDER BY date ASC NULLS FIRST LIMIT 1)", "complexity_score": 0.13500000000000004, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "State the driver with the most points scored. Find his full name with that points.", "sql": "SELECT T3.forename, T3.surname, T2.points FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId ORDER BY T2.points DESC NULLS LAST LIMIT 1", "complexity_score": 0.08, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the best lap time recorded? List the driver and race with such recorded lap time.", "sql": "SELECT T2.milliseconds, T1.forename, T1.surname, T3.name FROM drivers AS T1 INNER JOIN lapTimes AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T2.raceId = T3.raceId ORDER BY T2.milliseconds ASC NULLS FIRST LIMIT 1", "complexity_score": 0.08, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the average lap time for Lewis Hamilton in the 2009 Malaysian Grand Prix?", "sql": "SELECT AVG(T2.milliseconds) FROM races AS T1 INNER JOIN lapTimes AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' AND T1.year = 2009 AND T1.name = 'Malaysian Grand Prix'", "complexity_score": 0.123, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Calculate the percentage whereby Hamilton was not at the 1st track of the the f1 circuit since 2010.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.position <> 1 THEN T2.position END) AS REAL) * 100 / NULLIF(COUNT(T2.driverStandingsId), 0) FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.surname = 'Hamilton' AND T1.year >= 2010", "complexity_score": 0.109, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Name the driver with the most winning. Mention his nationality and what is his maximum point scores.", "sql": "SELECT T1.forename, T1.surname, T1.nationality, MAX(T2.points) FROM drivers AS T1 INNER JOIN driverStandings AS T2 ON T2.driverId = T1.driverId WHERE T2.wins >= 1 GROUP BY T1.forename, T1.surname, T1.nationality ORDER BY COUNT(T2.wins) DESC NULLS LAST LIMIT 1", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How old is the youngest Japanese driver? What is his name?", "sql": "SELECT EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM dob) AS age, forename, surname FROM drivers WHERE nationality = 'Japanese' ORDER BY dob DESC LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Name the races along with its circuit name and location for f1 races hosted in September 2005.", "sql": "SELECT DISTINCT T2.name, T1.name, T1.location FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.year = 2005 AND TO_CHAR(CAST(T2.date AS TIMESTAMP), 'MM') = '09'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which race was Alex Yoong in when he was in track number less than 20?", "sql": "SELECT T1.name FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Alex' AND T3.surname = 'Yoong' AND T2.position < 20", "complexity_score": 0.107, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "State the race and year of race in which Michael Schumacher had his fastest lap.", "sql": "SELECT T1.name, T1.year FROM races AS T1 INNER JOIN lapTimes AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Michael' AND T3.surname = 'Schumacher' ORDER BY T2.milliseconds ASC NULLS FIRST LIMIT 1", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which was Lewis Hamilton first race? What was his points recorded for his first race event?", "sql": "SELECT T1.name, T2.points FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' ORDER BY T1.year ASC NULLS FIRST LIMIT 1", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Among all European Grand Prix races, what is the percentage of the races were hosted in Germany?", "sql": "SELECT CAST(COUNT(CASE WHEN T1.country = 'Germany' THEN T2.circuitID END) AS REAL) * 100 / NULLIF(COUNT(T2.circuitId), 0) FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'European Grand Prix'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What's the location coordinates of Silverstone Circuit?", "sql": "SELECT lat, lng FROM circuits WHERE name = 'Silverstone Circuit'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What's the reference name of Marina Bay Street Circuit?", "sql": "SELECT circuitRef FROM circuits WHERE name = 'Marina Bay Street Circuit'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which country is the oldest driver from?", "sql": "SELECT nationality FROM drivers WHERE NOT dob IS NULL ORDER BY dob ASC NULLS FIRST LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which driver ranked the first in the Canadian Grand Prix in 2007? Please give his reference name.", "sql": "SELECT T3.forename, T3.surname, T3.driverRef FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T1.name = 'Canadian Grand Prix' AND T2.rank = 1 AND T1.year = 2007", "complexity_score": 0.107, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "In which Formula_1 race did Lewis Hamilton rank the highest?", "sql": "SELECT name FROM races WHERE raceId IN (SELECT raceId FROM results WHERE rank = 1 AND driverId = (SELECT driverId FROM drivers WHERE forename = 'Lewis' AND surname = 'Hamilton'))", "complexity_score": 0.22300000000000003, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What was the fastest lap speed among all drivers in the 2009 Spanish Grand Prix?", "sql": "SELECT T2.fastestLapSpeed FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId WHERE T1.name = 'Spanish Grand Prix' AND T1.year = 2009 AND NOT T2.fastestLapSpeed IS NULL ORDER BY T2.fastestLapSpeed DESC NULLS LAST LIMIT 1", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What was Lewis Hamilton's final rank in the 2008 Chinese Grand Prix?", "sql": "SELECT T2.positionOrder FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' AND T1.name = 'Chinese Grand Prix' AND T1.year = 2008", "complexity_score": 0.11699999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What's the finish time for the driver who ranked second in 2008's Chinese Grand Prix?", "sql": "SELECT T1.time FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T1.rank = 2 AND T2.name = 'Chinese Grand Prix' AND T2.year = 2008", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Among the drivers that finished the race in the 2008 Chinese Grand Prix, how many of them have participated in Formula_1 races?", "sql": "SELECT COUNT(*) FROM (SELECT T1.driverId FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Chinese Grand Prix' AND T2.year = 2008 AND T1.time IS NOT NULL GROUP BY T1.driverId HAVING COUNT(T2.raceId) > 0) AS subquery", "complexity_score": 0.16700000000000004, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How much faster in percentage is the champion than the driver who finished the race last in the 2008 Australian Grand Prix?", "sql": "WITH time_in_seconds AS (SELECT T1.positionOrder, CASE WHEN T1.positionOrder = 1 THEN (CAST(SUBSTR(T1.time, 1, 1) AS REAL) * 3600) + (CAST(SUBSTR(T1.time, 3, 2) AS REAL) * 60) + CAST(SUBSTR(T1.time, 6) AS REAL) ELSE CAST(SUBSTR(T1.time, 2) AS REAL) END AS time_seconds FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Australian Grand Prix' AND NOT T1.time IS NULL AND T2.year = 2008), champion_time AS (SELECT time_seconds FROM time_in_seconds WHERE positionOrder = 1), last_driver_incremental AS (SELECT time_seconds FROM time_in_seconds WHERE positionOrder = (SELECT MAX(positionOrder) FROM time_in_seconds)) SELECT (CAST((SELECT time_seconds FROM last_driver_incremental) AS REAL) * 100) / NULLIF((SELECT time_seconds + (SELECT time_seconds FROM last_driver_incremental) FROM champion_time), 0)", "complexity_score": 0.338, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["CTE", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 4, "num_ctes": 3, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How many circuits are there in Adelaide, Australia?", "sql": "SELECT COUNT(circuitId) FROM circuits WHERE location = 'Adelaide' AND country = 'Australia'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What are the maximum points of British constructors?", "sql": "SELECT MAX(T1.points) FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T2.nationality = 'British'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please list the constructor names with 0 points at race 291.", "sql": "SELECT T2.name FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T1.raceId = 291", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How many Japanese constructors have 0 points in 2 races?", "sql": "SELECT COUNT(T1.raceId) FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T2.nationality = 'Japanese' GROUP BY T1.constructorId HAVING COUNT(raceId) = 2", "complexity_score": 0.081, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please calculate the race completion percentage of Japanese drivers from 2007 to 2009.", "sql": "SELECT CAST(SUM(CASE WHEN NOT T1.time IS NULL THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.raceId), 0) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN drivers AS T3 ON T1.driverId = T3.driverId WHERE T3.nationality = 'Japanese' AND T2.year BETWEEN 2007 AND 2009", "complexity_score": 0.109, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the average time in seconds of champion for each year, before year 1975?", "sql": "WITH time_in_seconds AS (SELECT T2.year, T2.raceId, T1.positionOrder, CASE WHEN T1.positionOrder = 1 THEN (CASE WHEN SPLIT_PART(T1.time, ':', 1) <> '' AND SPLIT_PART(T1.time, ':', 2) <> '' AND SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 1) <> '' THEN (CAST(SPLIT_PART(T1.time, ':', 1) AS REAL) * 3600) + (CAST(SPLIT_PART(T1.time, ':', 2) AS REAL) * 60) + CAST(SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 1) AS REAL) + CAST(SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 2) AS REAL)/1000 ELSE 0 END) ELSE (CASE WHEN SUBSTRING(T1.time FROM 2) <> '' THEN CAST(SUBSTRING(T1.time FROM 2) AS REAL) ELSE 0 END) END AS time_seconds FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T1.time IS NOT NULL AND T1.time != ''), champion_time AS (SELECT year, raceId, time_seconds FROM time_in_seconds WHERE positionOrder = 1) SELECT year, AVG(time_seconds) FROM champion_time WHERE year < 1975 GROUP BY year HAVING AVG(time_seconds) IS NOT NULL", "complexity_score": 0.17900000000000002, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["CTE", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 2, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the fastest lap number of the champion in 2009?", "sql": "SELECT T1.fastestLap FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.year = 2009 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the average of fastest lap speed in the 2009 Spanish Grand Prix race?", "sql": "SELECT AVG(CAST(T1.fastestLapSpeed AS NUMERIC)) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.year = 2009 AND T2.name = 'Spanish Grand Prix'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "From 2000 to 2005, what percentage of drivers who were born before 1985 and the lap numbers were over 50?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(T3.dob AS TIMESTAMP), 'YYYY') < '1985' AND T1.laps > 50 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN drivers AS T3 ON T1.driverId = T3.driverId WHERE T2.year BETWEEN 2000 AND 2005", "complexity_score": 0.109, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How many French drivers who obtain the laptime less than 02:00.00?", "sql": "SELECT COUNT(T1.driverId) FROM drivers AS T1 INNER JOIN lapTimes AS T2 ON T1.driverId = T2.driverId WHERE T1.nationality = 'French' AND (EXTRACT(MINUTE FROM T2.time::INTERVAL) * 60 + EXTRACT(SECOND FROM T2.time::INTERVAL)) < 120", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "List out the code for drivers who have nationality in America.", "sql": "SELECT code FROM drivers WHERE Nationality = 'American'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "State code numbers of top 3 yougest drivers. How many Netherlandic drivers among them?", "sql": "SELECT COUNT(*) FROM (SELECT nationality FROM drivers ORDER BY dob DESC LIMIT 3) AS T3 WHERE nationality = 'Dutch'", "complexity_score": 0.09900000000000003, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please state the reference name of the oldest German driver.", "sql": "SELECT driverRef FROM drivers WHERE nationality = 'German' ORDER BY dob ASC LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which drivers who were born in 1971 and has the fastest lap time on the race? Give id and code of these drivers.", "sql": "SELECT T2.driverId, T2.code FROM results AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId WHERE TO_CHAR(CAST(T2.dob AS TIMESTAMP), 'YYYY') = '1971' AND NOT T1.fastestLapTime IS NULL", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "From race no. 50 to 100, how many finishers have been disqualified?", "sql": "SELECT SUM(CASE WHEN NOT time IS NULL THEN 1 ELSE 0 END) FROM results WHERE statusId = 2 AND raceID < 100 AND raceId > 50", "complexity_score": 0.043000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How many times the circuits were held in Austria? Please give their location and coordinates.", "sql": "SELECT DISTINCT location, lat, lng FROM circuits WHERE country = 'Austria'", "complexity_score": 0.017, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "On what year did the youngest driver had his first qualifying race? Also state the name, date and time of the race.", "sql": "SELECT T3.year, T3.name, T3.date, T3.time FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T1.raceId = T3.raceId WHERE T1.driverId = (SELECT driverId FROM drivers ORDER BY dob DESC NULLS LAST LIMIT 1) ORDER BY T3.date ASC NULLS FIRST LIMIT 1", "complexity_score": 0.163, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "List down top 3 German drivers who has the shortest average pit stop duration and were born between 1980-1985.", "sql": "SELECT T2.forename, T2.surname FROM pitStops AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId WHERE T2.nationality = 'German' AND EXTRACT(YEAR FROM T2.dob) BETWEEN 1980 AND 1985 GROUP BY T2.forename, T2.surname ORDER BY AVG(CAST(T1.duration AS INTERVAL)) LIMIT 3", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Who is the champion of the Canadian Grand Prix in 2008? Indicate his finish time.", "sql": "SELECT T1.time FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Canadian Grand Prix' AND T2.year = 2008 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is the constructor reference name of the champion in the 2009 Singapore Grand Prix? Please give its website.", "sql": "SELECT T3.constructorRef, T3.url FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN constructors AS T3 ON T1.constructorId = T3.constructorId WHERE T2.name = 'Singapore Grand Prix' AND T2.year = 2009 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.107, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Please list all the superpowers of 3-D Man.", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T1.superhero_name = '3-D Man'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which constructor scored most points from Monaco Grand Prix between 1980 and 2010? List the score, name and nationality of this team.", "sql": "SELECT SUM(T1.points), T2.name, T2.nationality FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId INNER JOIN races AS T3 ON T3.raceid = T1.raceid WHERE T3.name = 'Monaco Grand Prix' AND T3.year BETWEEN 1980 AND 2010 GROUP BY T2.name, T2.nationality ORDER BY SUM(T1.points) DESC LIMIT 1", "complexity_score": 0.109, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "What is full name of the racer who ranked 1st in the 3rd qualifying race held in the Marina Bay Street Circuit in 2008?", "sql": "SELECT T2.forename, T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T1.raceid = T3.raceid WHERE q3 IS NOT NULL AND T3.year = 2008 AND T3.circuitId IN (SELECT circuitId FROM circuits WHERE name = 'Marina Bay Street Circuit') ORDER BY CAST(SPLIT_PART(q3, ':', 1) AS INTEGER) * 60 + CAST(SPLIT_PART(SPLIT_PART(q3, ':', 2), '.', 1) AS REAL) + CAST(SPLIT_PART(q3, '.', 2) AS REAL) / 1000 ASC LIMIT 1", "complexity_score": 0.2, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "As of the present, what is the full name of the youngest racer? Indicate her nationality and the name of the race to which he/she first joined.", "sql": "SELECT T1.forename, T1.surname, T1.nationality, T3.name FROM drivers AS T1 INNER JOIN driverStandings AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T2.raceId = T3.raceId WHERE T1.dob notnull ORDER BY T1.dob DESC LIMIT 1", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "How many accidents did the driver who had the highest number accidents in the Canadian Grand Prix have?", "sql": "SELECT COUNT(T1.driverId) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN status AS T3 ON T1.statusId = T3.statusId WHERE T3.statusId = 3 AND T2.name = 'Canadian Grand Prix' GROUP BY T1.driverId ORDER BY COUNT(T1.driverId) DESC NULLS LAST LIMIT 1", "complexity_score": 0.109, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Which top 20 driver created the shortest lap time ever record in a Formula_1 race? Please give them full names.", "sql": "WITH lap_times_in_seconds AS (SELECT driverId, (CASE WHEN SPLIT_PART(time, ':', 1) <> '' THEN CAST(SPLIT_PART(time, ':', 1) AS float) * 60 ELSE 0 END + CASE WHEN SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 1) <> '' THEN CAST(SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 1) AS float) ELSE 0 END + CASE WHEN SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 2) <> '' THEN CAST(SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 2) AS float) / 1000 ELSE 0 END) AS time_in_seconds FROM lapTimes) SELECT T2.forename, T2.surname, T1.driverId FROM (SELECT driverId, MIN(time_in_seconds) AS min_time_in_seconds FROM lap_times_in_seconds GROUP BY driverId) AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId ORDER BY T1.min_time_in_seconds ASC LIMIT 20", "complexity_score": 0.137, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["CTE", "FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WITH"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "formula_1", "intent": "Please list the lap records for the circuits in Italy.", "sql": "WITH fastest_lap_times AS (SELECT T1.raceId, T1.FastestLapTime, (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) AS time_in_seconds FROM results AS T1 WHERE T1.FastestLapTime IS NOT NULL) SELECT T1.FastestLapTime AS lap_record FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId INNER JOIN (SELECT MIN(fastest_lap_times.time_in_seconds) AS min_time_in_seconds FROM fastest_lap_times INNER JOIN races AS T2 ON fastest_lap_times.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId WHERE T3.country = 'Italy') AS T4 ON (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) = T4.min_time_in_seconds LIMIT 1", "complexity_score": 0.261, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-LIMIT-SUBQUERY", "clauses_present": ["CTE", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "SUBQUERY", "WHERE", "WITH"], "num_joins": 5, "num_subqueries": 1, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Among the superheroes with the super power of \"Super Strength\", how many of them have a height of over 200cm?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Super Strength' AND T1.height_cm > 200", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Among the superheroes with blue eyes, how many of them have the super power of \"Agility\"?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN colour AS T4 ON T1.eye_colour_id = T4.id WHERE T3.power_name = 'Agility' AND T4.colour = 'Blue'", "complexity_score": 0.138, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Please list the superhero names of all the superheroes that have blue eyes and blond hair.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T2.colour = 'Blue' AND T3.colour = 'Blond'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Rank heroes published by Marvel Comics by their height in descending order.", "sql": "SELECT superhero_name, height_cm, RANK() OVER (ORDER BY height_cm DESC NULLS LAST) AS HeightRank FROM superhero INNER JOIN publisher ON superhero.publisher_id = publisher.id WHERE publisher.publisher_name = 'Marvel Comics'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Rank superheroes from Marvel Comics by their eye color popularity, starting with the most common color.", "sql": "SELECT colour.colour AS EyeColor, COUNT(superhero.id) AS Count, RANK() OVER (ORDER BY COUNT(superhero.id) DESC NULLS LAST) AS PopularityRank FROM superhero INNER JOIN colour ON superhero.eye_colour_id = colour.id INNER JOIN publisher ON superhero.publisher_id = publisher.id WHERE publisher.publisher_name = 'Marvel Comics' GROUP BY colour.colour", "complexity_score": 0.105, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "List the superheroes from Marvel Comics who have the super power of 'Super Strength'.", "sql": "SELECT superhero_name FROM superhero AS T1 WHERE EXISTS(SELECT 1 FROM hero_power AS T2 INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Super Strength' AND T1.id = T2.hero_id) AND EXISTS(SELECT 1 FROM publisher AS T4 WHERE T4.publisher_name = 'Marvel Comics' AND T1.publisher_id = T4.id)", "complexity_score": 0.116, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which publisher published the slowest superhero?", "sql": "SELECT T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN hero_attribute AS T3 ON T1.id = T3.hero_id INNER JOIN attribute AS T4 ON T3.attribute_id = T4.id WHERE T4.attribute_name = 'Speed' ORDER BY T3.attribute_value NULLS FIRST LIMIT 1", "complexity_score": 0.12200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many gold-eyed superheroes did Marvel Comics publish?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN colour AS T3 ON T1.eye_colour_id = T3.id WHERE T2.publisher_name = 'Marvel Comics' AND T3.colour = 'Gold'", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Who is the dumbest superhero?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Intelligence' ORDER BY T2.attribute_value NULLS FIRST LIMIT 1", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is Copycat's race?", "sql": "SELECT T2.race FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id WHERE T1.superhero_name = 'Copycat'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which superheroes have a durability attribute value of less than 50?", "sql": "SELECT superhero_name FROM superhero AS T1 WHERE EXISTS(SELECT 1 FROM hero_attribute AS T2 INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Durability' AND T2.attribute_value < 50 AND T1.id = T2.hero_id)", "complexity_score": 0.08900000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What are the names of the superheroes with the power of death touch?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Death Touch'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many female superheroes have a strength value of 100?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id INNER JOIN gender AS T4 ON T1.gender_id = T4.id WHERE T3.attribute_name = 'Strength' AND T2.attribute_value = 100 AND T4.gender = 'Female'", "complexity_score": 0.14800000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the percentage of superheroes who act in their own self-interest or make decisions based on their own moral code? Indicate how many of the said superheroes were published by Marvel Comics.", "sql": "SELECT (CAST(COUNT(*) AS REAL) * 100 / NULLIF((SELECT COUNT(*) FROM superhero), 0)), CAST(SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) AS REAL) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN alignment AS T3 ON T3.id = T1.alignment_id WHERE T3.alignment = 'Bad'", "complexity_score": 0.181, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Between DC and Marvel Comics, which publisher has published more superheroes? Find the difference in the number of superheroes they have published.", "sql": "SELECT SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.publisher_name = 'DC Comics' THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Give the publisher ID of Star Trek.", "sql": "SELECT id FROM publisher WHERE publisher_name = 'Star Trek'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the total number of superheroes without full name?", "sql": "SELECT COUNT(id) FROM superhero WHERE full_name IS NULL", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the average weight of all female superheroes?", "sql": "SELECT AVG(T1.weight_kg) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id WHERE T2.gender = 'Female'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "List down at least five superpowers of male superheroes.", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T3.id = T2.power_id INNER JOIN gender AS T4 ON T4.id = T1.gender_id WHERE T4.gender = 'Male' LIMIT 5", "complexity_score": 0.12200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Among the superheroes with height from 170 to 190, list the names of the superheroes with no eye color.", "sql": "SELECT DISTINCT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.height_cm BETWEEN 170 AND 190 AND T2.colour = 'No Colour'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Provide the hair colour of the human superhero who is 185 cm tall.", "sql": "SELECT DISTINCT T3.colour FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T1.height_cm = 185 AND T2.race = 'Human'", "complexity_score": 0.097, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "In superheroes with height between 150 to 180, what is the percentage of heroes published by Marvel Comics?", "sql": "SELECT CAST(COUNT(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.height_cm BETWEEN 150 AND 180", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Among the male superheroes, list the super hero names of superheroes with weight greater than the 79% average weight of all superheroes.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id WHERE T2.gender = 'Male' AND T1.weight_kg * 100 > (SELECT AVG(weight_kg) FROM superhero) * 79", "complexity_score": 0.14400000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What are the superpowers of heroes with ID 1?", "sql": "SELECT DISTINCT T2.power_name FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T1.hero_id = 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many heroes have stealth power?", "sql": "SELECT COUNT(T1.hero_id) FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T2.power_name = 'Stealth'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the hero's full name with the highest attribute in strength?", "sql": "SELECT T1.full_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Strength' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which superhero has the most durability published by Dark Horse Comics?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T3.id = T2.attribute_id INNER JOIN publisher AS T4 ON T4.id = T1.publisher_id WHERE T4.publisher_name = 'Dark Horse Comics' AND T3.attribute_name = 'Durability' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.132, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "List the eyes, hair and skin colour of all female superheroes published by Dark Horse Comics.", "sql": "SELECT T1.eye_colour_id, T1.hair_colour_id, T1.skin_colour_id FROM superhero AS T1 INNER JOIN publisher AS T2 ON T2.id = T1.publisher_id INNER JOIN gender AS T3 ON T3.id = T1.gender_id WHERE T2.publisher_name = 'Dark Horse Comics' AND T3.gender = 'Female'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which superhero has the same eyes, hair and skin colour? Indicate the publisher of the superhero.", "sql": "SELECT T1.superhero_name, T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.eye_colour_id = T1.hair_colour_id AND T1.eye_colour_id = T1.skin_colour_id", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the percentage of blue female superheroes among all female superheroes?", "sql": "SELECT CAST(COUNT(CASE WHEN T3.colour = 'Blue' THEN T1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.gender = 'Female'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many powers does Amazo hero have?", "sql": "SELECT COUNT(T1.power_id) FROM hero_power AS T1 INNER JOIN superhero AS T2 ON T1.hero_id = T2.id WHERE T2.superhero_name = 'Amazo'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Provide the heights of the heroes whose eye colours are amber.", "sql": "SELECT T1.height_cm FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T2.colour = 'Amber'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "List the heroes' names whose eyes and hair colours are both black.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id AND T1.hair_colour_id = T2.id WHERE T2.colour = 'Black'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Describe the names of neutral alignment superheroes.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id WHERE T2.alignment = 'Neutral'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many heroes have the highest attribute value in strength?", "sql": "SELECT COUNT(T1.hero_id) FROM hero_attribute AS T1 INNER JOIN attribute AS T2 ON T1.attribute_id = T2.id WHERE T2.attribute_name = 'Strength' AND T1.attribute_value = (SELECT MAX(attribute_value) FROM hero_attribute)", "complexity_score": 0.15000000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many percent of female heroes were published by Marvel Comics?", "sql": "SELECT CAST(COUNT(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN gender AS T3 ON T1.gender_id = T3.id WHERE T3.gender = 'Female'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Calculate the difference between Emil Blonsky's weight and Charles Chandler's weight.", "sql": "SELECT (SELECT weight_kg FROM superhero WHERE full_name LIKE 'Emil Blonsky') - (SELECT weight_kg FROM superhero WHERE full_name LIKE 'Charles Chandler') AS CALCULATE", "complexity_score": 0.132, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Calculate the average height for all superhero.", "sql": "SELECT CAST(SUM(height_cm) AS REAL) / NULLIF(COUNT(id), 0) FROM superhero", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is Abomination's superpower?", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T1.superhero_name = 'Abomination'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which hero was the fastest?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Speed' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "State all of 3-D Man's attributes along with their values.", "sql": "SELECT T3.attribute_name, T2.attribute_value FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T1.superhero_name = '3-D Man'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which superheroes have blue eyes with brown hair?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T2.colour = 'Blue' AND T3.colour = 'Brown'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "What is the publisher for Hawkman, Karate Kid and Speedy?", "sql": "SELECT T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.superhero_name IN ('Hawkman', 'Karate Kid', 'Speedy')", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Calculate the percentage of superheroes with blue eyes.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.colour = 'Blue' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Find the ratio between male superheroes and female superheroes.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.gender = 'Male' THEN T1.id ELSE NULL END) AS REAL) / NULLIF(COUNT(CASE WHEN T2.gender = 'Female' THEN T1.id ELSE NULL END), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Provide the eye colour of the superhero who has Karen Beecher-Duncan as their full name.", "sql": "SELECT T2.colour FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.full_name = 'Karen Beecher-Duncan'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "In superheroes with missing weight data, calculate the difference between the number of superheroes with blue eyes and no eye color.", "sql": "SELECT SUM(CASE WHEN T2.id = 7 THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.id = 1 THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.weight_kg = 0 OR T1.weight_kg IS NULL", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "How many green-skinned villains are there in the superhero universe?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.alignment = 'Bad' AND T3.colour = 'Green'", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Identify superheroes who can control wind and list their names in alphabetical order.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Wind Control' ORDER BY T1.superhero_name NULLS FIRST", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Identify the gender of the superhero who has the ability of Phoenix Force.", "sql": "SELECT T4.gender FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN gender AS T4 ON T1.gender_id = T4.id WHERE T3.power_name = 'Phoenix Force'", "complexity_score": 0.12200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "superhero", "intent": "Which publisher created more superheroes: DC or Marvel Comics? Find the difference in the number of superheroes.", "sql": "SELECT SUM(CASE WHEN T2.publisher_name = 'DC Comics' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which user has a higher reputation, Harlan or Jarrod Dixon?", "sql": "SELECT DisplayName FROM users WHERE DisplayName IN ('Harlan', 'Jarrod Dixon') AND Reputation = (SELECT MAX(Reputation) FROM users WHERE DisplayName IN ('Harlan', 'Jarrod Dixon'))", "complexity_score": 0.11600000000000002, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Please list the display names of all the users whose accounts were created in the year 2011.", "sql": "SELECT DisplayName FROM users WHERE TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "How many users last accessed the website after 2014/9/1?", "sql": "SELECT COUNT(Id) FROM users WHERE DATE(LastAccessDate) > '2014-09-01'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Who is the owner of the post \"Eliciting priors from experts\"?", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Title = 'Eliciting priors from experts'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "How many posts does the user csgillespie own?", "sql": "SELECT COUNT(T1.id) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T2.DisplayName = 'csgillespie'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the display name of the user who last edited the post \"Examples for teaching: Correlation does not mean causation\"?", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.LastEditorUserId = T2.Id WHERE T1.Title = 'Examples for teaching: Correlation does not mean causation'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among the posts owned by an elder user, how many of them have a score of over 19?", "sql": "SELECT COUNT(T1.Id) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score >= 20 AND T2.Age > 65", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "From which post is the tag \"bayesian\" excerpted from? Please give the body of the post.", "sql": "SELECT T2.Body FROM tags AS T1 INNER JOIN posts AS T2 ON T2.Id = T1.ExcerptPostId WHERE T1.TagName = 'bayesian'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the average score of the posts owned by the user csgillespie?", "sql": "SELECT AVG(T1.Score) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T2.DisplayName = 'csgillespie'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among the posts with a score of over 5, what is the percentage of them being owned by an elder user?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Age > 65 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score > 5", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "User No.3025 gave a comment at 20:29:39 on 2014/4/23 to a post, how many favorite counts did that post get?", "sql": "SELECT T1.FavoriteCount FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId WHERE T2.CreationDate = '2014-04-23 20:29:39.0' AND T2.UserId = 3025", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "User No.23853 gave a comment to a post at 9:08:18 on 2013/7/12, was that post well-finished?", "sql": "SELECT CASE WHEN T2.ClosedDate IS NULL THEN 'NOT well-finished' ELSE 'well-finished' END AS resylt FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T1.UserId = 23853 AND T1.CreationDate = '2013-07-12 09:08:18.0'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "For the user with the display name of \"Tiago Pasqualini\", how many posts did he/she own?", "sql": "SELECT COUNT(T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Tiago Pasqualini'", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Provide the display name of the user who made the vote No.6347.", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.UserId WHERE T2.Id = 6347", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "For the user No.24, how many times is the number of his/her posts compared to his/her votes?", "sql": "SELECT CAST(COUNT(DISTINCT T2.Id) AS REAL) / NULLIF(COUNT(DISTINCT T1.Id), 0) FROM votes AS T1 INNER JOIN posts AS T2 ON T1.UserId = T2.OwnerUserId WHERE T1.UserId = 24", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "How many views did the post titled 'Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer' get?", "sql": "SELECT ViewCount FROM posts WHERE Title = 'Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Write the contents of comments with a score of 17.", "sql": "SELECT Text FROM comments WHERE Score = 17", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Name the user that commented 'thank you user93!'", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.UserId WHERE T2.Text = 'thank you user93!'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which user made a post titled 'Understanding what Dassault iSight is doing?' and how much is the reputation of the user?", "sql": "SELECT T1.DisplayName, T1.Reputation FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T2.Title = 'Understanding what Dassault iSight is doing?'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Who is the owner of the post titled 'Open source tools for visualizing multi-dimensional data?'", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Title = 'Open source tools for visualizing multi-dimensional data?'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Write all the comments left by users who edited the post titled 'Why square the difference instead of taking the absolute value in standard deviation?'", "sql": "SELECT T2.Comment FROM posts AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.PostId WHERE T1.Title = 'Why square the difference instead of taking the absolute value in standard deviation?'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which user added a bounty amount of 50 to the post title mentioning variance?", "sql": "SELECT T3.DisplayName, T1.Title FROM posts AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.PostId INNER JOIN users AS T3 ON T3.Id = T2.UserId WHERE T2.BountyAmount = 50 AND T1.Title LIKE '%variance%'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Calculate the average view count of each post tagged as 'humor' and list the title and the comment of each post.", "sql": "SELECT AVG(T2.ViewCount) AS AverageViewCount, T2.Title, T1.Text FROM comments AS T1 INNER JOIN posts AS T2 ON T2.Id = T1.PostId WHERE T2.Tags = '' GROUP BY T2.Title, T1.Text", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "How many users are awarded with more than 5 badges?", "sql": "SELECT COUNT(UserId) FROM (SELECT UserId, COUNT(Name) AS num FROM badges GROUP BY UserId) AS T WHERE T.num > 5", "complexity_score": 0.10500000000000002, "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which user have only one post history per post and having at least 1000 views?", "sql": "SELECT T2.UserId FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T3.ViewCount >= 1000 GROUP BY T2.UserId HAVING COUNT(DISTINCT T2.PostHistoryTypeId) = 1", "complexity_score": 0.1, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the percentage difference of student badges given during 2010 and 2011?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) - CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) FROM badges WHERE Name = 'Student'", "complexity_score": 0.041, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the average of the up votes and the average user age for users creating more than 10 posts?", "sql": "SELECT AVG(T1.UpVotes), AVG(T1.Age) FROM users AS T1 INNER JOIN (SELECT OwnerUserId, COUNT(*) AS post_count FROM posts GROUP BY OwnerUserId HAVING COUNT(*) > 10) AS T2 ON T1.Id = T2.OwnerUserId", "complexity_score": 0.152, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Calculate the ratio of votes in 2010 and 2011.", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END), 0) FROM votes", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which post by slashnick has the most answers count? State the post ID.", "sql": "SELECT T2.PostId FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.DisplayName = 'slashnick' ORDER BY T3.AnswerCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among posts by Harvey Motulsky and Noah Snyder, which one has higher popularity?", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.DisplayName = 'Harvey Motulsky' OR T1.DisplayName = 'Noah Snyder' GROUP BY T1.DisplayName ORDER BY SUM(T3.ViewCount) DESC NULLS LAST LIMIT 1", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "State all the tags used by Mark Meckes in his posts that doesn't have comments.", "sql": "SELECT T3.Tags FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId WHERE T1.DisplayName = 'Mark Meckes' AND T3.CommentCount = 0", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Based on posts posted by Community, calculate the percentage of posts that use the R language.", "sql": "SELECT CAST(SUM(CASE WHEN T3.TagName = 'r' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN tags AS T3 ON T3.ExcerptPostId = T2.PostId WHERE T1.DisplayName = 'Community'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Calculate the difference in view count from post posted by Mornington and view count from posts posted by Amos.", "sql": "SELECT SUM(CASE WHEN T1.DisplayName = 'Mornington' THEN T3.ViewCount ELSE 0 END) - SUM(CASE WHEN T1.DisplayName = 'Amos' THEN T3.ViewCount ELSE 0 END) AS diff FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId", "complexity_score": 0.092, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the average monthly number of links created in 2010 for posts that have no more than 2 answers?", "sql": "SELECT CAST(COUNT(T1.Id) AS REAL) / NULLIF(12, 0) FROM postLinks AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.AnswerCount <= 2 AND TO_CHAR(CAST(T1.CreationDate AS TIMESTAMP), 'YYYY') = '2010'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "When did 'chl' cast its first vote in a post?", "sql": "SELECT T2.CreationDate FROM users AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.UserId WHERE T1.DisplayName = 'chl' ORDER BY T2.CreationDate NULLS FIRST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the display name of the user who acquired the first Autobiographer badge?", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN badges AS T2 ON T1.Id = T2.UserId WHERE T2.name = 'Autobiographer' ORDER BY T2.Date LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among the users located in United Kingdom, how many users whose post have a total favorite amount of 4 or more?", "sql": "SELECT COUNT(T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.Location = 'United Kingdom' AND T2.FavoriteCount >= 4", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which post by Harvey Motulsky has the most views? Please give the id and title of this post.", "sql": "SELECT T2.Id, T2.Title FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Harvey Motulsky' ORDER BY T2.ViewCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Which is the most valuable post in 2010? Please give its id and the owner's display name.", "sql": "SELECT T2.OwnerUserId, T1.DisplayName FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE TO_CHAR(CAST(T1.CreationDate AS TIMESTAMP), 'YYYY') = '2010' ORDER BY T2.FavoriteCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the percentage of posts whose owners had a reputation of over 1000 in 2011?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(T2.CreaionDate AS TIMESTAMP), 'YYYY') = '2011' AND T1.Reputation > 1000 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId", "complexity_score": 0.067, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Identify the total views on the post 'Computer Game Datasets'. Name the user who posted it last time.", "sql": "SELECT T2.ViewCount, T3.DisplayName FROM postHistory AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id INNER JOIN users AS T3 ON T2.LastEditorUserId = T3.Id WHERE T1.Text = 'Computer Game Datasets'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "How many comments were added to the post with the highest score?", "sql": "SELECT COUNT(T2.Id) FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId GROUP BY T1.Id ORDER BY T1.Score DESC NULLS LAST LIMIT 1", "complexity_score": 0.051000000000000004, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Provide the text of the latest 10 comments to the post with the title 'Analysing wind data with R' and the display name of the user who left it.", "sql": "SELECT T3.Text, T1.DisplayName FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId INNER JOIN comments AS T3 ON T2.Id = T3.PostId WHERE T2.Title = 'Analysing wind data with R' ORDER BY T1.CreationDate DESC NULLS LAST LIMIT 10", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among all the posts posted by the most influential user, identify the percentage with a score above 50.", "sql": "SELECT CAST(SUM(CASE WHEN T2.Score > 50 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId INNER JOIN (SELECT MAX(Reputation) AS max_reputation FROM users) AS T3 ON T1.Reputation = T3.max_reputation", "complexity_score": 0.164, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "What is the excerpt post ID and wiki post ID of the tag named sample?", "sql": "SELECT ExcerptPostId, WikiPostId FROM tags WHERE TagName = 'sample'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Give the user's reputation and up vote number of the user that commented \"fine, you win :)\".", "sql": "SELECT T2.Reputation, T2.UpVotes FROM comments AS T1 INNER JOIN users AS T2 ON T1.UserId = T2.Id WHERE T1.Text = 'fine, you win :)'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among the posts with views ranging from 100 to 150, what is the comment with the highest score?", "sql": "SELECT Text FROM comments WHERE PostId IN (SELECT Id FROM posts WHERE ViewCount BETWEEN 100 AND 150) ORDER BY Score DESC NULLS LAST LIMIT 1", "complexity_score": 0.11000000000000001, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "In posts with 1 comment, how many of the comments have 0 score?", "sql": "SELECT COUNT(T1.id) FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.CommentCount = 1 AND T2.Score = 0", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "codebase_community", "intent": "Among the comments with scores between 5 to 10, what is the percentage of the users with 0 up votes?", "sql": "SELECT CAST(SUM(CASE WHEN T1.UpVotes = 0 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) AS per FROM users AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.UserId WHERE T2.Score BETWEEN 5 AND 10", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which are the cards that have incredibly powerful foils.", "sql": "SELECT id FROM cards WHERE NOT cardKingdomFoilId IS NULL AND NOT cardKingdomId IS NULL", "complexity_score": 0.027000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What are the borderless cards available without powerful foils?", "sql": "SELECT id FROM cards WHERE borderColor = 'borderless' AND (cardKingdomId IS NULL OR cardKingdomId IS NULL)", "complexity_score": 0.037000000000000005, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "List all the mythic rarity print cards banned in gladiator format.", "sql": "SELECT DISTINCT T1.id FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.format = 'gladiator' AND T2.status = 'Banned' AND T1.rarity = 'mythic'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "For artifact type of cards that do not have multiple faces on the same card, state its legalities status for vintage play format.", "sql": "SELECT DISTINCT T2.status FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.type = 'Artifact' AND T2.format = 'vintage' AND T1.side IS NULL", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "List all the card id and artist with unknown power which are legal for commander play format.", "sql": "SELECT T1.id, T1.artist FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.status = 'Legal' AND T2.format = 'commander' AND (T1.power IS NULL OR T1.power = '*')", "complexity_score": 0.082, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Find all cards illustrated by Stephen Daniel and describe the text of the ruling of these cards. State if these cards have missing or degraded properties and values.", "sql": "SELECT T1.id, T2.text, T1.hasContentWarning FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE T1.artist = 'Stephen Daniele'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Name the card and artist with the most ruling information. Also state if the card is a promotional printing.", "sql": "SELECT T1.name, T1.artist, T1.isPromo FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE T1.isPromo = 1 AND T1.artist = (SELECT artist FROM cards WHERE isPromo = 1 GROUP BY artist HAVING COUNT(DISTINCT uuid) = (SELECT MAX(count_uuid) FROM (SELECT COUNT(DISTINCT uuid) AS count_uuid FROM cards WHERE isPromo = 1 GROUP BY artist) AS subquery)) LIMIT 1", "complexity_score": 0.32900000000000007, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 3, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Calculate the percentage of the cards availabe in Chinese Simplified.", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'Chinese Simplified' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid", "complexity_score": 0.05700000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "How many cards have infinite power?", "sql": "SELECT COUNT(*) FROM cards WHERE power = '*'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the border color of card \"Ancestor's Chosen\"?", "sql": "SELECT DISTINCT borderColor FROM cards WHERE name = 'Ancestor''s Chosen'", "complexity_score": 0.017, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the rule of playing card \"Benalish Knight\"?", "sql": "SELECT T2.format FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.name = 'Benalish Knight'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the percentage of borderless cards?", "sql": "SELECT CAST(SUM(CASE WHEN borderColor = 'borderless' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the percentage of cards whose language is French among the Story Spotlight cards?", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'French' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.isStorySpotlight = 1", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "How many cards with original type of \"Summon - Angel\" have subtype other than \"Angel\"?", "sql": "SELECT COUNT(id) FROM cards WHERE originalType = 'Summon - Angel' AND subtypes <> 'Angel'", "complexity_score": 0.033, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What are the cards belong to duel deck a? List the ID.", "sql": "SELECT id FROM cards WHERE duelDeck = 'a'", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "How many of the banned cards are white border?", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.status = 'Banned' AND T1.borderColor = 'white'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Among the Artifact cards, which are black color and comes with foreign languague translation?", "sql": "SELECT DISTINCT T1.name FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.originalType = 'Artifact' AND T1.colors = 'B'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the mana cost of cards with a normal layout, a 2003 frame version, with a black border color, and available in paper and mtgo?", "sql": "SELECT manaCost FROM cards WHERE availability = 'mtgo,paper' AND borderColor = 'black' AND frameVersion = '2003' AND layout = 'normal'", "complexity_score": 0.047, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the percentage of Story Spotlight cards that do not have a text box? List them by their ID.", "sql": "SELECT CAST(SUM(CASE WHEN isTextless = 0 AND isStorySpotlight = 1 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards", "complexity_score": 0.032, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "How many Brazilian Portuguese translated sets are inside the Commander block?", "sql": "SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T2.language = 'Portuguese (Brazil)' AND T1.block = 'Commander'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Lists all types of cards in German.", "sql": "SELECT T1.subtypes, T1.supertypes FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T2.language = 'German' AND NOT T1.subtypes IS NULL AND NOT T1.supertypes IS NULL", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "How many unknown power cards contain info about the triggered ability", "sql": "SELECT Count(DISTINCT T1.id) FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE (T1.power IS NULL OR T1.power = '*') AND T2.text LIKE '%triggered ability%'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Indicates the number of cards with pre-modern format, ruling text \"This is a triggered mana ability.\" that do not have multiple faces.", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid INNER JOIN rulings AS T3 ON T1.uuid = T3.uuid WHERE T2.format = 'premodern' AND T3.text = 'This is a triggered mana ability.' AND T1.Side IS NULL", "complexity_score": 0.113, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the foreign name of the card in French of type Creature, normal layout and black border color, by artist Matthew D. Wilson?", "sql": "SELECT name FROM foreign_data WHERE uuid IN (SELECT uuid FROM cards WHERE types = 'Creature' AND layout = 'normal' AND borderColor = 'black' AND artist = 'Matthew D. Wilson') AND language = 'French'", "complexity_score": 0.15000000000000002, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What language is the set of 180 cards that belongs to the Ravnica block translated into?", "sql": "SELECT T2.language FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T1.block = 'Ravnica' AND T1.baseSetSize = 180", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What percentage of cards with format commander and legal status do not have a content warning?", "sql": "SELECT CAST(SUM(CASE WHEN T1.hasContentWarning = 0 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.format = 'commander' AND T2.status = 'Legal'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What percentage of cards without power are in French?", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'French' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.power IS NULL OR T1.power = '*'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the language of the card with the multiverse number 149934?", "sql": "SELECT language FROM foreign_data WHERE multiverseid = 149934", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What proportion of cards do not have a text box with a normal layout?", "sql": "SELECT CAST(SUM(CASE WHEN isTextless = 1 AND layout = 'normal' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM cards", "complexity_score": 0.032, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What languages are available in the set known as Archenemy on the magic card market and having the code ARC?", "sql": "SELECT T2.language FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T1.mcmName = 'Archenemy' AND T2.setCode = 'ARC'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which foreign language used by \"A Pedra Fellwar\"?", "sql": "SELECT DISTINCT language FROM foreign_data WHERE name = 'A Pedra Fellwar'", "complexity_score": 0.017, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which card costs more converted mana, \"Serra Angel\" or \"Shrine Keeper\"?", "sql": "SELECT name FROM cards WHERE name IN ('Serra Angel', 'Shrine Keeper') ORDER BY convertedManaCost DESC NULLS LAST LIMIT 1", "complexity_score": 0.017, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What's the Italian name of the set of cards with \"Ancestor's Chosen\" is in?", "sql": "SELECT translation FROM set_translations WHERE setCode IN (SELECT setCode FROM cards WHERE name = 'Ancestor''s Chosen') AND language = 'Italian'", "complexity_score": 0.12000000000000002, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "For the set of cards with \"Ancestor's Chosen\" in it, is there a Korean version of it?", "sql": "SELECT CASE WHEN SUM(CASE WHEN T2.language = 'Korean' AND NOT T2.translation IS NULL THEN 1 ELSE 0 END) > 0 THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.setCode WHERE T1.name = 'Ancestor''s Chosen'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Among the cards in the set \"Hauptset Zehnte Edition\", how many of them are designed by Adam Rex?", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.setCode WHERE T2.translation = 'Hauptset Zehnte Edition' AND T1.artist = 'Adam Rex'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the Simplified Chinese translation of the name of the set \"Eighth Edition\"?", "sql": "SELECT T2.translation FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE T1.name = 'Eighth Edition' AND T2.language = 'Chinese Simplified'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Did the set of cards with \"Angel of Mercy\" appear on Magic: The Gathering Online?", "sql": "SELECT CASE WHEN NOT T2.mtgoCode IS NULL THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T1.name = 'Angel of Mercy'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Among the sets in the block \"Ice Age\", how many of them have an Italian translation?", "sql": "SELECT COUNT(DISTINCT T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE T1.block = 'Ice Age' AND T2.language = 'Italian' AND NOT T2.translation IS NULL", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Is the set of cards with Adarkar Valkyrie only available outside the United States?", "sql": "SELECT CASE WHEN isForeignOnly = 1 THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T1.name = 'Adarkar Valkyrie'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Among the sets of cards that have an Italian translation, how many of them have a base set number of under 100?", "sql": "SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE NOT T2.translation IS NULL AND T1.baseSetSize < 100 AND T2.language = 'Italian'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which of these artists have designed a card in the set Coldsnap, Jeremy Jarvis, Aaron Miller or Chippy?", "sql": "SELECT T1.artist FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE (T2.name = 'Coldsnap' AND T1.artist = 'Chippy') OR (T2.name = 'Coldsnap' AND T1.artist = 'Aaron Miller') OR (T2.name = 'Coldsnap' AND T1.artist = 'Jeremy Jarvis') GROUP BY T1.artist", "complexity_score": 0.10200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Among the cards with converted mana cost higher than 5 in the set Coldsnap, how many of them have unknown power?", "sql": "SELECT SUM(CASE WHEN T1.power = '*' OR T1.power IS NULL THEN 1 ELSE 0 END) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap' AND T1.convertedManaCost > 5", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the Italian flavor text of the card \"Ancestor's Chosen\"?", "sql": "SELECT T2.flavorText FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T2.uuid = T1.uuid WHERE T1.name = 'Ancestor''s Chosen' AND T2.language = 'Italian'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Please list the Italian text ruling of all the cards in the set Coldsnap.", "sql": "SELECT DISTINCT T1.text FROM foreign_data AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid INNER JOIN sets AS T3 ON T3.code = T2.setCode WHERE T3.name = 'Coldsnap' AND T1.language = 'Italian'", "complexity_score": 0.097, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Please list the Italian names of the cards in the set Coldsnap with the highest converted mana cost.", "sql": "SELECT T2.name FROM foreign_data AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid INNER JOIN sets AS T3 ON T3.code = T2.setCode WHERE T3.name = 'Coldsnap' AND T1.language = 'Italian' ORDER BY T2.convertedManaCost DESC NULLS LAST", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the percentage of the cards with a converted mana cost of 7 in the set Coldsnap?", "sql": "SELECT CAST(SUM(CASE WHEN T1.convertedManaCost = 7 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "What is the percentage of incredibly powerful cards in the set Coldsnap?", "sql": "SELECT CAST(SUM(CASE WHEN NOT T1.cardKingdomFoilId IS NULL AND NOT T1.cardKingdomId IS NULL THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'", "complexity_score": 0.07400000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which of the play format has the highest number of banned status? Indicate the play format and the names of all the card meet the condition.", "sql": "WITH MaxBanned AS (SELECT format FROM legalities WHERE status = 'Banned' GROUP BY format ORDER BY COUNT(*) DESC LIMIT 1)SELECT T2.format, T1.name FROM cards AS T1 INNER JOIN legalities AS T2 ON T2.uuid = T1.uuid INNER JOIN MaxBanned MB ON MB.format = T2.format WHERE T2.status = 'Banned'", "complexity_score": 0.14400000000000002, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["CTE", "FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE", "WITH"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Which cards are ranked 1st on EDHRec? List all of the cards name and its banned play format.", "sql": "SELECT T1.name, T2.format FROM cards AS T1 INNER JOIN legalities AS T2 ON T2.uuid = T1.uuid WHERE T1.edhrecRank = 1 AND T2.status = 'Banned' GROUP BY T1.name, T2.format", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "List the names of all the cards in the set Hour of Devastation and find the formats in which these cards are legal.", "sql": "SELECT DISTINCT T2.name, CASE WHEN T1.status = 'Legal' THEN T1.format ELSE NULL END FROM legalities AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid WHERE T2.setCode IN (SELECT code FROM sets WHERE name = 'Hour of Devastation')", "complexity_score": 0.14500000000000002, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "Find and list the names of sets which doesn't have Japanese translation but have Korean translation.", "sql": "SELECT name FROM sets WHERE code IN (SELECT setCode FROM set_translations WHERE language = 'Korean' AND NOT language LIKE '%Japanese%')", "complexity_score": 0.12000000000000002, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "card_games", "intent": "List all the frame styles and cards Allen Williams worked on and find any banned cards if there are any.", "sql": "SELECT DISTINCT T1.frameVersion, T1.name, CASE WHEN T2.status = 'Banned' THEN T1.name ELSE 'NO' END FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.artist = 'Allen Williams'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the most common bond type?", "sql": "SELECT T.bond_type FROM (SELECT bond_type, COUNT(bond_id) FROM bond GROUP BY bond_type ORDER BY COUNT(bond_id) DESC NULLS LAST LIMIT 1) AS T", "complexity_score": 0.09800000000000002, "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "SUBQUERY"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Calculate the average number of oxygen atoms in single-bonded molecules.", "sql": "SELECT AVG(oxygen_count) FROM (SELECT T1.molecule_id, COUNT(T1.element) AS oxygen_count FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '-' AND T1.element = 'o' GROUP BY T1.molecule_id) AS oxygen_counts", "complexity_score": 0.15000000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "On average how many carcinogenic molecules are single bonded?", "sql": "SELECT AVG(single_bond_count) FROM (SELECT T3.molecule_id, COUNT(T1.bond_type) AS single_bond_count FROM bond AS T1 INNER JOIN atom AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN molecule AS T3 ON T3.molecule_id = T2.molecule_id WHERE T1.bond_type = '-' AND T3.label = '+' GROUP BY T3.molecule_id) AS subquery", "complexity_score": 0.18500000000000003, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Find the triple-bonded molecules which are carcinogenic.", "sql": "SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '#' AND T2.label = '+'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the percentage of carbon in double-bond molecules?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T1.element = 'c' THEN T1.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T1.atom_id), 0) FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '='", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What elements are in the TR004_8_9 bond atoms?", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id = 'TR004_8_9'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What elements are in a double type bond?", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN connected AS T3 ON T1.atom_id = T3.atom_id WHERE T2.bond_type = '='", "complexity_score": 0.087, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Which type of label is the most numerous in atoms with hydrogen?", "sql": "SELECT T.label FROM (SELECT T2.label, COUNT(T2.molecule_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.element = 'h' GROUP BY T2.label ORDER BY COUNT(T2.molecule_id) DESC NULLS LAST LIMIT 1) AS t", "complexity_score": 0.14, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Which element is the least numerous in non-carcinogenic molecules?", "sql": "SELECT T.element FROM (SELECT T1.element, COUNT(DISTINCT T1.molecule_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '-' GROUP BY T1.element ORDER BY COUNT(DISTINCT T1.molecule_id) ASC NULLS FIRST LIMIT 1) AS t", "complexity_score": 0.14, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What type of bond is there between the atoms TR004_8 and TR004_20?", "sql": "SELECT T1.bond_type FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.atom_id = 'TR004_8' AND T2.atom_id2 = 'TR004_20' OR T2.atom_id2 = 'TR004_8' AND T2.atom_id = 'TR004_20'", "complexity_score": 0.082, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "How many atoms with iodine and with sulfur type elements are there in single bond molecules?", "sql": "SELECT COUNT(DISTINCT CASE WHEN T1.element = 'i' THEN T1.atom_id ELSE NULL END) AS iodine_nums, COUNT(DISTINCT CASE WHEN T1.element = 's' THEN T1.atom_id ELSE NULL END) AS sulfur_nums FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_type = '-'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What percentage of carcinogenic-type molecules does not contain fluorine?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T1.element <> 'f' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the percentage of carcinogenic molecules in triple type bonds?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T2.label = '+' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '#'", "complexity_score": 0.09899999999999999, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Please list top three elements of the toxicology of the molecule TR000 in alphabetical order.", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE T.molecule_id = 'TR000' ORDER BY T.element NULLS FIRST LIMIT 3", "complexity_score": 0.017, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the percentage of double bonds in the molecule TR008? Please provide your answer as a percentage with five decimal places.", "sql": "SELECT ROUND(CAST(COUNT(CASE WHEN T.bond_type = '=' THEN T.bond_id ELSE NULL END) AS NUMERIC) * 100 / CAST(COUNT(T.bond_id) AS NUMERIC), 5) AS percentage FROM bond AS T WHERE T.molecule_id = 'TR008'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the percentage of molecules that are carcinogenic? Please provide your answer as a percentage with three decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN t.label = '+' THEN t.molecule_id ELSE NULL END) AS REAL) / NULLIF(COUNT(t.molecule_id), 0) * 100) AS NUMERIC), 3) AS percentage FROM molecule t", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "How much of the hydrogen in molecule TR206 is accounted for? Please provide your answer as a percentage with four decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN T.element = 'h' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0)) AS NUMERIC), 4) AS percentage FROM atom AS T WHERE T.molecule_id = 'TR206'", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the elements of the toxicology and label of molecule TR060?", "sql": "SELECT DISTINCT T1.element, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR060'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Which bond type accounted for the majority of the bonds found in molecule TR010 and state whether or not this molecule is carcinogenic?", "sql": "SELECT T.bond_type FROM (SELECT T1.bond_type, COUNT(T1.molecule_id) FROM bond AS T1 WHERE T1.molecule_id = 'TR010' GROUP BY T1.bond_type ORDER BY COUNT(T1.molecule_id) DESC NULLS LAST LIMIT 1) AS T", "complexity_score": 0.10500000000000002, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Please list top three molecules that have single bonds between two atoms and are not carcinogenic in alphabetical order.", "sql": "SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '-' AND T2.label = '-' ORDER BY T2.molecule_id NULLS FIRST LIMIT 3", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "How many bonds which involved atom 12 does molecule TR009 have?", "sql": "SELECT COUNT(T2.bond_id) FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T1.molecule_id = 'TR009' AND T2.atom_id = T1.molecule_id || '_1' OR T2.atom_id2 = T1.molecule_id || '_2'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the bond type and the atoms of the bond ID of TR001_6_9?", "sql": "SELECT T1.bond_type, T2.atom_id, T2.atom_id2 FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.bond_id = 'TR001_6_9'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "How many connections does the atom 19 have?", "sql": "SELECT COUNT(T.bond_id) FROM connected AS T WHERE RIGHT(T.atom_id, 2) = '19'", "complexity_score": 0.023, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "List all the elements of the toxicology of the molecule \"TR004\".", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE T.molecule_id = 'TR004'", "complexity_score": 0.017, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Among all the atoms from 21 to 25, list all the molecules that are carcinogenic.", "sql": "SELECT DISTINCT T2.molecule_id FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE RIGHT(T1.atom_id, 2) BETWEEN '21' AND '25' AND T2.label = '+'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the bonds that have phosphorus and nitrogen as their atom elements?", "sql": "SELECT T2.bond_id FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id IN (SELECT T3.bond_id FROM connected AS T3 INNER JOIN atom AS T4 ON T3.atom_id = T4.atom_id WHERE T4.element = 'p') AND T1.element = 'n'", "complexity_score": 0.17000000000000004, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Is the molecule with the most double bonds carcinogenic?", "sql": "SELECT T1.label FROM molecule AS T1 INNER JOIN (SELECT T.molecule_id, COUNT(T.bond_type) FROM bond AS T WHERE T.bond_type = '=' GROUP BY T.molecule_id ORDER BY COUNT(T.bond_type) DESC NULLS LAST LIMIT 1) AS T2 ON T1.molecule_id = T2.molecule_id", "complexity_score": 0.14, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the average number of bonds the atoms with the element iodine have?", "sql": "SELECT CAST(COUNT(T2.bond_id) AS REAL) / NULLIF(COUNT(T1.atom_id), 0) FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T1.element = 'i'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "List all the elements of atoms that can not bond with any other atoms.", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE NOT T.element IN (SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id)", "complexity_score": 0.128, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the atoms of the triple bond with the molecule \"TR041\"?", "sql": "SELECT T2.atom_id, T2.atom_id2 FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_type = '#' AND T3.molecule_id = 'TR041'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the elements of the atoms of TR144_8_19?", "sql": "SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR144_8_19'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "List the elements of all the triple bonds.", "sql": "SELECT DISTINCT T3.element FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id INNER JOIN atom AS T3 ON T2.atom_id = T3.atom_id WHERE T1.bond_type = '#'", "complexity_score": 0.087, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What proportion of single bonds are carcinogenic? Please provide your answer as a percentage with five decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN T2.label = '+' THEN T1.bond_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.bond_id), 0)) AS NUMERIC), 5) AS percentage FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '-'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Calculate the total atoms with triple-bond molecules containing the element phosphorus or bromine.", "sql": "SELECT COUNT(T1.atom_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '#' AND T1.element IN ('p', 'br')", "complexity_score": 0.10300000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the composition of element chlorine in percentage among the single bond molecules?", "sql": "SELECT CAST(COUNT(CASE WHEN T.element = 'cl' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0) FROM (SELECT T1.atom_id, T1.element FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '-') AS T", "complexity_score": 0.17500000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What are the elements for bond id TR001_10_11?", "sql": "SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR001_10_11'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the percentage of element chlorine in carcinogenic molecules?", "sql": "SELECT CAST(COUNT(CASE WHEN T1.element = 'cl' THEN T1.element ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.element), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+'", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Tally the toxicology element of the 4th atom of each molecule that was carcinogenic.", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+' AND RIGHT(T1.atom_id, 1) = '4' AND LENGTH(T1.atom_id) = 7", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "What is the ratio of Hydrogen elements in molecule ID TR006? List the ratio with its label.", "sql": "WITH SubQuery AS (SELECT DISTINCT T1.atom_id, T1.element, T1.molecule_id, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR006') SELECT CAST(COUNT(CASE WHEN element = 'h' THEN atom_id ELSE NULL END) AS REAL) / NULLIF(COUNT(atom_id), 0) AS ratio, label FROM SubQuery GROUP BY label", "complexity_score": 0.118, "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["CTE", "DISTINCT", "FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 1, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "toxicology", "intent": "Which non-carcinogenic molecules consisted more than 5 atoms?", "sql": "SELECT T.molecule_id FROM (SELECT T1.molecule_id, COUNT(T2.atom_id) FROM molecule AS T1 INNER JOIN atom AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.label = '-' GROUP BY T1.molecule_id HAVING COUNT(T2.atom_id) > 5) AS t", "complexity_score": 0.14700000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "How many schools with an average score in Math greater than 400 in the SAT test are exclusively virtual?", "sql": "SELECT COUNT(DISTINCT T2.School) FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.Virtual = 'F' AND T1.AvgScrMath > 400", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Please list the codes of the schools with a total enrollment of over 500.", "sql": "SELECT T2.CDSCode FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.\"Enrollment (K-12)\" + T2.\"Enrollment (Ages 5-17)\" > 500", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Among the schools with an SAT excellence rate of over 0.3, what is the highest eligible free rate for students aged 5-17?", "sql": "SELECT MAX(CAST(T1.\"Free Meal Count (Ages 5-17)\" AS REAL) / NULLIF(T1.\"Enrollment (Ages 5-17)\", 0)) FROM frpm AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE CAST(T2.NumGE1500 AS REAL) / NULLIF(T2.NumTstTakr, 0) > 0.3", "complexity_score": 0.058, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Rank schools by their average score in Writing where the score is greater than 499, showing their charter numbers.", "sql": "SELECT CharterNum, AvgScrWrite, RANK() OVER (ORDER BY AvgScrWrite DESC NULLS LAST) AS WritingScoreRank FROM schools AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T2.AvgScrWrite > 499 AND NOT CharterNum IS NULL", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "List the names of schools with more than 30 difference in enrollements between K-12 and ages 5-17? Please also give the full street adress of the schools.", "sql": "SELECT T1.School, T1.Street FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.\"Enrollment (K-12)\" - T2.\"Enrollment (Ages 5-17)\" > 30", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Give the names of the schools with the percent eligible for free meals in K-12 is more than 0.1 and test takers whose test score is greater than or equal to 1500?", "sql": "SELECT T2.\"School Name\" FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE CAST(T2.\"Free Meal Count (K-12)\" AS REAL) / NULLIF(T2.\"Enrollment (K-12)\", 0) > 0.1 AND T1.NumGE1500 > 0", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Name schools in Riverside which the average of average math score for SAT is grater than 400, what is the funding type of these schools?", "sql": "SELECT T1.sname, T2.\"Charter Funding Type\" FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE T2.\"District Name\" LIKE 'Riverside%' GROUP BY T1.sname, T2.\"Charter Funding Type\" HAVING CAST(SUM(T1.AvgScrMath) AS REAL) / NULLIF(COUNT(T1.cds), 0) > 400", "complexity_score": 0.07100000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "State the names and full communication address of high schools in Monterey which has more than 800 free or reduced price meals for ages 15-17?", "sql": "SELECT T1.\"School Name\", T2.Street, T2.City, T2.State, T2.Zip FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Monterey' AND T1.\"Free Meal Count (Ages 5-17)\" > 800 AND T1.\"School Type\" = 'High Schools (Public)'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the average score in writing for the schools that were opened after 1991 or closed before 2000? List the school names along with the score. Also, list the communication number of the schools if there is any.", "sql": "SELECT T2.School, T1.AvgScrWrite, T2.Phone FROM schools AS T2 LEFT JOIN satscores AS T1 ON T2.CDSCode = T1.cds WHERE TO_CHAR(CAST(T2.OpenDate AS TIMESTAMP), 'YYYY') > '1991' OR TO_CHAR(CAST(T2.ClosedDate AS TIMESTAMP), 'YYYY') < '2000'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-WHERE", "clauses_present": ["FROM", "JOIN", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Consider the average difference between K-12 enrollment and 15-17 enrollment of schools that are locally funded, list the names and DOC type of schools which has a difference above this average.", "sql": "SELECT T2.School, T2.DOC FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.FundingType = 'Locally funded' AND (T1.\"Enrollment (K-12)\" - T1.\"Enrollment (Ages 5-17)\") > (SELECT AVG(T3.\"Enrollment (K-12)\" - T3.\"Enrollment (Ages 5-17)\") FROM frpm AS T3 INNER JOIN schools AS T4 ON T3.CDSCode = T4.CDSCode WHERE T4.FundingType = 'Locally funded')", "complexity_score": 0.17600000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the eligible free rate of the 10th and 11th schools with the highest enrolment for students in grades 1 through 12?", "sql": "SELECT CAST(\"Free Meal Count (K-12)\" AS REAL) / NULLIF(\"Enrollment (K-12)\", 0) FROM frpm ORDER BY \"Enrollment (K-12)\" DESC NULLS LAST LIMIT 2 OFFSET 9", "complexity_score": 0.010000000000000002, "pattern_signature": "SELECT-FROM-ORDER-LIMIT-OFFSET", "clauses_present": ["FROM", "LIMIT", "OFFSET", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the eligible free or reduced price meal rate for the top 5 schools in grades 1-12 with the highest free or reduced price meal count of the schools with the ownership code 66?", "sql": "SELECT CAST(T1.\"FRPM Count (K-12)\" AS REAL) / NULLIF(T1.\"Enrollment (K-12)\", 0) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.SOC::integer = 66 ORDER BY T1.\"FRPM Count (K-12)\" DESC NULLS LAST LIMIT 5", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the complete address of the school with the lowest excellence rate? Indicate the Street, City, Zip and State.", "sql": "SELECT T2.Street, T2.City, T2.State, T2.Zip FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY CAST(T1.NumGE1500 AS REAL) / NULLIF(T1.NumTstTakr, 0) ASC NULLS FIRST LIMIT 1", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Under whose administration is the school with the highest number of students scoring 1500 or more on the SAT? Indicate their full names.", "sql": "SELECT T2.AdmFName1, T2.AdmLName1, T2.AdmFName2, T2.AdmLName2, T2.AdmFName3, T2.AdmLName3 FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.NumGE1500 DESC NULLS LAST LIMIT 1", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the average number of test takers from Fresno schools that opened between 1/1/1980 and 12/31/1980?", "sql": "SELECT AVG(T1.NumTstTakr) FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE TO_CHAR(CAST(T2.OpenDate AS TIMESTAMP), 'YYYY') = '1980' AND T2.County = 'Fresno'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the telephone number for the school with the lowest average score in reading in Fresno Unified?", "sql": "SELECT T2.Phone FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.District = 'Fresno Unified' AND NOT T1.AvgScrRead IS NULL ORDER BY T1.AvgScrRead ASC NULLS FIRST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "List the names of virtual schools that are among the top 5 in their respective counties based on average reading scores.", "sql": "SELECT School FROM (SELECT T2.School, T1.AvgScrRead, RANK() OVER (PARTITION BY T2.County ORDER BY T1.AvgScrRead DESC NULLS LAST) AS rnk FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.Virtual = 'F') AS ranked_schools WHERE rnk <= 5", "complexity_score": 0.14100000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "SUBQUERY", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the average writing score of each of the schools managed by Ricci Ulrich? List the schools and the corresponding average writing scores.", "sql": "SELECT T2.School, T1.AvgScrWrite FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.AdmFName1 = 'Ricci' AND T2.AdmLName1 = 'Ulrich'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Which state special schools have the highest number of enrollees from grades 1 through 12?", "sql": "SELECT T2.School FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.DOC = '31' ORDER BY T1.\"Enrollment (K-12)\" DESC LIMIT 1", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the monthly average number of schools that opened in Alameda County under the jurisdiction of the Elementary School District in 1980?", "sql": "SELECT CAST(COUNT(School) AS REAL) / NULLIF(12, 0) FROM schools WHERE DOC = '52' AND County = 'Alameda' AND EXTRACT(YEAR FROM OpenDate) = 1980", "complexity_score": 0.043000000000000003, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the ratio of merged Unified School District schools in Orange County to merged Elementary School District schools?", "sql": "SELECT CAST(SUM(CASE WHEN DOC::integer = 54 THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN DOC::integer = 52 THEN 1 ELSE 0 END), 0) FROM schools WHERE StatusType = 'Merged' AND County = 'Orange'", "complexity_score": 0.03900000000000001, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the postal street address for the school with the 7th highest Math average? Indicate the school's name.", "sql": "SELECT T2.MailStreet, T2.School FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.AvgScrMath DESC NULLS LAST LIMIT 1 OFFSET 6", "complexity_score": 0.045000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT-OFFSET", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "OFFSET", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the total number of non-chartered schools in the county of Los Angeles with a percent (%) of eligible free meals for grades 1 through 12 that is less than 0.18%?", "sql": "SELECT COUNT(T2.School) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Los Angeles' AND T2.Charter = 0 AND CAST(T1.\"Free Meal Count (K-12)\" AS REAL) * 100 / NULLIF(T1.\"Enrollment (K-12)\", 0) < 0.18", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "How many students from the ages of 5 to 17 are enrolled at the State Special School school in Fremont for the 2014-2015 academic year?", "sql": "SELECT T1.\"Enrollment (Ages 5-17)\" FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.EdOpsCode = 'SSS' AND T2.City = 'Fremont' AND T1.\"Academic Year\" = '2014-2015'", "complexity_score": 0.07200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Which schools served a grade span of Kindergarten to 9th grade in the county of Los Angeles and what is its Percent (%) Eligible FRPM (Ages 5-17)?", "sql": "SELECT T2.School, T1.\"FRPM Count (Ages 5-17)\" * 100 / NULLIF(T1.\"Enrollment (Ages 5-17)\", 0) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Los Angeles' AND T2.GSserved = 'K-9'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Between San Diego and Santa Barbara, which county offers the most number of schools that does not offer physical building? Indicate the amount.", "sql": "SELECT County, COUNT(Virtual) FROM schools WHERE (County = 'San Diego' OR County = 'Santa Barbara') AND Virtual = 'F' GROUP BY County ORDER BY COUNT(Virtual) DESC NULLS LAST LIMIT 1", "complexity_score": 0.049, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the grade span offered in the school with the highest longitude?", "sql": "SELECT GSoffered FROM schools ORDER BY ABS(longitude) DESC NULLS LAST LIMIT 1", "complexity_score": 0.010000000000000002, "pattern_signature": "SELECT-FROM-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "Of the schools that offers a magnet program serving a grade span of Kindergarten to 8th grade, how many offers Multiple Provision Types? List the number of cities that offers a Kindergarten to 8th grade span and indicate how many schools are there serving such grade span for each city.", "sql": "SELECT T2.City, COUNT(T2.CDSCode) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.Magnet = 1 AND T2.GSoffered = 'K-8' AND T1.\"NSLP Provision Status\" = 'Multiple Provision Types' GROUP BY T2.City", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What is the Percent (%) Eligible Free (K-12) in the school administered by an administrator whose first name is Alusine. List the district code of the school.", "sql": "SELECT T1.\"Free Meal Count (K-12)\" * 100 / NULLIF(T1.\"Enrollment (K-12)\", 0), T1.\"District Code\" FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.AdmFName1 = 'Alusine'", "complexity_score": 0.052000000000000005, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "california_schools", "intent": "What are the valid e-mail addresses of the administrator of the school located in the San Bernardino county, City of San Bernardino City Unified that opened between 1/1/2009 to 12/31/2010 whose school types are public Intermediate/Middle Schools and Unified Schools?", "sql": "SELECT T2.AdmEmail1, T2.AdmEmail2 FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'San Bernardino' AND T2.City = 'San Bernardino' AND T2.DOC::integer = 54 AND EXTRACT(YEAR FROM T2.OpenDate) BETWEEN 2009 AND 2010 AND T2.SOC::integer = 62", "complexity_score": 0.09200000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "How many accounts who choose issuance after transaction are staying in East Bohemia region?", "sql": "SELECT COUNT(T2.account_id) FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id WHERE T1.A3 = 'east Bohemia' AND T2.frequency = 'POPLATEK PO OBRATU'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "List out the no. of districts that have female average salary is more than 6000 but less than 10000?", "sql": "SELECT COUNT(DISTINCT T2.district_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'F' AND T2.A11 BETWEEN 6000 AND 10000", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "How many male customers who are living in North Bohemia have average salary greater than 8000?", "sql": "SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'M' AND T2.A3 = 'north Bohemia' AND T2.A11 > 8000", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "List out the account numbers of female clients who are oldest and has lowest average salary, calculate the gap between this lowest average salary with the highest average salary?", "sql": "SELECT T1.account_id, (SELECT MAX(A11) - MIN(A11) FROM district) FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T1.account_id = T3.account_id INNER JOIN client AS T4 ON T3.client_id = T4.client_id WHERE T2.district_id = (SELECT district_id FROM client WHERE gender = 'F' ORDER BY birth_date ASC NULLS FIRST LIMIT 1) ORDER BY T2.A11 DESC NULLS LAST LIMIT 1", "complexity_score": 0.24900000000000003, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 3, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "List out the account numbers of clients who are youngest and have highest average salary?", "sql": "SELECT T1.account_id FROM account AS T1 INNER JOIN disp AS T2 ON T1.account_id = T2.account_id INNER JOIN client AS T3 ON T2.client_id = T3.client_id INNER JOIN district AS T4 ON T4.district_id = T1.district_id WHERE T2.client_id = (SELECT client_id FROM client ORDER BY birth_date DESC NULLS LAST LIMIT 1) GROUP BY T4.A11, T1.account_id", "complexity_score": 0.198, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 3, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Among the accounts who have approved loan date in 1997, list out the accounts that have the lowest approved amount and choose weekly issuance statement.", "sql": "SELECT T2.account_id FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1997' AND T2.frequency = 'POPLATEK TYDNE' ORDER BY T1.amount NULLS FIRST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Among the accounts who have loan validity more than 12 months, list out the accounts that have the highest approved amount and have account opening date in 1993.", "sql": "SELECT T1.account_id FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T2.date AS TIMESTAMP), 'YYYY') = '1993' AND T1.duration > 12 ORDER BY T1.amount DESC NULLS LAST LIMIT 1", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Among the account opened, how many female customers who were born before 1950 and stayed in Sokolov?", "sql": "SELECT COUNT(T2.client_id) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T2.gender = 'F' AND TO_CHAR(CAST(T2.birth_date AS TIMESTAMP), 'YYYY') < '1950' AND T1.A2 = 'Sokolov'", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For the female client who was born in 1976/1/29, which district did she opened her account?", "sql": "SELECT T1.A2 FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T2.birth_date = '1976-01-29' AND T2.gender = 'F'", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For the branch which located in the south Bohemia with biggest number of inhabitants, what is the percentage of the male clients?", "sql": "SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.client_id), 0) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'south Bohemia' GROUP BY T2.A4 ORDER BY T2.A4 DESC LIMIT 1", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For the client whose loan was approved first in 1993/7/5, what is the increase rate of his/her account balance from 1993/3/22 to 1998/12/27?", "sql": "SELECT CAST((SUM(CASE WHEN T3.date = '1998-12-27' THEN T3.balance ELSE 0 END) - SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END), 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN trans AS T3 ON T3.account_id = T2.account_id WHERE T1.date = '1993-07-05'", "complexity_score": 0.105, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What is the percentage of loan amount that has been fully paid with no issue.", "sql": "SELECT (CAST(SUM(CASE WHEN status = 'A' THEN amount ELSE 0 END) AS REAL) * 100) / NULLIF(SUM(amount), 0) FROM loan", "complexity_score": 0.022000000000000002, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For loan amount less than USD100,000, what is the percentage of accounts that is still running with no issue.", "sql": "SELECT CAST(SUM(CASE WHEN status = 'C' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(account_id), 0) FROM loan WHERE amount < 100000", "complexity_score": 0.029, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For loans contracts which are still running where client are in debt, list the district of the and the state the percentage unemployment rate increment from year 1995 to 1996.", "sql": "SELECT CAST((T3.A13 - T3.A12) AS REAL) * 100 / NULLIF(T3.A12, 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN district AS T3 ON T2.district_id = T3.district_id WHERE T1.status = 'D'", "complexity_score": 0.087, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "List the top nine districts, by descending order, from the highest to the lowest, the number of female account holders.", "sql": "SELECT T2.A2, COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'F' GROUP BY T2.district_id, T2.A2 ORDER BY COUNT(T1.client_id) DESC NULLS LAST LIMIT 9", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Between 1/1/1995 and 12/31/1997, how many loans in the amount of at least 250,000 per account that chose monthly statement issuance were approved?", "sql": "SELECT COUNT(T1.account_id) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.date BETWEEN '1995-01-01' AND '1997-12-31' AND T1.frequency = 'POPLATEK MESICNE' AND T2.amount >= 250000", "complexity_score": 0.07800000000000001, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "How many accounts have running contracts in Branch location 1?", "sql": "SELECT COUNT(T1.account_id) FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN loan AS T3 ON T1.account_id = T3.account_id WHERE T1.district_id = 1 AND (T3.status = 'C' OR T3.status = 'D')", "complexity_score": 0.113, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "In the branch where the second-highest number of crimes were committed in 1995 occurred, how many male clients are there?", "sql": "SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'M' AND T2.A15 = (SELECT T3.A15 FROM district AS T3 ORDER BY T3.A15 DESC NULLS LAST LIMIT 1 OFFSET 1)", "complexity_score": 0.14400000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-OFFSET-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "OFFSET", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Which are the top ten withdrawals (non-credit card) by district names for the month of January 1996?", "sql": "SELECT DISTINCT T1.A2 FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN trans AS T3 ON T2.account_id = T3.account_id WHERE T3.type = 'VYDAJ' AND CAST(T3.date AS TEXT) LIKE '1996-01%' ORDER BY T1.A2 ASC LIMIT 10", "complexity_score": 0.097, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Who are the account holder identification numbers whose who have transactions on the credit card with the amount is less than the average, in 1998?", "sql": "SELECT T1.account_id FROM trans AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1998' AND T1.operation = 'VYBER KARTOU' AND T1.amount < (SELECT AVG(amount) FROM trans WHERE TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') = '1998')", "complexity_score": 0.16100000000000003, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Please list the account types that are not eligible for loans, and the average income of residents in the district where the account is located exceeds $8000 but is no more than $9000.", "sql": "SELECT T3.type FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T2.account_id = T3.account_id WHERE T3.type <> 'OWNER' AND T1.A11 BETWEEN 8000 AND 9000", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What is the average number of crimes committed in 1995 in regions where the number exceeds 4000 and the region has accounts that are opened starting from the year 1997?", "sql": "SELECT AVG(T1.A15) FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id WHERE TO_CHAR(CAST(T2.date AS TIMESTAMP), 'YYYY') >= '1997' AND T1.A15 > 4000", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "List all the withdrawals in cash transactions that the client with the id 3356 makes.", "sql": "SELECT T4.trans_id FROM client AS T1 INNER JOIN disp AS T2 ON T1.client_id = T2.client_id INNER JOIN account AS T3 ON T2.account_id = T3.account_id INNER JOIN trans AS T4 ON T3.account_id = T4.account_id WHERE T1.client_id = 3356 AND T4.operation = 'VYBER'", "complexity_score": 0.132, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What percentage of clients who opened their accounts in the district with an average salary of over 10000 are women?", "sql": "SELECT CAST(SUM(CASE WHEN T2.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.client_id), 0) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T1.A11 > 10000", "complexity_score": 0.064, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What was the growth rate of the total amount of loans across all accounts for a male client between 1996 and 1997?", "sql": "SELECT CAST((SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1997' THEN T1.amount ELSE 0 END) - SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1996' THEN T1.amount ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1996' THEN T1.amount ELSE 0 END), 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN disp AS T3 ON T3.account_id = T2.account_id INNER JOIN client AS T4 ON T4.client_id = T3.client_id WHERE T4.gender = 'M' AND T3.type = 'OWNER'", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "How often does account number 3 request an account statement to be released? What was the aim of debiting 3539 in total?", "sql": "SELECT T1.frequency, T2.k_symbol FROM account AS T1 INNER JOIN (SELECT account_id, k_symbol, SUM(amount) AS total_amount FROM \"order\" GROUP BY account_id, k_symbol) AS T2 ON T1.account_id = T2.account_id WHERE T1.account_id = 3 AND T2.total_amount = 3539", "complexity_score": 0.14400000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What percentage of male clients request for weekly statements to be issued?", "sql": "SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.client_id), 0) FROM client AS T1 INNER JOIN district AS T3 ON T1.district_id = T3.district_id INNER JOIN account AS T2 ON T2.district_id = T3.district_id INNER JOIN disp AS T4 ON T1.client_id = T4.client_id AND T2.account_id = T4.account_id WHERE T2.frequency = 'POPLATEK TYDNE'", "complexity_score": 0.14400000000000002, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Name the account numbers of female clients who are oldest and have lowest average salary?", "sql": "SELECT T3.account_id FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN account AS T3 ON T2.district_id = T3.district_id INNER JOIN disp AS T4 ON T1.client_id = T4.client_id AND T4.account_id = T3.account_id WHERE T1.gender = 'F' ORDER BY T1.birth_date ASC NULLS FIRST, T2.A11 ASC NULLS FIRST LIMIT 1", "complexity_score": 0.132, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "What is the average amount of loan which are still on running contract with statement issuance after each transaction?", "sql": "SELECT AVG(T2.amount) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.status IN ('C', 'D') AND T1.frequency = 'POPLATEK PO OBRATU'", "complexity_score": 0.068, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "Provide the IDs and age of the client with high level credit card, which is eligible for loans.", "sql": "SELECT T1.client_id, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T3.birth_date) AS age FROM disp AS T1 INNER JOIN card AS T2 ON T2.disp_id = T1.disp_id INNER JOIN client AS T3 ON T1.client_id = T3.client_id WHERE T2.type = 'gold' AND T1.type = 'OWNER'", "complexity_score": 0.097, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "For accounts in 1993 with statement issued after transaction, list the account ID, district name and district region.", "sql": "SELECT T1.account_id, T2.A2, T2.A3 FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.frequency = 'POPLATEK PO OBRATU' AND EXTRACT(YEAR FROM T1.date) = 1993", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} -{"db_id": "financial", "intent": "From Year 1995 to 2000, who are the accounts holders from 'east Bohemia'. State the account ID the frequency of statement issuance.", "sql": "SELECT T1.account_id, T1.frequency FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'east Bohemia' AND EXTRACT(YEAR FROM T1.date) BETWEEN 1995 AND 2000", "complexity_score": 0.062000000000000006, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the ratio of customers who pay in EUR against customers who pay in CZK?", "sql": "SELECT CAST(SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END), 0) FROM customers", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "In 2012, who had the least consumption in LAM?", "sql": "SELECT T1.CustomerID FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM' AND SUBSTR(T2.Date, 1, 4) = '2012' GROUP BY T1.CustomerID ORDER BY SUM(T2.Consumption) ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What was the average monthly consumption of customers in SME for the year 2013?", "sql": "SELECT AVG(T2.Consumption) / NULLIF(12, 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What was the difference in gas consumption between CZK-paying customers and EUR-paying customers in 2012?", "sql": "SELECT SUM(CASE WHEN T1.Currency = 'CZK' THEN CAST(T2.Consumption AS float) ELSE 0 END) -SUM(CASE WHEN T1.Currency = 'EUR' THEN CAST(T2.Consumption AS float) ELSE 0 END) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE substring(T2.Date, 1, 4) = '2012'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Which year recorded the most consumption of gas paid in CZK?", "sql": "SELECT SUBSTR(T2.Date, 1, 4) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' GROUP BY SUBSTR(T2.Date, 1, 4) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What was the gas consumption peak month for SME customers in 2013?", "sql": "SELECT SUBSTR(T2.Date, 5, 2) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME' GROUP BY SUBSTR(T2.Date, 5, 2) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the difference in the annual average consumption of the customers with the least amount of consumption paid in CZK for 2013 between SME and LAM, LAM and KAM, and KAM and SME?", "sql": "SELECT CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' AND T2.Consumption = (SELECT MIN(Consumption) FROM yearmonth) AND T2.Date::text BETWEEN '201301' AND '201312'", "complexity_score": 0.2167, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 13, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Which of the three segments\u2014SME, LAM and KAM\u2014has the biggest and lowest percentage increases in consumption paid in EUR between 2012 and 2013?", "sql": "SELECT CAST((SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID", "complexity_score": 0.1969, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 9, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "How much did customer 6 consume in total between August and November 2013?", "sql": "SELECT SUM(Consumption) FROM yearmonth WHERE CustomerID = 6 AND Date BETWEEN '201308' AND '201311'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "How many more \"discount\" gas stations does the Czech Republic have compared to Slovakia?", "sql": "SELECT SUM(CASE WHEN Country = 'CZE' THEN 1 ELSE 0 END) - SUM(CASE WHEN Country = 'SVK' THEN 1 ELSE 0 END) FROM gasstations WHERE Segment = 'Discount'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Is it true that more SMEs pay in Czech koruna than in euros? If so, how many more?", "sql": "SELECT SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END) - SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) FROM customers WHERE Segment = 'SME'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "How many percent of LAM customer consumed more than 46.73?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Consumption > 46.73 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "In February 2012, what percentage of customers consumed more than 528.3?", "sql": "SELECT CAST(SUM(CASE WHEN Consumption > 528.3 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(CustomerID), 0) FROM yearmonth WHERE Date = '201202'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the highest monthly consumption in the year 2012?", "sql": "SELECT SUM(CAST(Consumption AS float)) FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2012' GROUP BY SUBSTR(Date, 5, 2) ORDER BY SUM(Consumption) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Please list the product description of the products consumed in September, 2013.", "sql": "SELECT T3.Description FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Date = '201309'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Please list the countries of the gas stations with transactions taken place in June, 2013.", "sql": "SELECT DISTINCT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN yearmonth AS T3 ON T1.CustomerID = T3.CustomerID WHERE T3.Date = '201306'", "complexity_score": 0.0906, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Among the customers who paid in euro, how many of them have a monthly consumption of over 1000?", "sql": "SELECT COUNT(*) FROM yearmonth AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.Currency = 'EUR' AND T1.Consumption > 1000.00", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Please list the product descriptions of the transactions taken place in the gas stations in the Czech Republic.", "sql": "SELECT DISTINCT T3.Description FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Country = 'CZE'", "complexity_score": 0.0906, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Please list the disparate time of the transactions taken place in the gas stations from chain no. 11.", "sql": "SELECT DISTINCT T1.Time FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.ChainID = 11", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Among the transactions made in the gas stations in the Czech Republic, how many of them are taken place after 2012/1/1?", "sql": "SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.Country = 'CZE' AND TO_CHAR(CAST(T1.Date AS TIMESTAMP), 'YYYY') >= '2012'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What kind of currency did the customer paid at 16:25:00 in 2012/8/24?", "sql": "SELECT DISTINCT T3.Currency FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN customers AS T3 ON T1.CustomerID = T3.CustomerID WHERE T1.Date = '2012-08-24' AND T1.Time = '16:25:00'", "complexity_score": 0.101, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What segment did the customer have at 2012/8/23 21:20:00?", "sql": "SELECT T2.Segment FROM transactions_1k AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.date = '2012-08-23' AND T1.time = '21:20:00'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "For all the transactions happened during 8:00-9:00 in 2012/8/26, how many happened in CZE?", "sql": "SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-26' AND T1.Time BETWEEN '08:00:00' AND '09:00:00' AND T2.Country = 'CZE'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What's the nationality of the customer who spent 548.4 in 2012/8/24?", "sql": "SELECT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-24' AND T1.Price = '548.4'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the percentage of the customers who used EUR in 2012/8/25?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Currency = 'EUR' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.CustomerID), 0) FROM transactions_1k AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Date = '2012-08-25'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "For the customer who paid 634.8 in 2012/8/25, what was the consumption decrease rate from Year 2012 to 2013?", "sql": "SELECT CAST(SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2012' THEN Consumption ELSE 0 END) - SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2013' THEN Consumption ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN SUBSTR(Date, 1, 4) = '2012' THEN Consumption ELSE 0 END), 0) FROM yearmonth WHERE CustomerID = (SELECT T1.CustomerID FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-25' AND T1.Price = 1513.12 )", "complexity_score": 0.1802, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the percentage of \"premium\" against the overall segment in Country = \"SVK\"?", "sql": "SELECT CAST(SUM(CASE WHEN Country = 'SVK' AND Segment = 'Premium' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Country = 'SVK' THEN 1 ELSE 0 END), 0) FROM gasstations", "complexity_score": 0.0333, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "What is the amount spent by customer \"38508\" at the gas stations? How much had the customer spent in January 2012?", "sql": "SELECT SUM(T1.Price ), SUM(CASE WHEN T3.Date = '201201' THEN T1.Price ELSE 0 END) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN yearmonth AS T3 ON T1.CustomerID = T3.CustomerID WHERE T1.CustomerID = '38508'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "Who is the top spending customer and how much is the average price per single item purchased by this customer? What currency was being used?", "sql": "SELECT T2.CustomerID, SUM(T2.Price / NULLIF(T2.Amount, 0)), T1.Currency FROM customers AS T1 INNER JOIN transactions_1k AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.CustomerID = (SELECT CustomerID FROM yearmonth ORDER BY Consumption DESC NULLS LAST LIMIT 1) GROUP BY T2.CustomerID, T1.Currency", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "debit_card_specializing", "intent": "For all the people who paid more than 29.00 per unit of product id No.5. Give their consumption status in the August of 2012.", "sql": "SELECT T2.Consumption FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Price / NULLIF(T1.Amount, 0) > 29.00 AND T1.ProductID = 5 AND T2.Date = '201208'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What's Angela Sanders's major?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.first_name = 'Angela' AND T1.last_name = 'Sanders'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Among the students from the Student_Club who attended the event \"Women's Soccer\", how many of them want a T-shirt that's in medium size?", "sql": "SELECT COUNT(T1.event_id) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event INNER JOIN member AS T3 ON T2.link_to_member = T3.member_id WHERE T1.event_name = 'Women''s Soccer' AND T3.t_shirt_size = 'Medium'", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Among the events attended by more than 10 members of the Student_Club, how many of them are meetings?", "sql": "SELECT COUNT(DISTINCT T1.event_id) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event WHERE T1.type = 'Meeting' GROUP BY T1.event_id HAVING COUNT(T2.link_to_event) > 10", "complexity_score": 0.074, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List all the names of events that had an attendance of over 20 students but were not fundraisers.", "sql": "SELECT T1.event_name FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event GROUP BY T1.event_id HAVING COUNT(T2.link_to_event) > 20 EXCEPT SELECT T1.event_name FROM event AS T1 WHERE T1.type = 'Fundraiser'", "complexity_score": 0.0677, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-EXCEPT", "clauses_present": ["EXCEPT", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What is the amount of the funds that the Vice President received?", "sql": "SELECT T2.amount FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Vice President'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List the full name of the Student_Club members that grew up in Illinois state.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN zip_code AS T2 ON T1.zip = T2.zip_code WHERE T2.state = 'Illinois'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Was each expense in October Meeting on October 8, 2019 approved?", "sql": "SELECT T3.approved FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' AND T1.event_date LIKE '2019-10-08%'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Calculate the total average cost that Elijah Allen spent in the events on September and October.", "sql": "SELECT AVG(T2.cost) FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.last_name = 'Allen' AND T1.first_name = 'Elijah' AND (SUBSTR(T2.expense_date, 6, 2) = '09' OR SUBSTR(T2.expense_date, 6, 2) = '10')", "complexity_score": 0.0917, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Calculate the difference of the total amount spent in all events by the Student_Club in year 2019 and 2020.", "sql": "SELECT SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2019' THEN T2.spent ELSE 0 END) - SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2020' THEN T2.spent ELSE 0 END) AS num FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What was the notes of the fundraising on 2019/9/14?", "sql": "SELECT notes FROM income WHERE source = 'Fundraising' AND date_received = '2019-09-14'", "complexity_score": 0.0281, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Tell the phone number of \"Carlo Jacobs\".", "sql": "SELECT phone FROM member WHERE first_name = 'Carlo' AND last_name = 'Jacobs'", "complexity_score": 0.0281, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What is the status of the event which bought \"Post Cards, Posters\" on 2019/8/20?", "sql": "SELECT T1.event_status FROM budget AS T1 INNER JOIN expense AS T2 ON T1.budget_id = T2.link_to_budget WHERE T2.expense_description = 'Post Cards, Posters' AND T2.expense_date = '2019-08-20'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What was Brent Thomason's major?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.first_name = 'Brent' AND T1.last_name = 'Thomason'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "For all the club members from \"Business\" major, how many of them wear medium size t-shirt?", "sql": "SELECT COUNT(T1.member_id) FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T2.major_name = 'Business' AND T1.t_shirt_size = 'Medium'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Which department was the President of the club in?", "sql": "SELECT T2.department FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.position = 'President'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "State the date Connor Hilton paid his/her dues.", "sql": "SELECT T2.date_received FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Connor' AND T1.last_name = 'Hilton' AND T2.source = 'Dues'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "How many times was the budget in Advertisement for \"Yearly Kickoff\" meeting more than \"October Meeting\"?", "sql": "SELECT CAST(SUM(CASE WHEN T2.event_name = 'Yearly Kickoff' THEN T1.amount ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN T2.event_name = 'October Meeting' THEN T1.amount ELSE 0 END), 0) FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' AND T2.type = 'Meeting'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What is the total cost of the pizzas for all the events?", "sql": "SELECT SUM(cost) FROM expense WHERE expense_description = 'Pizza'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "How many cities are there in Orange County, Virginia?", "sql": "SELECT COUNT(city) FROM zip_code WHERE county = 'Orange County' AND state = 'Virginia'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What does the person with the phone number \"809-555-3360\" major in?", "sql": "SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.phone = '809-555-3360'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "How many members attended the \"Women's Soccer\" event?", "sql": "SELECT COUNT(T2.link_to_member) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'Women''s Soccer'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List all the members of the \"School of Applied Sciences, Technology and Education\" department.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T2.department = 'School of Applied Sciences, Technology and Education'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Among all the closed events, which event has the highest spend-to-budget ratio?", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T2.status = 'Closed' ORDER BY T1.spent / NULLIF(T1.amount, 0) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What is the highest amount of budget spend for an event?", "sql": "SELECT MAX(spent) FROM budget", "complexity_score": 0.0167, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What is the total amount of money spent for food?", "sql": "SELECT SUM(spent) FROM budget WHERE category = 'Food'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List the name of students that have attended more than 7 events.", "sql": "SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN attendance AS T2 ON T1.member_id = T2.link_to_member GROUP BY T1.member_id, T1.first_name, T1.last_name HAVING COUNT(T2.link_to_event) > 7", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Which student has been entrusted to manage the budget for the Yearly Kickoff?", "sql": "SELECT T4.first_name, T4.last_name FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget INNER JOIN member AS T4 ON T3.link_to_member = T4.member_id WHERE T1.event_name = 'Yearly Kickoff'", "complexity_score": 0.1271, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Which event has the lowest cost?", "sql": "SELECT T1.event_name FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget ORDER BY T3.cost NULLS FIRST LIMIT 1", "complexity_score": 0.0833, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Based on the total cost for all event, what is the percentage of cost for Yearly Kickoff event?", "sql": "SELECT CAST(SUM(CASE WHEN T1.event_name = 'Yearly Kickoff' THEN T3.cost ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(T3.cost), 0) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget", "complexity_score": 0.0958, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Indicate the top source of funds received in September 2019 based on their amount.", "sql": "SELECT source FROM income WHERE date_received BETWEEN '2019-09-01' AND '2019-09-30' ORDER BY source DESC NULLS LAST LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "How many members of the Student_Club have major in 'Physics Teaching'?", "sql": "SELECT COUNT(T2.member_id) FROM major AS T1 INNER JOIN member AS T2 ON T1.major_id = T2.link_to_major WHERE T1.major_name = 'Physics Teaching'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Name the event with the highest amount spent on advertisement.", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' ORDER BY T1.spent DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Did Maya Mclean attend the 'Women's Soccer' event?", "sql": "SELECT CASE WHEN T3.event_name = 'Women''s Soccer' THEN 'YES' END AS result FROM member AS T1 INNER JOIN attendance AS T2 ON T1.member_id = T2.link_to_member INNER JOIN event AS T3 ON T2.link_to_event = T3.event_id WHERE T1.first_name = 'Maya' AND T1.last_name = 'Mclean'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Indicate the cost of posters for 'September Speaker' event.", "sql": "SELECT T3.cost FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'September Speaker' AND T3.expense_description = 'Posters'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Indicate the name of the closed event whose cost has exceeded the budget the most.", "sql": "SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T2.event_id = T1.link_to_event WHERE T1.event_status = 'Closed' AND T1.remaining < 0 ORDER BY T1.remaining NULLS FIRST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Identify the type of expenses and their total value approved for 'October Meeting' event.", "sql": "SELECT T1.type, SUM(T3.cost) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' GROUP BY T1.type", "complexity_score": 0.0969, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Calculate the amount budgeted for 'April Speaker' event. List all the budgeted categories for said event in an ascending order based on their amount budgeted.", "sql": "SELECT T2.category, SUM(T2.amount) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'April Speaker' GROUP BY T2.category ORDER BY SUM(T2.amount) ASC", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Mention the total expense used on 8/20/2019.", "sql": "SELECT SUM(cost) FROM expense WHERE expense_date = '2019-08-20'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List out the full name and total cost that member id \"rec4BLdZHS2Blfp4v\" incurred?", "sql": "SELECT T1.first_name, T1.last_name, SUM(T2.cost) FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.member_id = 'rec4BLdZHS2Blfp4v' GROUP BY T1.first_name, T1.last_name", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "State what kind of expenses that Sacha Harrison incurred?", "sql": "SELECT T2.expense_description FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Sacha' AND T1.last_name = 'Harrison'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "State the category of events were held at MU 215.", "sql": "SELECT DISTINCT T2.category FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.location = 'MU 215'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List the last name of members with a major in environmental engineering and include its department and college name.", "sql": "SELECT T2.last_name, T1.department, T1.college FROM major AS T1 INNER JOIN member AS T2 ON T1.major_id = T2.link_to_major WHERE T2.position = 'Member' AND T1.major_name = 'Environmental Engineering'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "What are the budget category of the events located at MU 215 and a guest speaker type with a 0 budget spent?", "sql": "SELECT DISTINCT T2.category, T1.type FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.location = 'MU 215' AND T2.spent = 0 AND T1.type = 'Guest Speaker'", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Among the members with t-shirt size of medium, what is the percentage of the amount 50 received by the Student_Club?", "sql": "SELECT CAST(SUM(CASE WHEN T2.amount = 50 THEN 1.0 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.income_id), 0) FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Member' AND T1.t_shirt_size = 'Medium'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "List the names of closed event as \"game\" that was closed from 3/15/2019 to 3/20/2020.", "sql": "SELECT DISTINCT event_name FROM event WHERE type = 'Game' AND DATE(SUBSTR(event_date, 1, 10)) BETWEEN '2019-03-15' AND '2020-03-20' AND status = 'Closed'", "complexity_score": 0.0385, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Give the full name and contact number of members who had to spend more than average on each expense.", "sql": "SELECT DISTINCT T3.first_name, T3.last_name, T3.phone FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member WHERE T1.cost > (SELECT AVG(T1.cost) FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member)", "complexity_score": 0.2281, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 4, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Write the full name of the member who spent money for water, veggie tray and supplies and include the cost of it.", "sql": "SELECT T2.first_name, T2.last_name, T1.cost FROM expense AS T1 INNER JOIN member AS T2 ON T1.link_to_member = T2.member_id WHERE T1.expense_description = 'Water, Veggie tray, supplies'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "student_club", "intent": "Write the full names of students who received funds on the date of 9/9/2019 and include the amount received.", "sql": "SELECT DISTINCT T3.first_name, T3.last_name, T4.amount FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event INNER JOIN member AS T3 ON T3.member_id = T2.link_to_member INNER JOIN income AS T4 ON T4.link_to_member = T3.member_id WHERE T4.date_received = '2019-09-09'", "complexity_score": 0.1271, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Are there more in-patient or outpatient who were male? What is the deviation in percentage?", "sql": "SELECT CAST(SUM(CASE WHEN Admission = '+' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE SEX = 'M'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the percentage of female patient were born after 1930?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') > '1930' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM Patient WHERE SEX = 'F'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the ratio of outpatient to inpatient followed up treatment among all the 'SLE' diagnosed patient?", "sql": "SELECT SUM(CASE WHEN Admission = '+' THEN 1.0 ELSE 0 END) / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE Diagnosis = 'SLE'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the disease patient '30609' diagnosed with. List all the date of laboratory tests done for this patient.", "sql": "SELECT T1.Diagnosis, T2.Date FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID = 30609", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "List the patient ID, sex and birthday of patient with LDH beyond normal range.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.LDH > 500", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "State the ID and age of patient with positive degree of coagulation.", "sql": "SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.RVVT = '+'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For patients with severe degree of thrombosis, list their ID, sex and disease the patient is diagnosed with.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.Thrombosis = 2", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many female patients who came at the hospital in 1997 was immediately followed at the outpatient clinic?", "sql": "SELECT COUNT(*) FROM Patient WHERE TO_CHAR(CAST(Description AS TIMESTAMP), 'YYYY') = '1997' AND SEX = 'F' AND Admission = '-'", "complexity_score": 0.0448, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many of the patients with the most serious thrombosis cases examined in 1997 are women?", "sql": "SELECT COUNT(*) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND TO_CHAR(CAST(T2.\"Examination Date\" AS TIMESTAMP), 'YYYY') = '1997' AND T2.Thrombosis = 1", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What are the symptoms observed by the youngest patient to ever did a medical examination? Identify their diagnosis.", "sql": "SELECT T2.Symptoms, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE NOT T2.Symptoms IS NULL ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "The oldest SJS patient's medical laboratory work was completed on what date, and what age was the patient when they initially arrived at the hospital?", "sql": "SELECT T1.Date, EXTRACT(YEAR FROM T2.\"First Date\") - EXTRACT(YEAR FROM T2.Birthday) AS Age, T2.Birthday FROM Laboratory AS T1 INNER JOIN Patient AS T2 ON T1.ID = T2.ID WHERE T2.Diagnosis = 'SJS' AND T2.Birthday IS NOT NULL ORDER BY T2.Birthday ASC LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the ratio of male to female patients among all those with abnormal uric acid counts?", "sql": "SELECT CAST(SUM(CASE WHEN T2.UA <= 8.0 AND T1.SEX = 'M' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN T2.UA <= 6.5 AND T1.SEX = 'F' THEN 1 ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID", "complexity_score": 0.0802, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many underage patients were examined during the course of the three-year period from 1990 to 1993?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE EXTRACT(YEAR FROM T2.\"Examination Date\") BETWEEN 1990 AND 1993 AND EXTRACT(YEAR FROM T2.\"Examination Date\") - EXTRACT(YEAR FROM T1.Birthday) < 18", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How old was the patient who had the highest hemoglobin count at the time of the examination, and what is the doctor's diagnosis?", "sql": "SELECT EXTRACT(YEAR FROM T2.Date) - EXTRACT(YEAR FROM T1.Birthday) AS age_difference, T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.HGB IS NOT NULL ORDER BY T2.HGB DESC LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For the patient who was diagnosed with SLE on 1994/2/19, what was his/her anti-Cardiolipin antibody concentration status on 1993/11/12?", "sql": "SELECT \"aCL IgA\", \"aCL IgG\", \"aCL IgM\" FROM Examination WHERE ID IN (SELECT ID FROM Patient WHERE Diagnosis = 'SLE' AND Description = '1994-02-19') AND \"Examination Date\" = '1993-11-12'", "complexity_score": 0.1354, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For the patient who was born on 1959/2/18, what is the decrease rate for his/her total cholesterol from November to December in 1981?", "sql": "SELECT CAST((SUM(CASE WHEN T2.date::text LIKE '1981-11-%' THEN T2.\"T-CHO\" ELSE 0 END) - SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2.\"T-CHO\" ELSE 0 END)) AS REAL) / NULLIF(SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2.\"T-CHO\" ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Birthday = '1959-02-18'", "complexity_score": 0.0729, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many patients who were examined between 1987/7/6 and 1996/1/31 had a GPT level greater than 30 and an ALB level less than 4? List them by their ID.", "sql": "SELECT DISTINCT ID FROM Laboratory WHERE Date BETWEEN '1987-07-06' AND '1996-01-31' AND GPT > 30 AND ALB < 4", "complexity_score": 0.0385, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What number of patients with a degree of thrombosis level 2 and ANA pattern of only S, have a level of anti-Cardiolip in antibody (IgM) 20% higher than average?", "sql": "SELECT COUNT(*) FROM Examination WHERE Thrombosis = 2 AND \"ANA Pattern\" = 'S' AND \"aCL IgM\" > (SELECT AVG(\"aCL IgM\") * 1.2 FROM Examination WHERE Thrombosis = 2 AND \"ANA Pattern\" = 'S')", "complexity_score": 0.1479, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "List all patients who were followed up at the outpatient clinic who underwent a laboratory test in October 1991 and had a total blood bilirubin level within the normal range.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Admission = '-' AND T2.\"T-BIL\" < 2.0 AND T2.Date::text LIKE '1991-10-%'", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the average blood albumin level for female patients with a PLT greater than 400 who have been diagnosed with SLE?", "sql": "SELECT AVG(T2.ALB) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT > 400 AND T1.Diagnosis = 'SLE' AND T1.SEX = 'F'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many female patients were given an APS diagnosis?", "sql": "SELECT COUNT(ID) FROM Patient WHERE SEX = 'F' AND Diagnosis = 'APS'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What percentage of patients who were born in 1980 and were diagnosed with RA are women?", "sql": "SELECT CAST(SUM(CASE WHEN SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(ID), 0) FROM Patient WHERE Diagnosis = 'RA' AND TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') = '1980'", "complexity_score": 0.0406, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Was the patient with the number 57266's uric acid within a normal range?", "sql": "SELECT CASE WHEN (T1.SEX = 'F' AND T2.UA > 6.5) OR (T1.SEX = 'M' AND T2.UA > 8.0) THEN TRUE ELSE FALSE END FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID = 57266", "complexity_score": 0.0854, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Provide IDs for male patients with ALT glutamic pylvic transaminase (GPT) that have history of ALT glutamic pylvic transaminase (GPT) exceed the normal range.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'M' AND T2.GPT >= 60", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Please provide the diagnosis of patients with ALT glutamic pylvic transaminase beyond the normal range by ascending order of their date of birth.", "sql": "SELECT DISTINCT ON (T1.Birthday) T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GPT > 60 ORDER BY T1.Birthday ASC", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["DISTINCT", "DISTINCT_ON", "FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Provide all ID, sex and birthday of patients whose urea nitrogen (UN) just within the borderline of passing?", "sql": "SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.UN = 29", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "List and group all patients by sex for total bilirubin (T-BIL) level not within the normal range.", "sql": "SELECT T1.ID, T1.SEX FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.\"T-BIL\" >= 2.0 GROUP BY T1.SEX,T1.ID", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What is the average age of the male patient with high cholesterol?", "sql": "SELECT AVG(EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM T1.Birthday)) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.\"T-CHO\" >= 250 AND T1.SEX = 'M'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For all patients with triglyceride (TG) level beyond the normal range, how many are age more than 50 years?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.TG >= 200 AND EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) > 50", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For patient born between 1936-1956, how many male patients have creatinine phosphokinase beyond the normal range?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE TO_CHAR(CAST(T1.Birthday AS TIMESTAMP), 'YYYY') BETWEEN '1936' AND '1956' AND T1.SEX = 'M' AND T2.CPK >= 250", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Provide ID, sex and age of patient who has blood glucose (GLU) not within normal range but with total cholesterol(T-CHO) within normal range.", "sql": "SELECT DISTINCT T1.ID, T1.SEX, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GLU >= 180 AND T2.\"T-CHO\" < 250", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "What are the patient's diagnosis for those who has lower red blood blood cell? State their ID and age.", "sql": "SELECT DISTINCT T1.Diagnosis, T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.RBC < 3.5", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients who were diagnosed with SLE, who is the oldest with normal hemoglobin level. Provide the ID and sex.", "sql": "SELECT T1.ID, T1.SEX FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Diagnosis = 'SLE' AND T2.HGB > 10 AND T2.HGB < 17 ORDER BY T1.Birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Name the ID and age of patient with two or more laboratory examinations which show their hematoclit level exceeded the normal range.", "sql": "SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID IN (SELECT ID FROM Laboratory WHERE HCT >= 52 GROUP BY ID HAVING COUNT(ID) >= 2)", "complexity_score": 0.1542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For patients with abnormal platelet level, state the number of patients with lower than normal range. How is it compare to the number of patients with higher than normal range?", "sql": "SELECT SUM(CASE WHEN T2.PLT <= 100 THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.PLT >= 400 THEN 1 ELSE 0 END) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For laboratory examinations take in 1984, list all patients below 50 years old with normal platelet level.", "sql": "SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT BETWEEN 100 AND 400 AND EXTRACT(YEAR FROM T2.Date) - EXTRACT(YEAR FROM T1.Birthday) < 50 AND EXTRACT(YEAR FROM T2.Date) = 1984", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For all patients who are older than 55 years old, what is the percentage of female who has abnormal prothrombin time (PT)?", "sql": "SELECT CAST(SUM(CASE WHEN T2.PT >= 14 AND T1.SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(CASE WHEN T2.PT >= 14 THEN 1 ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) > 55", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the male patients who have a normal level of white blood cells, how many of them have an abnormal fibrinogen level?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.FG <= 150 OR T2.FG >= 450 AND T2.WBC > 3.5 AND T2.WBC < 9.0 AND T1.SEX = 'M'", "complexity_score": 0.1021, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many patients with an Ig G higher than normal?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE T2.IGG >= 2000", "complexity_score": 0.0969, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients with a normal Ig G level, how many of them have symptoms?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE T2.IGG BETWEEN 900 AND 2000 AND NOT T3.Symptoms IS NULL", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many patients with a normal Ig A level came to the hospital after 1990/1/1?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.IGA BETWEEN 80 AND 500 AND TO_CHAR(CAST(T1.\"First Date\" AS TIMESTAMP), 'YYYY') > '1990'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For the patients with an abnormal Ig M level, what is the most common disease they are diagnosed with?", "sql": "SELECT T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE NOT T2.IGM BETWEEN 40 AND 400 GROUP BY T1.Diagnosis ORDER BY COUNT(T1.Diagnosis) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many patients with a abnormal C-reactive protein don't have their data recorded?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE (T2.CRP = '+') AND T1.Description IS NULL", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients whose creatinine level is abnormal, how many of them aren't 70 yet?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CRE >= 1.5 AND EXTRACT(YEAR FROM AGE(CURRENT_DATE, T1.Birthday)) < 70", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "How many patients have a normal level of anti-ribonuclear protein and have been admitted to the hospital?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.RNP = 'negative' OR T2.RNP = '0' AND T1.Admission = '+'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients with normal anti-SM, how many of them does not have thrombosis?", "sql": "SELECT COUNT(T1.ID) FROM Examination AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.SM IN ('negative', '0') AND T1.Thrombosis = 0", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients who has a normal anti-scl70, how many of them are female and does not have any symptom?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE (T2.SC170 = 'negative' OR T2.SC170 = '0') AND T1.SEX = 'F' AND T3.Symptoms IS NULL", "complexity_score": 0.1281, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients who has a normal level of anti-centromere and a normal level of anti-SSB, how many of them are male?", "sql": "SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CENTROMEA IN ('negative', '0') AND T2.SSB IN ('negative', '0') AND T1.SEX = 'M'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "Among the patients who have an abnormal level of glutamic oxaloacetic transaminase, when was the youngest of them born?", "sql": "SELECT T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GOT >= 60 ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "thrombosis_prediction", "intent": "For the patients with a normal range of creatinine phosphokinase, how many of them have a positive measure of degree of coagulation?", "sql": "SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T1.ID = T3.ID WHERE T2.CPK < 250 AND (T3.KCT = '+' OR T3.RVVT = '+' OR T3.LAC = '+')", "complexity_score": 0.1281, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Give the name of the league had the most goals in the 2016 season?", "sql": "SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' GROUP BY t2.name ORDER BY SUM(t1.home_team_goal + t1.away_team_goal) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "In Scotland Premier League, which away team won the most during the 2010 season?", "sql": "SELECT teamInfo.team_long_name FROM League AS leagueData INNER JOIN Match AS matchData ON leagueData.id = matchData.league_id INNER JOIN Team AS teamInfo ON matchData.away_team_api_id = teamInfo.team_api_id WHERE leagueData.name = 'Scotland Premier League' AND matchData.season = '2009/2010' AND matchData.away_team_goal - matchData.home_team_goal > 0 GROUP BY teamInfo.team_long_name, matchData.away_team_api_id ORDER BY COUNT(*) DESC LIMIT 1", "complexity_score": 0.1177, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What are the speed in which attacks are put together of the top 4 teams with the highest build Up Play Speed?", "sql": "SELECT t1.buildUpPlaySpeed FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id ORDER BY t1.buildUpPlaySpeed ASC NULLS FIRST LIMIT 4", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Give the name of the league had the most matches end as draw in the 2016 season?", "sql": "SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' AND t1.home_team_goal = t1.away_team_goal GROUP BY t2.name ORDER BY COUNT(t1.id) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "At present, calculate for the player's age who have a sprint speed of no less than 97 between 2013 to 2015.", "sql": "SELECT DISTINCT EXTRACT(YEAR FROM AGE(NOW(), t2.birthday::timestamp)) + (CASE WHEN EXTRACT(MONTH FROM AGE(NOW(), t2.birthday::timestamp)) > 0 OR EXTRACT(DAY FROM AGE(NOW(), t2.birthday::timestamp)) > 0 THEN 1 ELSE 0 END) AS age FROM Player_Attributes AS t1 INNER JOIN Player AS t2 ON t1.player_api_id = t2.player_api_id WHERE EXTRACT(YEAR FROM t1.date::date) BETWEEN 2013 AND 2015 AND t1.sprint_speed >= 97", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Give the name of the league with the highest matches of all time and how many matches were played in the said league.", "sql": "SELECT t2.name, t1.max_count FROM League AS t2 JOIN (SELECT league_id, MAX(cnt) AS max_count FROM (SELECT league_id, COUNT(id) AS cnt FROM Match GROUP BY league_id) AS subquery GROUP BY league_id ORDER BY MAX(cnt) DESC LIMIT 1) AS t1 ON t1.league_id = t2.id", "complexity_score": 0.224, "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "LIMIT", "ORDER", "SELECT", "SUBQUERY"], "num_joins": 1, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Give the team_fifa_api_id of teams with more than 50 but less than 60 build-up play speed.", "sql": "SELECT DISTINCT team_fifa_api_id FROM Team_Attributes WHERE buildUpPlaySpeed > 50 AND buildUpPlaySpeed < 60", "complexity_score": 0.0281, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "List the long name of teams with above-average build-up play passing in 2012.", "sql": "SELECT DISTINCT t4.team_long_name FROM Team_Attributes AS t3 INNER JOIN Team AS t4 ON t3.team_api_id = t4.team_api_id WHERE SUBSTR(t3.\"date\", 1, 4) = '2012' AND t3.buildUpPlayPassing > (SELECT CAST(SUM(t2.buildUpPlayPassing) AS REAL) / NULLIF(COUNT(t1.id), 0) FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') = '2012')", "complexity_score": 0.1896, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Calculate the percentage of players who prefer left foot, who were born between 1987 and 1992.", "sql": "SELECT CAST(COUNT(CASE WHEN t2.preferred_foot = 'left' THEN t1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(t1.id), 0) AS percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t1.birthday, 1, 4) BETWEEN '1987' AND '1992'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Find the average number of long-shot done by Ahmed Samir Farag.", "sql": "SELECT CAST(SUM(t2.long_shots) AS REAL) / NULLIF(COUNT(t2.\"date\"), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Ahmed Samir Farag'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "List the top 10 players' names whose heights are above 180 in descending order of average heading accuracy.", "sql": "SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 180 GROUP BY t1.id ORDER BY CAST(SUM(t2.heading_accuracy) AS REAL) / NULLIF(COUNT(t2.\"player_fifa_api_id\"), 0) DESC NULLS LAST LIMIT 10", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "List the name of leagues in which the average goals by the home team is higher than the away team in the 2009/2010 season.", "sql": "SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2009/2010' GROUP BY t1.name HAVING (CAST(SUM(t2.home_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) - (CAST(SUM(t2.away_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) > 0", "complexity_score": 0.0865, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "List the football players with a birthyear of 1970 and a birthmonth of October.", "sql": "SELECT player_name FROM Player WHERE SUBSTR(birthday, 1, 7) = '1970-10'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What is the overall rating of the football player Gabriel Tamas in year 2011?", "sql": "SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Gabriel Tamas' AND TO_CHAR(CAST(t2.date AS TIMESTAMP), 'YYYY') = '2011'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Calculate the average home team goal in the 2010/2011 season in the country of Poland.", "sql": "SELECT CAST(SUM(t2.home_team_goal) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Country AS t1 INNER JOIN Match AS t2 ON t1.id = t2.country_id WHERE t1.name = 'Poland' AND t2.season = '2010/2011'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Who has the highest average finishing rate between the highest and shortest football player?", "sql": "SELECT A FROM (SELECT AVG(finishing) AS result, 'Max' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MAX(height) FROM Player) UNION SELECT AVG(finishing) AS result, 'Min' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MIN(height) FROM Player)) AS subquery ORDER BY result DESC LIMIT 1", "complexity_score": 0.3042, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "UNION", "WHERE"], "num_joins": 2, "num_subqueries": 3, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "From 2010 to 2015, what was the average overall rating of players who are higher than 170?", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 170 AND TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') >= '2010' AND TO_CHAR(CAST(t2.\"date\" AS TIMESTAMP), 'YYYY') <= '2015'", "complexity_score": 0.0875, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What is the difference of the average ball control score between Abdou Diallo and Aaron Appindangoye\n?", "sql": "SELECT CAST(SUM(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.ball_control ELSE 0 END) AS REAL) / NULLIF(COUNT(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.id ELSE NULL END), 0) - CAST(SUM(CASE WHEN t1.player_name = 'Aaron Appindangoye' THEN t2.ball_control ELSE 0 END) AS REAL) / NULLIF(COUNT(CASE WHEN t1.player_name = 'Aaron Appindangoye' THEN t2.id ELSE NULL END), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.0719, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Which player is older, Aaron Lennon or Abdelaziz Barrada?", "sql": "SELECT player_name FROM Player WHERE player_name IN ('Aaron Lennon', 'Abdelaziz Barrada') ORDER BY birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Which player is the tallest?", "sql": "SELECT player_name FROM Player ORDER BY height DESC NULLS LAST LIMIT 1", "complexity_score": 0.0104, "pattern_signature": "SELECT-FROM-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Among the players whose preferred foot was the left foot when attacking, how many of them would remain in his position when the team attacked?", "sql": "SELECT COUNT(player_api_id) FROM Player_Attributes WHERE preferred_foot = 'left' AND attacking_work_rate = 'low'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Among the players born before the year 1986, how many of them would remain in his position and defense while the team attacked?", "sql": "SELECT COUNT(DISTINCT t1.player_name) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE TO_CHAR(CAST(t1.birthday AS TIMESTAMP), 'YYYY') < '1986' AND t2.defensive_work_rate = 'high'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Please list the names of the players whose volley score and dribbling score are over 70.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.volleys > 70 AND t2.dribbling > 70", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "How many matches were held in the Belgium Jupiler League in April, 2009?", "sql": "SELECT COUNT(t2.id) FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t1.name = 'Belgium Jupiler League' AND SUBSTR(t2.\"date\", 1, 7) = '2009-04'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Give the name of the league had the most matches in the 2008/2009 season?", "sql": "SELECT t1.name FROM League AS t1 JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2008/2009' GROUP BY t1.name HAVING COUNT(t2.id) = (SELECT MAX(match_count) FROM (SELECT COUNT(t2.id) AS match_count FROM Match AS t2 WHERE t2.season = '2008/2009' GROUP BY t2.league_id) AS subquery)", "complexity_score": 0.2458, "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "How much higher in percentage is Ariel Borysiuk's overall rating than that of Paulin Puel?", "sql": "SELECT (SUM(CASE WHEN t1.player_name = 'Ariel Borysiuk' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.0656, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Calculate the average overall rating of Pietro Marino.", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Pietro Marino'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What is Ajax's highest chance creation passing score and what is it classified as?", "sql": "SELECT t2.chanceCreationPassing, t2.chanceCreationPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Ajax' ORDER BY t2.chanceCreationPassing DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "For the players who had a 77 points overall rating on 2016/6/23, who was the oldest? Give the name of the player.", "sql": "SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2016-06-23' AND t2.overall_rating = 77 ORDER BY t1.birthday ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What was the overall rating for Aaron Mooy on 2016/2/4?", "sql": "SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2016-02-04' AND t1.player_name = 'Aaron Mooy'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "How was Francesco Migliore's attacking work rate on 2015/5/1?", "sql": "SELECT t2.attacking_work_rate FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.\"date\" LIKE '2015-05-01%' AND t1.player_name = 'Francesco Migliore'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "When was the first time did Kevin Constant have his highest crossing score? Give the date.", "sql": "SELECT \"date\" FROM (SELECT t2.crossing, t2.\"date\" FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE t1.player_name = 'Kevin Constant' ORDER BY t2.crossing DESC) AS subquery ORDER BY \"date\" DESC LIMIT 1", "complexity_score": 0.1333, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Tell the build Up play passing class for \"FC Lorient\" on 2010/2/22.", "sql": "SELECT t2.buildUpPlayPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'FC Lorient' AND t2.\"date\" LIKE '2010-02-22%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "For the team \"Hannover 96\", what was its defence aggression class on 2015/9/10?", "sql": "SELECT t2.defenceAggressionClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Hannover 96' AND t2.\"date\" LIKE '2015-09-10%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What was the average overall rating for Marko Arnautovic from 2007/2/22 to 2016/4/21?", "sql": "SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE t1.player_name = 'Marko Arnautovic' AND SUBSTR(t2.\"date\", 1, 10) BETWEEN '2007-02-22' AND '2016-04-21'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What percentage is Landon Donovan's overall rating higher than Jordan Bowery on 2013/7/12?", "sql": "SELECT (SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Jordan Bowery' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END), 0) AS LvsJ_percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE SUBSTR(t2.\"date\", 1, 10) = '2013-07-12'", "complexity_score": 0.0729, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "List down most tallest players' name.", "sql": "SELECT player_name FROM (SELECT player_name, height, DENSE_RANK() OVER (ORDER BY height DESC) AS rank FROM Player) AS subquery WHERE rank = 1", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", "clauses_present": ["FROM", "ORDER", "SELECT", "SUBQUERY", "WHERE", "WINDOW"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "State the name of the most strongest player.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.overall_rating = (SELECT MAX(overall_rating) FROM Player_Attributes)", "complexity_score": 0.1396, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Who are the players that tend to be attacking when their mates were doing attack moves? List down their name.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.attacking_work_rate = 'high'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What are the short name of team who played safe while creating chance of passing?", "sql": "SELECT DISTINCT t1.team_short_name FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.chanceCreationPassingClass = 'Safe'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "How many football players born after the 1990s have the first name \"Aaron\"?", "sql": "SELECT COUNT(id) FROM Player WHERE birthday > '1990' AND player_name LIKE 'Aaron%'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What is the difference between players 6 and 23's jumping scores?", "sql": "SELECT SUM(CASE WHEN t1.id = 6 THEN t1.jumping ELSE 0 END) - SUM(CASE WHEN t1.id = 23 THEN t1.jumping ELSE 0 END) FROM Player_Attributes AS t1", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Please provide top four football players' IDs who are among the lowest potential players and prefer to use the right foot when attacking.", "sql": "SELECT id FROM Player_Attributes WHERE preferred_foot = 'right' ORDER BY potential ASC NULLS LAST LIMIT 4", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "How many players had the highest potential score for crossing that preferred to use their left foots while attacking?", "sql": "SELECT COUNT(t1.id) FROM Player_Attributes AS t1 WHERE t1.preferred_foot = 'left' AND t1.crossing = (SELECT MAX(crossing) FROM Player_Attributes)", "complexity_score": 0.1198, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What was the final score for the match on September 24, 2008, in the Belgian Jupiler League between the home team and the away team?", "sql": "SELECT t2.home_team_goal, t2.away_team_goal FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t1.name = 'Belgium Jupiler League' AND t2.\"date\" LIKE '2008-09-24%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Does the KSV Cercle Brugge team have a slow, balanced or fast speed class?", "sql": "SELECT DISTINCT t1.buildUpPlaySpeedClass FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.team_long_name = 'KSV Cercle Brugge'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Please state the finishing rate and curve score of the player who has the heaviest weight.", "sql": "SELECT id, finishing, curve FROM Player_Attributes WHERE player_api_id = (SELECT player_api_id FROM Player ORDER BY weight DESC NULLS LAST LIMIT 1) LIMIT 1", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Which top 4 leagues had the most games in the 2015-2016 season?", "sql": "SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2015/2016' GROUP BY t1.name ORDER BY COUNT(t2.id) DESC NULLS LAST LIMIT 4", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Please provide the full name of the away team that scored the most goals.", "sql": "SELECT t2.team_long_name FROM Match AS t1 INNER JOIN Team AS t2 ON t1.away_team_api_id = t2.team_api_id ORDER BY t1.away_team_goal DESC NULLS LAST LIMIT 1", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "Please name one player whose overall strength is the greatest.", "sql": "SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.overall_rating = (SELECT MAX(overall_rating) FROM Player_Attributes)", "complexity_score": 0.1396, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "european_football_2", "intent": "What is the percentage of players that are under 180 cm who have an overall strength of more than 70?", "sql": "SELECT CAST(COUNT(CASE WHEN t2.overall_rating > 70 AND t1.height < 180 THEN t1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(t1.id), 0) AS percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id", "complexity_score": 0.0698, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please list the reference names of the drivers who are eliminated in the first period in race number 20.", "sql": "SELECT T2.driverRef FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 20 ORDER BY T1.q1 DESC NULLS LAST LIMIT 5", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the surname of the driver with the best lap time in race number 19 in the second qualifying period?", "sql": "SELECT T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 19 ORDER BY T1.q2 ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please give the name of the race held on the circuits in Germany.", "sql": "SELECT DISTINCT T2.name FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T1.country = 'Germany'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the coordinates location of the circuits for Australian grand prix?", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Australian Grand Prix'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Give the coordinate position for Abu Dhabi Grand Prix.", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Abu Dhabi Grand Prix'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What's Bruno Senna's Q1 result in the qualifying race No. 354?", "sql": "SELECT T1.q1 FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 354 AND T2.forename = 'Bruno' AND T2.surname = 'Senna'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is his number of the driver who finished 0:01:54 in the Q3 of qualifying race No.903?", "sql": "SELECT T2.number FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 903 AND T1.q3 LIKE '1:54%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For the Bahrain Grand Prix in 2007, how many drivers not finished the game?", "sql": "SELECT COUNT(T3.driverId) FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T1.year = 2007 AND T1.name = 'Bahrain Grand Prix' AND T2.time IS NULL", "complexity_score": 0.1177, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For all the drivers who finished the game in race No. 592, who is the oldest?", "sql": "SELECT T1.forename, T1.surname FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T2.raceId = 592 AND NOT T2.time IS NULL AND NOT T1.dob IS NULL ORDER BY T1.dob ASC NULLS FIRST LIMIT 1", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Who was the player that got the lap time of 0:01:27 in the race No. 161? Show his introduction website.", "sql": "SELECT DISTINCT T2.forename, T2.surname, T2.url FROM lapTimes AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 161 AND T1.time LIKE '1:27%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Where is Malaysian Grand Prix held? Give the location coordinates.", "sql": "SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Malaysian Grand Prix'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For the constructor which got the highest point in the race No. 9 , what is its introduction website?", "sql": "SELECT T2.url FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T2.constructorId = T1.constructorId WHERE T1.raceId = 9 ORDER BY T1.points DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "In the race No. 45, for the driver who had the Q3 time as 0:01:33, what is his abbreviated code?", "sql": "SELECT T2.code FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 45 AND T1.q3 LIKE '1:33%'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Show me the season page of year when the race No. 901 took place.", "sql": "SELECT T2.url FROM races AS T1 INNER JOIN seasons AS T2 ON T2.year = T1.year WHERE T1.raceId = 901", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For all the drivers who finished the game in race No. 872, who is the youngest?", "sql": "SELECT T1.forename, T1.surname FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T2.raceId = 872 AND NOT T2.time IS NULL ORDER BY T1.dob DESC NULLS LAST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For the driver who set the fastest lap speed, what is his nationality?", "sql": "SELECT T1.nationality FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId ORDER BY CAST(T2.fastestLapSpeed AS DOUBLE PRECISION) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Paul di Resta was in the No. 853 race, what percent faster did he finish in the 853rd race than the next race for the fastest lap speed?", "sql": "SELECT (SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END) - SUM(CASE WHEN T2.raceId = 854 THEN T2.fastestLapSpeed::numeric ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END), 0) FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T1.forename = 'Paul' AND T1.surname = 'di Resta'", "complexity_score": 0.0833, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "For the drivers who took part in the race in 1983/7/16, what's their race completion rate?", "sql": "SELECT CAST(COUNT(CASE WHEN NOT T2.time IS NULL THEN T2.driverId END) AS REAL) * 100 / NULLIF(COUNT(T2.driverId), 0) FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId WHERE T1.date = '1983-07-16'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "List the names of all races that occurred in the earliest recorded year and month.", "sql": "SELECT name FROM races WHERE TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') = (SELECT TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') FROM races ORDER BY date ASC NULLS FIRST LIMIT 1) AND TO_CHAR(CAST(date AS TIMESTAMP), 'MM') = (SELECT TO_CHAR(CAST(date AS TIMESTAMP), 'MM') FROM races ORDER BY date ASC NULLS FIRST LIMIT 1)", "complexity_score": 0.1406, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "State the driver with the most points scored. Find his full name with that points.", "sql": "SELECT T3.forename, T3.surname, T2.points FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId ORDER BY T2.points DESC NULLS LAST LIMIT 1", "complexity_score": 0.0833, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the best lap time recorded? List the driver and race with such recorded lap time.", "sql": "SELECT T2.milliseconds, T1.forename, T1.surname, T3.name FROM drivers AS T1 INNER JOIN lapTimes AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T2.raceId = T3.raceId ORDER BY T2.milliseconds ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0833, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the average lap time for Lewis Hamilton in the 2009 Malaysian Grand Prix?", "sql": "SELECT AVG(T2.milliseconds) FROM races AS T1 INNER JOIN lapTimes AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' AND T1.year = 2009 AND T1.name = 'Malaysian Grand Prix'", "complexity_score": 0.1281, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Calculate the percentage whereby Hamilton was not at the 1st track of the the f1 circuit since 2010.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.position <> 1 THEN T2.position END) AS REAL) * 100 / NULLIF(COUNT(T2.driverStandingsId), 0) FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.surname = 'Hamilton' AND T1.year >= 2010", "complexity_score": 0.1135, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Name the driver with the most winning. Mention his nationality and what is his maximum point scores.", "sql": "SELECT T1.forename, T1.surname, T1.nationality, MAX(T2.points) FROM drivers AS T1 INNER JOIN driverStandings AS T2 ON T2.driverId = T1.driverId WHERE T2.wins >= 1 GROUP BY T1.forename, T1.surname, T1.nationality ORDER BY COUNT(T2.wins) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How old is the youngest Japanese driver? What is his name?", "sql": "SELECT EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM dob) AS age, forename, surname FROM drivers WHERE nationality = 'Japanese' ORDER BY dob DESC LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Name the races along with its circuit name and location for f1 races hosted in September 2005.", "sql": "SELECT DISTINCT T2.name, T1.name, T1.location FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.year = 2005 AND TO_CHAR(CAST(T2.date AS TIMESTAMP), 'MM') = '09'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which race was Alex Yoong in when he was in track number less than 20?", "sql": "SELECT T1.name FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Alex' AND T3.surname = 'Yoong' AND T2.position < 20", "complexity_score": 0.1115, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "State the race and year of race in which Michael Schumacher had his fastest lap.", "sql": "SELECT T1.name, T1.year FROM races AS T1 INNER JOIN lapTimes AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Michael' AND T3.surname = 'Schumacher' ORDER BY T2.milliseconds ASC NULLS FIRST LIMIT 1", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which was Lewis Hamilton first race? What was his points recorded for his first race event?", "sql": "SELECT T1.name, T2.points FROM races AS T1 INNER JOIN driverStandings AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' ORDER BY T1.year ASC NULLS FIRST LIMIT 1", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Among all European Grand Prix races, what is the percentage of the races were hosted in Germany?", "sql": "SELECT CAST(COUNT(CASE WHEN T1.country = 'Germany' THEN T2.circuitID END) AS REAL) * 100 / NULLIF(COUNT(T2.circuitId), 0) FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'European Grand Prix'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What's the location coordinates of Silverstone Circuit?", "sql": "SELECT lat, lng FROM circuits WHERE name = 'Silverstone Circuit'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What's the reference name of Marina Bay Street Circuit?", "sql": "SELECT circuitRef FROM circuits WHERE name = 'Marina Bay Street Circuit'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which country is the oldest driver from?", "sql": "SELECT nationality FROM drivers WHERE NOT dob IS NULL ORDER BY dob ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which driver ranked the first in the Canadian Grand Prix in 2007? Please give his reference name.", "sql": "SELECT T3.forename, T3.surname, T3.driverRef FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T1.name = 'Canadian Grand Prix' AND T2.rank = 1 AND T1.year = 2007", "complexity_score": 0.1115, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "In which Formula_1 race did Lewis Hamilton rank the highest?", "sql": "SELECT name FROM races WHERE raceId IN (SELECT raceId FROM results WHERE rank = 1 AND driverId = (SELECT driverId FROM drivers WHERE forename = 'Lewis' AND surname = 'Hamilton'))", "complexity_score": 0.2323, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What was the fastest lap speed among all drivers in the 2009 Spanish Grand Prix?", "sql": "SELECT T2.fastestLapSpeed FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId WHERE T1.name = 'Spanish Grand Prix' AND T1.year = 2009 AND NOT T2.fastestLapSpeed IS NULL ORDER BY T2.fastestLapSpeed DESC NULLS LAST LIMIT 1", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What was Lewis Hamilton's final rank in the 2008 Chinese Grand Prix?", "sql": "SELECT T2.positionOrder FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId INNER JOIN drivers AS T3 ON T3.driverId = T2.driverId WHERE T3.forename = 'Lewis' AND T3.surname = 'Hamilton' AND T1.name = 'Chinese Grand Prix' AND T1.year = 2008", "complexity_score": 0.1219, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What's the finish time for the driver who ranked second in 2008's Chinese Grand Prix?", "sql": "SELECT T1.time FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T1.rank = 2 AND T2.name = 'Chinese Grand Prix' AND T2.year = 2008", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Among the drivers that finished the race in the 2008 Chinese Grand Prix, how many of them have participated in Formula_1 races?", "sql": "SELECT COUNT(*) FROM (SELECT T1.driverId FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Chinese Grand Prix' AND T2.year = 2008 AND T1.time IS NOT NULL GROUP BY T1.driverId HAVING COUNT(T2.raceId) > 0) AS subquery", "complexity_score": 0.174, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How much faster in percentage is the champion than the driver who finished the race last in the 2008 Australian Grand Prix?", "sql": "WITH time_in_seconds AS (SELECT T1.positionOrder, CASE WHEN T1.positionOrder = 1 THEN (CAST(SUBSTR(T1.time, 1, 1) AS REAL) * 3600) + (CAST(SUBSTR(T1.time, 3, 2) AS REAL) * 60) + CAST(SUBSTR(T1.time, 6) AS REAL) ELSE CAST(SUBSTR(T1.time, 2) AS REAL) END AS time_seconds FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Australian Grand Prix' AND NOT T1.time IS NULL AND T2.year = 2008), champion_time AS (SELECT time_seconds FROM time_in_seconds WHERE positionOrder = 1), last_driver_incremental AS (SELECT time_seconds FROM time_in_seconds WHERE positionOrder = (SELECT MAX(positionOrder) FROM time_in_seconds)) SELECT (CAST((SELECT time_seconds FROM last_driver_incremental) AS REAL) * 100) / NULLIF((SELECT time_seconds + (SELECT time_seconds FROM last_driver_incremental) FROM champion_time), 0)", "complexity_score": 0.3521, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["CTE", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 4, "num_ctes": 3, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How many circuits are there in Adelaide, Australia?", "sql": "SELECT COUNT(circuitId) FROM circuits WHERE location = 'Adelaide' AND country = 'Australia'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What are the maximum points of British constructors?", "sql": "SELECT MAX(T1.points) FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T2.nationality = 'British'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please list the constructor names with 0 points at race 291.", "sql": "SELECT T2.name FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T1.raceId = 291", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How many Japanese constructors have 0 points in 2 races?", "sql": "SELECT COUNT(T1.raceId) FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T2.nationality = 'Japanese' GROUP BY T1.constructorId HAVING COUNT(raceId) = 2", "complexity_score": 0.0844, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please calculate the race completion percentage of Japanese drivers from 2007 to 2009.", "sql": "SELECT CAST(SUM(CASE WHEN NOT T1.time IS NULL THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.raceId), 0) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN drivers AS T3 ON T1.driverId = T3.driverId WHERE T3.nationality = 'Japanese' AND T2.year BETWEEN 2007 AND 2009", "complexity_score": 0.1135, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the average time in seconds of champion for each year, before year 1975?", "sql": "WITH time_in_seconds AS (SELECT T2.year, T2.raceId, T1.positionOrder, CASE WHEN T1.positionOrder = 1 THEN (CASE WHEN SPLIT_PART(T1.time, ':', 1) <> '' AND SPLIT_PART(T1.time, ':', 2) <> '' AND SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 1) <> '' THEN (CAST(SPLIT_PART(T1.time, ':', 1) AS REAL) * 3600) + (CAST(SPLIT_PART(T1.time, ':', 2) AS REAL) * 60) + CAST(SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 1) AS REAL) + CAST(SPLIT_PART(SPLIT_PART(T1.time, ':', 3), '.', 2) AS REAL)/1000 ELSE 0 END) ELSE (CASE WHEN SUBSTRING(T1.time FROM 2) <> '' THEN CAST(SUBSTRING(T1.time FROM 2) AS REAL) ELSE 0 END) END AS time_seconds FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T1.time IS NOT NULL AND T1.time != ''), champion_time AS (SELECT year, raceId, time_seconds FROM time_in_seconds WHERE positionOrder = 1) SELECT year, AVG(time_seconds) FROM champion_time WHERE year < 1975 GROUP BY year HAVING AVG(time_seconds) IS NOT NULL", "complexity_score": 0.1865, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["CTE", "FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 2, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the fastest lap number of the champion in 2009?", "sql": "SELECT T1.fastestLap FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.year = 2009 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the average of fastest lap speed in the 2009 Spanish Grand Prix race?", "sql": "SELECT AVG(CAST(T1.fastestLapSpeed AS NUMERIC)) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.year = 2009 AND T2.name = 'Spanish Grand Prix'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "From 2000 to 2005, what percentage of drivers who were born before 1985 and the lap numbers were over 50?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(T3.dob AS TIMESTAMP), 'YYYY') < '1985' AND T1.laps > 50 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN drivers AS T3 ON T1.driverId = T3.driverId WHERE T2.year BETWEEN 2000 AND 2005", "complexity_score": 0.1135, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How many French drivers who obtain the laptime less than 02:00.00?", "sql": "SELECT COUNT(T1.driverId) FROM drivers AS T1 INNER JOIN lapTimes AS T2 ON T1.driverId = T2.driverId WHERE T1.nationality = 'French' AND (EXTRACT(MINUTE FROM T2.time::INTERVAL) * 60 + EXTRACT(SECOND FROM T2.time::INTERVAL)) < 120", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "List out the code for drivers who have nationality in America.", "sql": "SELECT code FROM drivers WHERE Nationality = 'American'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "State code numbers of top 3 yougest drivers. How many Netherlandic drivers among them?", "sql": "SELECT COUNT(*) FROM (SELECT nationality FROM drivers ORDER BY dob DESC LIMIT 3) AS T3 WHERE nationality = 'Dutch'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please state the reference name of the oldest German driver.", "sql": "SELECT driverRef FROM drivers WHERE nationality = 'German' ORDER BY dob ASC LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which drivers who were born in 1971 and has the fastest lap time on the race? Give id and code of these drivers.", "sql": "SELECT T2.driverId, T2.code FROM results AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId WHERE TO_CHAR(CAST(T2.dob AS TIMESTAMP), 'YYYY') = '1971' AND NOT T1.fastestLapTime IS NULL", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "From race no. 50 to 100, how many finishers have been disqualified?", "sql": "SELECT SUM(CASE WHEN NOT time IS NULL THEN 1 ELSE 0 END) FROM results WHERE statusId = 2 AND raceID < 100 AND raceId > 50", "complexity_score": 0.0448, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How many times the circuits were held in Austria? Please give their location and coordinates.", "sql": "SELECT DISTINCT location, lat, lng FROM circuits WHERE country = 'Austria'", "complexity_score": 0.0177, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "On what year did the youngest driver had his first qualifying race? Also state the name, date and time of the race.", "sql": "SELECT T3.year, T3.name, T3.date, T3.time FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T1.raceId = T3.raceId WHERE T1.driverId = (SELECT driverId FROM drivers ORDER BY dob DESC NULLS LAST LIMIT 1) ORDER BY T3.date ASC NULLS FIRST LIMIT 1", "complexity_score": 0.1698, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "List down top 3 German drivers who has the shortest average pit stop duration and were born between 1980-1985.", "sql": "SELECT T2.forename, T2.surname FROM pitStops AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId WHERE T2.nationality = 'German' AND EXTRACT(YEAR FROM T2.dob) BETWEEN 1980 AND 1985 GROUP BY T2.forename, T2.surname ORDER BY AVG(CAST(T1.duration AS INTERVAL)) LIMIT 3", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Who is the champion of the Canadian Grand Prix in 2008? Indicate his finish time.", "sql": "SELECT T1.time FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.name = 'Canadian Grand Prix' AND T2.year = 2008 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is the constructor reference name of the champion in the 2009 Singapore Grand Prix? Please give its website.", "sql": "SELECT T3.constructorRef, T3.url FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN constructors AS T3 ON T1.constructorId = T3.constructorId WHERE T2.name = 'Singapore Grand Prix' AND T2.year = 2009 AND T1.time LIKE '_:%:__.___'", "complexity_score": 0.1115, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Please list all the superpowers of 3-D Man.", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T1.superhero_name = '3-D Man'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which constructor scored most points from Monaco Grand Prix between 1980 and 2010? List the score, name and nationality of this team.", "sql": "SELECT SUM(T1.points), T2.name, T2.nationality FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId INNER JOIN races AS T3 ON T3.raceid = T1.raceid WHERE T3.name = 'Monaco Grand Prix' AND T3.year BETWEEN 1980 AND 2010 GROUP BY T2.name, T2.nationality ORDER BY SUM(T1.points) DESC LIMIT 1", "complexity_score": 0.1135, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "What is full name of the racer who ranked 1st in the 3rd qualifying race held in the Marina Bay Street Circuit in 2008?", "sql": "SELECT T2.forename, T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T1.raceid = T3.raceid WHERE q3 IS NOT NULL AND T3.year = 2008 AND T3.circuitId IN (SELECT circuitId FROM circuits WHERE name = 'Marina Bay Street Circuit') ORDER BY CAST(SPLIT_PART(q3, ':', 1) AS INTEGER) * 60 + CAST(SPLIT_PART(SPLIT_PART(q3, ':', 2), '.', 1) AS REAL) + CAST(SPLIT_PART(q3, '.', 2) AS REAL) / 1000 ASC LIMIT 1", "complexity_score": 0.2083, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "As of the present, what is the full name of the youngest racer? Indicate her nationality and the name of the race to which he/she first joined.", "sql": "SELECT T1.forename, T1.surname, T1.nationality, T3.name FROM drivers AS T1 INNER JOIN driverStandings AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T2.raceId = T3.raceId WHERE T1.dob notnull ORDER BY T1.dob DESC LIMIT 1", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "How many accidents did the driver who had the highest number accidents in the Canadian Grand Prix have?", "sql": "SELECT COUNT(T1.driverId) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN status AS T3 ON T1.statusId = T3.statusId WHERE T3.statusId = 3 AND T2.name = 'Canadian Grand Prix' GROUP BY T1.driverId ORDER BY COUNT(T1.driverId) DESC NULLS LAST LIMIT 1", "complexity_score": 0.1135, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Which top 20 driver created the shortest lap time ever record in a Formula_1 race? Please give them full names.", "sql": "WITH lap_times_in_seconds AS (SELECT driverId, (CASE WHEN SPLIT_PART(time, ':', 1) <> '' THEN CAST(SPLIT_PART(time, ':', 1) AS float) * 60 ELSE 0 END + CASE WHEN SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 1) <> '' THEN CAST(SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 1) AS float) ELSE 0 END + CASE WHEN SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 2) <> '' THEN CAST(SPLIT_PART(SPLIT_PART(time, ':', 2), '.', 2) AS float) / 1000 ELSE 0 END) AS time_in_seconds FROM lapTimes) SELECT T2.forename, T2.surname, T1.driverId FROM (SELECT driverId, MIN(time_in_seconds) AS min_time_in_seconds FROM lap_times_in_seconds GROUP BY driverId) AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId ORDER BY T1.min_time_in_seconds ASC LIMIT 20", "complexity_score": 0.1427, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["CTE", "FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WITH"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "formula_1", "intent": "Please list the lap records for the circuits in Italy.", "sql": "WITH fastest_lap_times AS (SELECT T1.raceId, T1.FastestLapTime, (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) AS time_in_seconds FROM results AS T1 WHERE T1.FastestLapTime IS NOT NULL) SELECT T1.FastestLapTime AS lap_record FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId INNER JOIN (SELECT MIN(fastest_lap_times.time_in_seconds) AS min_time_in_seconds FROM fastest_lap_times INNER JOIN races AS T2 ON fastest_lap_times.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId WHERE T3.country = 'Italy') AS T4 ON (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) = T4.min_time_in_seconds LIMIT 1", "complexity_score": 0.2719, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-LIMIT-SUBQUERY", "clauses_present": ["CTE", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "SUBQUERY", "WHERE", "WITH"], "num_joins": 5, "num_subqueries": 1, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Among the superheroes with the super power of \"Super Strength\", how many of them have a height of over 200cm?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Super Strength' AND T1.height_cm > 200", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Among the superheroes with blue eyes, how many of them have the super power of \"Agility\"?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN colour AS T4 ON T1.eye_colour_id = T4.id WHERE T3.power_name = 'Agility' AND T4.colour = 'Blue'", "complexity_score": 0.1438, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Please list the superhero names of all the superheroes that have blue eyes and blond hair.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T2.colour = 'Blue' AND T3.colour = 'Blond'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Rank heroes published by Marvel Comics by their height in descending order.", "sql": "SELECT superhero_name, height_cm, RANK() OVER (ORDER BY height_cm DESC NULLS LAST) AS HeightRank FROM superhero INNER JOIN publisher ON superhero.publisher_id = publisher.id WHERE publisher.publisher_name = 'Marvel Comics'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Rank superheroes from Marvel Comics by their eye color popularity, starting with the most common color.", "sql": "SELECT colour.colour AS EyeColor, COUNT(superhero.id) AS Count, RANK() OVER (ORDER BY COUNT(superhero.id) DESC NULLS LAST) AS PopularityRank FROM superhero INNER JOIN colour ON superhero.eye_colour_id = colour.id INNER JOIN publisher ON superhero.publisher_id = publisher.id WHERE publisher.publisher_name = 'Marvel Comics' GROUP BY colour.colour", "complexity_score": 0.1094, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "List the superheroes from Marvel Comics who have the super power of 'Super Strength'.", "sql": "SELECT superhero_name FROM superhero AS T1 WHERE EXISTS(SELECT 1 FROM hero_power AS T2 INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Super Strength' AND T1.id = T2.hero_id) AND EXISTS(SELECT 1 FROM publisher AS T4 WHERE T4.publisher_name = 'Marvel Comics' AND T1.publisher_id = T4.id)", "complexity_score": 0.1208, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which publisher published the slowest superhero?", "sql": "SELECT T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN hero_attribute AS T3 ON T1.id = T3.hero_id INNER JOIN attribute AS T4 ON T3.attribute_id = T4.id WHERE T4.attribute_name = 'Speed' ORDER BY T3.attribute_value NULLS FIRST LIMIT 1", "complexity_score": 0.1271, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many gold-eyed superheroes did Marvel Comics publish?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN colour AS T3 ON T1.eye_colour_id = T3.id WHERE T2.publisher_name = 'Marvel Comics' AND T3.colour = 'Gold'", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Who is the dumbest superhero?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Intelligence' ORDER BY T2.attribute_value NULLS FIRST LIMIT 1", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is Copycat's race?", "sql": "SELECT T2.race FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id WHERE T1.superhero_name = 'Copycat'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which superheroes have a durability attribute value of less than 50?", "sql": "SELECT superhero_name FROM superhero AS T1 WHERE EXISTS(SELECT 1 FROM hero_attribute AS T2 INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Durability' AND T2.attribute_value < 50 AND T1.id = T2.hero_id)", "complexity_score": 0.0927, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What are the names of the superheroes with the power of death touch?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Death Touch'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many female superheroes have a strength value of 100?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id INNER JOIN gender AS T4 ON T1.gender_id = T4.id WHERE T3.attribute_name = 'Strength' AND T2.attribute_value = 100 AND T4.gender = 'Female'", "complexity_score": 0.1542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the percentage of superheroes who act in their own self-interest or make decisions based on their own moral code? Indicate how many of the said superheroes were published by Marvel Comics.", "sql": "SELECT (CAST(COUNT(*) AS REAL) * 100 / NULLIF((SELECT COUNT(*) FROM superhero), 0)), CAST(SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) AS REAL) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN alignment AS T3 ON T3.id = T1.alignment_id WHERE T3.alignment = 'Bad'", "complexity_score": 0.1885, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Between DC and Marvel Comics, which publisher has published more superheroes? Find the difference in the number of superheroes they have published.", "sql": "SELECT SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.publisher_name = 'DC Comics' THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Give the publisher ID of Star Trek.", "sql": "SELECT id FROM publisher WHERE publisher_name = 'Star Trek'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the total number of superheroes without full name?", "sql": "SELECT COUNT(id) FROM superhero WHERE full_name IS NULL", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the average weight of all female superheroes?", "sql": "SELECT AVG(T1.weight_kg) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id WHERE T2.gender = 'Female'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "List down at least five superpowers of male superheroes.", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T3.id = T2.power_id INNER JOIN gender AS T4 ON T4.id = T1.gender_id WHERE T4.gender = 'Male' LIMIT 5", "complexity_score": 0.1271, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Among the superheroes with height from 170 to 190, list the names of the superheroes with no eye color.", "sql": "SELECT DISTINCT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.height_cm BETWEEN 170 AND 190 AND T2.colour = 'No Colour'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Provide the hair colour of the human superhero who is 185 cm tall.", "sql": "SELECT DISTINCT T3.colour FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T1.height_cm = 185 AND T2.race = 'Human'", "complexity_score": 0.101, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "In superheroes with height between 150 to 180, what is the percentage of heroes published by Marvel Comics?", "sql": "SELECT CAST(COUNT(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.height_cm BETWEEN 150 AND 180", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Among the male superheroes, list the super hero names of superheroes with weight greater than the 79% average weight of all superheroes.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id WHERE T2.gender = 'Male' AND T1.weight_kg * 100 > (SELECT AVG(weight_kg) FROM superhero) * 79", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What are the superpowers of heroes with ID 1?", "sql": "SELECT DISTINCT T2.power_name FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T1.hero_id = 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many heroes have stealth power?", "sql": "SELECT COUNT(T1.hero_id) FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T2.power_name = 'Stealth'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the hero's full name with the highest attribute in strength?", "sql": "SELECT T1.full_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Strength' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which superhero has the most durability published by Dark Horse Comics?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T3.id = T2.attribute_id INNER JOIN publisher AS T4 ON T4.id = T1.publisher_id WHERE T4.publisher_name = 'Dark Horse Comics' AND T3.attribute_name = 'Durability' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.1375, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "List the eyes, hair and skin colour of all female superheroes published by Dark Horse Comics.", "sql": "SELECT T1.eye_colour_id, T1.hair_colour_id, T1.skin_colour_id FROM superhero AS T1 INNER JOIN publisher AS T2 ON T2.id = T1.publisher_id INNER JOIN gender AS T3 ON T3.id = T1.gender_id WHERE T2.publisher_name = 'Dark Horse Comics' AND T3.gender = 'Female'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which superhero has the same eyes, hair and skin colour? Indicate the publisher of the superhero.", "sql": "SELECT T1.superhero_name, T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.eye_colour_id = T1.hair_colour_id AND T1.eye_colour_id = T1.skin_colour_id", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the percentage of blue female superheroes among all female superheroes?", "sql": "SELECT CAST(COUNT(CASE WHEN T3.colour = 'Blue' THEN T1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.gender = 'Female'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many powers does Amazo hero have?", "sql": "SELECT COUNT(T1.power_id) FROM hero_power AS T1 INNER JOIN superhero AS T2 ON T1.hero_id = T2.id WHERE T2.superhero_name = 'Amazo'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Provide the heights of the heroes whose eye colours are amber.", "sql": "SELECT T1.height_cm FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T2.colour = 'Amber'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "List the heroes' names whose eyes and hair colours are both black.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id AND T1.hair_colour_id = T2.id WHERE T2.colour = 'Black'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Describe the names of neutral alignment superheroes.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id WHERE T2.alignment = 'Neutral'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many heroes have the highest attribute value in strength?", "sql": "SELECT COUNT(T1.hero_id) FROM hero_attribute AS T1 INNER JOIN attribute AS T2 ON T1.attribute_id = T2.id WHERE T2.attribute_name = 'Strength' AND T1.attribute_value = (SELECT MAX(attribute_value) FROM hero_attribute)", "complexity_score": 0.1563, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many percent of female heroes were published by Marvel Comics?", "sql": "SELECT CAST(COUNT(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN gender AS T3 ON T1.gender_id = T3.id WHERE T3.gender = 'Female'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Calculate the difference between Emil Blonsky's weight and Charles Chandler's weight.", "sql": "SELECT (SELECT weight_kg FROM superhero WHERE full_name LIKE 'Emil Blonsky') - (SELECT weight_kg FROM superhero WHERE full_name LIKE 'Charles Chandler') AS CALCULATE", "complexity_score": 0.1375, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Calculate the average height for all superhero.", "sql": "SELECT CAST(SUM(height_cm) AS REAL) / NULLIF(COUNT(id), 0) FROM superhero", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is Abomination's superpower?", "sql": "SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T1.superhero_name = 'Abomination'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which hero was the fastest?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Speed' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "State all of 3-D Man's attributes along with their values.", "sql": "SELECT T3.attribute_name, T2.attribute_value FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T1.superhero_name = '3-D Man'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which superheroes have blue eyes with brown hair?", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T2.colour = 'Blue' AND T3.colour = 'Brown'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "What is the publisher for Hawkman, Karate Kid and Speedy?", "sql": "SELECT T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.superhero_name IN ('Hawkman', 'Karate Kid', 'Speedy')", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Calculate the percentage of superheroes with blue eyes.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.colour = 'Blue' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Find the ratio between male superheroes and female superheroes.", "sql": "SELECT CAST(COUNT(CASE WHEN T2.gender = 'Male' THEN T1.id ELSE NULL END) AS REAL) / NULLIF(COUNT(CASE WHEN T2.gender = 'Female' THEN T1.id ELSE NULL END), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Provide the eye colour of the superhero who has Karen Beecher-Duncan as their full name.", "sql": "SELECT T2.colour FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.full_name = 'Karen Beecher-Duncan'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "In superheroes with missing weight data, calculate the difference between the number of superheroes with blue eyes and no eye color.", "sql": "SELECT SUM(CASE WHEN T2.id = 7 THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.id = 1 THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.weight_kg = 0 OR T1.weight_kg IS NULL", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "How many green-skinned villains are there in the superhero universe?", "sql": "SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.alignment = 'Bad' AND T3.colour = 'Green'", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Identify superheroes who can control wind and list their names in alphabetical order.", "sql": "SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Wind Control' ORDER BY T1.superhero_name NULLS FIRST", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Identify the gender of the superhero who has the ability of Phoenix Force.", "sql": "SELECT T4.gender FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN gender AS T4 ON T1.gender_id = T4.id WHERE T3.power_name = 'Phoenix Force'", "complexity_score": 0.1271, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "superhero", "intent": "Which publisher created more superheroes: DC or Marvel Comics? Find the difference in the number of superheroes.", "sql": "SELECT SUM(CASE WHEN T2.publisher_name = 'DC Comics' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which user has a higher reputation, Harlan or Jarrod Dixon?", "sql": "SELECT DisplayName FROM users WHERE DisplayName IN ('Harlan', 'Jarrod Dixon') AND Reputation = (SELECT MAX(Reputation) FROM users WHERE DisplayName IN ('Harlan', 'Jarrod Dixon'))", "complexity_score": 0.1208, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Please list the display names of all the users whose accounts were created in the year 2011.", "sql": "SELECT DisplayName FROM users WHERE TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "How many users last accessed the website after 2014/9/1?", "sql": "SELECT COUNT(Id) FROM users WHERE DATE(LastAccessDate) > '2014-09-01'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Who is the owner of the post \"Eliciting priors from experts\"?", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Title = 'Eliciting priors from experts'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "How many posts does the user csgillespie own?", "sql": "SELECT COUNT(T1.id) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T2.DisplayName = 'csgillespie'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the display name of the user who last edited the post \"Examples for teaching: Correlation does not mean causation\"?", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.LastEditorUserId = T2.Id WHERE T1.Title = 'Examples for teaching: Correlation does not mean causation'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among the posts owned by an elder user, how many of them have a score of over 19?", "sql": "SELECT COUNT(T1.Id) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score >= 20 AND T2.Age > 65", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "From which post is the tag \"bayesian\" excerpted from? Please give the body of the post.", "sql": "SELECT T2.Body FROM tags AS T1 INNER JOIN posts AS T2 ON T2.Id = T1.ExcerptPostId WHERE T1.TagName = 'bayesian'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the average score of the posts owned by the user csgillespie?", "sql": "SELECT AVG(T1.Score) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T2.DisplayName = 'csgillespie'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among the posts with a score of over 5, what is the percentage of them being owned by an elder user?", "sql": "SELECT CAST(SUM(CASE WHEN T2.Age > 65 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score > 5", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "User No.3025 gave a comment at 20:29:39 on 2014/4/23 to a post, how many favorite counts did that post get?", "sql": "SELECT T1.FavoriteCount FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId WHERE T2.CreationDate = '2014-04-23 20:29:39.0' AND T2.UserId = 3025", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "User No.23853 gave a comment to a post at 9:08:18 on 2013/7/12, was that post well-finished?", "sql": "SELECT CASE WHEN T2.ClosedDate IS NULL THEN 'NOT well-finished' ELSE 'well-finished' END AS resylt FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T1.UserId = 23853 AND T1.CreationDate = '2013-07-12 09:08:18.0'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "For the user with the display name of \"Tiago Pasqualini\", how many posts did he/she own?", "sql": "SELECT COUNT(T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Tiago Pasqualini'", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Provide the display name of the user who made the vote No.6347.", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.UserId WHERE T2.Id = 6347", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "For the user No.24, how many times is the number of his/her posts compared to his/her votes?", "sql": "SELECT CAST(COUNT(DISTINCT T2.Id) AS REAL) / NULLIF(COUNT(DISTINCT T1.Id), 0) FROM votes AS T1 INNER JOIN posts AS T2 ON T1.UserId = T2.OwnerUserId WHERE T1.UserId = 24", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "How many views did the post titled 'Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer' get?", "sql": "SELECT ViewCount FROM posts WHERE Title = 'Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Write the contents of comments with a score of 17.", "sql": "SELECT Text FROM comments WHERE Score = 17", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Name the user that commented 'thank you user93!'", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.UserId WHERE T2.Text = 'thank you user93!'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which user made a post titled 'Understanding what Dassault iSight is doing?' and how much is the reputation of the user?", "sql": "SELECT T1.DisplayName, T1.Reputation FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T2.Title = 'Understanding what Dassault iSight is doing?'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Who is the owner of the post titled 'Open source tools for visualizing multi-dimensional data?'", "sql": "SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Title = 'Open source tools for visualizing multi-dimensional data?'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Write all the comments left by users who edited the post titled 'Why square the difference instead of taking the absolute value in standard deviation?'", "sql": "SELECT T2.Comment FROM posts AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.PostId WHERE T1.Title = 'Why square the difference instead of taking the absolute value in standard deviation?'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which user added a bounty amount of 50 to the post title mentioning variance?", "sql": "SELECT T3.DisplayName, T1.Title FROM posts AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.PostId INNER JOIN users AS T3 ON T3.Id = T2.UserId WHERE T2.BountyAmount = 50 AND T1.Title LIKE '%variance%'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Calculate the average view count of each post tagged as 'humor' and list the title and the comment of each post.", "sql": "SELECT AVG(T2.ViewCount) AS AverageViewCount, T2.Title, T1.Text FROM comments AS T1 INNER JOIN posts AS T2 ON T2.Id = T1.PostId WHERE T2.Tags = '' GROUP BY T2.Title, T1.Text", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "How many users are awarded with more than 5 badges?", "sql": "SELECT COUNT(UserId) FROM (SELECT UserId, COUNT(Name) AS num FROM badges GROUP BY UserId) AS T WHERE T.num > 5", "complexity_score": 0.1094, "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which user have only one post history per post and having at least 1000 views?", "sql": "SELECT T2.UserId FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T3.ViewCount >= 1000 GROUP BY T2.UserId HAVING COUNT(DISTINCT T2.PostHistoryTypeId) = 1", "complexity_score": 0.1042, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the percentage difference of student badges given during 2010 and 2011?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) - CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) FROM badges WHERE Name = 'Student'", "complexity_score": 0.0427, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the average of the up votes and the average user age for users creating more than 10 posts?", "sql": "SELECT AVG(T1.UpVotes), AVG(T1.Age) FROM users AS T1 INNER JOIN (SELECT OwnerUserId, COUNT(*) AS post_count FROM posts GROUP BY OwnerUserId HAVING COUNT(*) > 10) AS T2 ON T1.Id = T2.OwnerUserId", "complexity_score": 0.1583, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 4, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Calculate the ratio of votes in 2010 and 2011.", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END), 0) FROM votes", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which post by slashnick has the most answers count? State the post ID.", "sql": "SELECT T2.PostId FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.DisplayName = 'slashnick' ORDER BY T3.AnswerCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among posts by Harvey Motulsky and Noah Snyder, which one has higher popularity?", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.DisplayName = 'Harvey Motulsky' OR T1.DisplayName = 'Noah Snyder' GROUP BY T1.DisplayName ORDER BY SUM(T3.ViewCount) DESC NULLS LAST LIMIT 1", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "State all the tags used by Mark Meckes in his posts that doesn't have comments.", "sql": "SELECT T3.Tags FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId WHERE T1.DisplayName = 'Mark Meckes' AND T3.CommentCount = 0", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Based on posts posted by Community, calculate the percentage of posts that use the R language.", "sql": "SELECT CAST(SUM(CASE WHEN T3.TagName = 'r' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN tags AS T3 ON T3.ExcerptPostId = T2.PostId WHERE T1.DisplayName = 'Community'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Calculate the difference in view count from post posted by Mornington and view count from posts posted by Amos.", "sql": "SELECT SUM(CASE WHEN T1.DisplayName = 'Mornington' THEN T3.ViewCount ELSE 0 END) - SUM(CASE WHEN T1.DisplayName = 'Amos' THEN T3.ViewCount ELSE 0 END) AS diff FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId", "complexity_score": 0.0958, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the average monthly number of links created in 2010 for posts that have no more than 2 answers?", "sql": "SELECT CAST(COUNT(T1.Id) AS REAL) / NULLIF(12, 0) FROM postLinks AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.AnswerCount <= 2 AND TO_CHAR(CAST(T1.CreationDate AS TIMESTAMP), 'YYYY') = '2010'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "When did 'chl' cast its first vote in a post?", "sql": "SELECT T2.CreationDate FROM users AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.UserId WHERE T1.DisplayName = 'chl' ORDER BY T2.CreationDate NULLS FIRST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the display name of the user who acquired the first Autobiographer badge?", "sql": "SELECT T1.DisplayName FROM users AS T1 INNER JOIN badges AS T2 ON T1.Id = T2.UserId WHERE T2.name = 'Autobiographer' ORDER BY T2.Date LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among the users located in United Kingdom, how many users whose post have a total favorite amount of 4 or more?", "sql": "SELECT COUNT(T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.Location = 'United Kingdom' AND T2.FavoriteCount >= 4", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which post by Harvey Motulsky has the most views? Please give the id and title of this post.", "sql": "SELECT T2.Id, T2.Title FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Harvey Motulsky' ORDER BY T2.ViewCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Which is the most valuable post in 2010? Please give its id and the owner's display name.", "sql": "SELECT T2.OwnerUserId, T1.DisplayName FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE TO_CHAR(CAST(T1.CreationDate AS TIMESTAMP), 'YYYY') = '2010' ORDER BY T2.FavoriteCount DESC NULLS LAST LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the percentage of posts whose owners had a reputation of over 1000 in 2011?", "sql": "SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(T2.CreaionDate AS TIMESTAMP), 'YYYY') = '2011' AND T1.Reputation > 1000 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId", "complexity_score": 0.0698, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Identify the total views on the post 'Computer Game Datasets'. Name the user who posted it last time.", "sql": "SELECT T2.ViewCount, T3.DisplayName FROM postHistory AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id INNER JOIN users AS T3 ON T2.LastEditorUserId = T3.Id WHERE T1.Text = 'Computer Game Datasets'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "How many comments were added to the post with the highest score?", "sql": "SELECT COUNT(T2.Id) FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId GROUP BY T1.Id ORDER BY T1.Score DESC NULLS LAST LIMIT 1", "complexity_score": 0.0531, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Provide the text of the latest 10 comments to the post with the title 'Analysing wind data with R' and the display name of the user who left it.", "sql": "SELECT T3.Text, T1.DisplayName FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId INNER JOIN comments AS T3 ON T2.Id = T3.PostId WHERE T2.Title = 'Analysing wind data with R' ORDER BY T1.CreationDate DESC NULLS LAST LIMIT 10", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among all the posts posted by the most influential user, identify the percentage with a score above 50.", "sql": "SELECT CAST(SUM(CASE WHEN T2.Score > 50 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId INNER JOIN (SELECT MAX(Reputation) AS max_reputation FROM users) AS T3 ON T1.Reputation = T3.max_reputation", "complexity_score": 0.1708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "What is the excerpt post ID and wiki post ID of the tag named sample?", "sql": "SELECT ExcerptPostId, WikiPostId FROM tags WHERE TagName = 'sample'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Give the user's reputation and up vote number of the user that commented \"fine, you win :)\".", "sql": "SELECT T2.Reputation, T2.UpVotes FROM comments AS T1 INNER JOIN users AS T2 ON T1.UserId = T2.Id WHERE T1.Text = 'fine, you win :)'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among the posts with views ranging from 100 to 150, what is the comment with the highest score?", "sql": "SELECT Text FROM comments WHERE PostId IN (SELECT Id FROM posts WHERE ViewCount BETWEEN 100 AND 150) ORDER BY Score DESC NULLS LAST LIMIT 1", "complexity_score": 0.1146, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "In posts with 1 comment, how many of the comments have 0 score?", "sql": "SELECT COUNT(T1.id) FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.CommentCount = 1 AND T2.Score = 0", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "codebase_community", "intent": "Among the comments with scores between 5 to 10, what is the percentage of the users with 0 up votes?", "sql": "SELECT CAST(SUM(CASE WHEN T1.UpVotes = 0 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) AS per FROM users AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.UserId WHERE T2.Score BETWEEN 5 AND 10", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which are the cards that have incredibly powerful foils.", "sql": "SELECT id FROM cards WHERE NOT cardKingdomFoilId IS NULL AND NOT cardKingdomId IS NULL", "complexity_score": 0.0281, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What are the borderless cards available without powerful foils?", "sql": "SELECT id FROM cards WHERE borderColor = 'borderless' AND (cardKingdomId IS NULL OR cardKingdomId IS NULL)", "complexity_score": 0.0385, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "List all the mythic rarity print cards banned in gladiator format.", "sql": "SELECT DISTINCT T1.id FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.format = 'gladiator' AND T2.status = 'Banned' AND T1.rarity = 'mythic'", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "For artifact type of cards that do not have multiple faces on the same card, state its legalities status for vintage play format.", "sql": "SELECT DISTINCT T2.status FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.type = 'Artifact' AND T2.format = 'vintage' AND T1.side IS NULL", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "List all the card id and artist with unknown power which are legal for commander play format.", "sql": "SELECT T1.id, T1.artist FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.status = 'Legal' AND T2.format = 'commander' AND (T1.power IS NULL OR T1.power = '*')", "complexity_score": 0.0854, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Find all cards illustrated by Stephen Daniel and describe the text of the ruling of these cards. State if these cards have missing or degraded properties and values.", "sql": "SELECT T1.id, T2.text, T1.hasContentWarning FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE T1.artist = 'Stephen Daniele'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Name the card and artist with the most ruling information. Also state if the card is a promotional printing.", "sql": "SELECT T1.name, T1.artist, T1.isPromo FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE T1.isPromo = 1 AND T1.artist = (SELECT artist FROM cards WHERE isPromo = 1 GROUP BY artist HAVING COUNT(DISTINCT uuid) = (SELECT MAX(count_uuid) FROM (SELECT COUNT(DISTINCT uuid) AS count_uuid FROM cards WHERE isPromo = 1 GROUP BY artist) AS subquery)) LIMIT 1", "complexity_score": 0.3427, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "LIMIT", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 3, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Calculate the percentage of the cards availabe in Chinese Simplified.", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'Chinese Simplified' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid", "complexity_score": 0.0594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "How many cards have infinite power?", "sql": "SELECT COUNT(*) FROM cards WHERE power = '*'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the border color of card \"Ancestor's Chosen\"?", "sql": "SELECT DISTINCT borderColor FROM cards WHERE name = 'Ancestor''s Chosen'", "complexity_score": 0.0177, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the rule of playing card \"Benalish Knight\"?", "sql": "SELECT T2.format FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.name = 'Benalish Knight'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the percentage of borderless cards?", "sql": "SELECT CAST(SUM(CASE WHEN borderColor = 'borderless' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the percentage of cards whose language is French among the Story Spotlight cards?", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'French' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.isStorySpotlight = 1", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "How many cards with original type of \"Summon - Angel\" have subtype other than \"Angel\"?", "sql": "SELECT COUNT(id) FROM cards WHERE originalType = 'Summon - Angel' AND subtypes <> 'Angel'", "complexity_score": 0.0344, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What are the cards belong to duel deck a? List the ID.", "sql": "SELECT id FROM cards WHERE duelDeck = 'a'", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "How many of the banned cards are white border?", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.status = 'Banned' AND T1.borderColor = 'white'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Among the Artifact cards, which are black color and comes with foreign languague translation?", "sql": "SELECT DISTINCT T1.name FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.originalType = 'Artifact' AND T1.colors = 'B'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the mana cost of cards with a normal layout, a 2003 frame version, with a black border color, and available in paper and mtgo?", "sql": "SELECT manaCost FROM cards WHERE availability = 'mtgo,paper' AND borderColor = 'black' AND frameVersion = '2003' AND layout = 'normal'", "complexity_score": 0.049, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the percentage of Story Spotlight cards that do not have a text box? List them by their ID.", "sql": "SELECT CAST(SUM(CASE WHEN isTextless = 0 AND isStorySpotlight = 1 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards", "complexity_score": 0.0333, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "How many Brazilian Portuguese translated sets are inside the Commander block?", "sql": "SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T2.language = 'Portuguese (Brazil)' AND T1.block = 'Commander'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Lists all types of cards in German.", "sql": "SELECT T1.subtypes, T1.supertypes FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T2.language = 'German' AND NOT T1.subtypes IS NULL AND NOT T1.supertypes IS NULL", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "How many unknown power cards contain info about the triggered ability", "sql": "SELECT Count(DISTINCT T1.id) FROM cards AS T1 INNER JOIN rulings AS T2 ON T1.uuid = T2.uuid WHERE (T1.power IS NULL OR T1.power = '*') AND T2.text LIKE '%triggered ability%'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Indicates the number of cards with pre-modern format, ruling text \"This is a triggered mana ability.\" that do not have multiple faces.", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid INNER JOIN rulings AS T3 ON T1.uuid = T3.uuid WHERE T2.format = 'premodern' AND T3.text = 'This is a triggered mana ability.' AND T1.Side IS NULL", "complexity_score": 0.1177, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the foreign name of the card in French of type Creature, normal layout and black border color, by artist Matthew D. Wilson?", "sql": "SELECT name FROM foreign_data WHERE uuid IN (SELECT uuid FROM cards WHERE types = 'Creature' AND layout = 'normal' AND borderColor = 'black' AND artist = 'Matthew D. Wilson') AND language = 'French'", "complexity_score": 0.1563, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What language is the set of 180 cards that belongs to the Ravnica block translated into?", "sql": "SELECT T2.language FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T1.block = 'Ravnica' AND T1.baseSetSize = 180", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What percentage of cards with format commander and legal status do not have a content warning?", "sql": "SELECT CAST(SUM(CASE WHEN T1.hasContentWarning = 0 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.format = 'commander' AND T2.status = 'Legal'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What percentage of cards without power are in French?", "sql": "SELECT CAST(SUM(CASE WHEN T2.language = 'French' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.power IS NULL OR T1.power = '*'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the language of the card with the multiverse number 149934?", "sql": "SELECT language FROM foreign_data WHERE multiverseid = 149934", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What proportion of cards do not have a text box with a normal layout?", "sql": "SELECT CAST(SUM(CASE WHEN isTextless = 1 AND layout = 'normal' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM cards", "complexity_score": 0.0333, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What languages are available in the set known as Archenemy on the magic card market and having the code ARC?", "sql": "SELECT T2.language FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T1.mcmName = 'Archenemy' AND T2.setCode = 'ARC'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which foreign language used by \"A Pedra Fellwar\"?", "sql": "SELECT DISTINCT language FROM foreign_data WHERE name = 'A Pedra Fellwar'", "complexity_score": 0.0177, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which card costs more converted mana, \"Serra Angel\" or \"Shrine Keeper\"?", "sql": "SELECT name FROM cards WHERE name IN ('Serra Angel', 'Shrine Keeper') ORDER BY convertedManaCost DESC NULLS LAST LIMIT 1", "complexity_score": 0.0177, "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What's the Italian name of the set of cards with \"Ancestor's Chosen\" is in?", "sql": "SELECT translation FROM set_translations WHERE setCode IN (SELECT setCode FROM cards WHERE name = 'Ancestor''s Chosen') AND language = 'Italian'", "complexity_score": 0.125, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "For the set of cards with \"Ancestor's Chosen\" in it, is there a Korean version of it?", "sql": "SELECT CASE WHEN SUM(CASE WHEN T2.language = 'Korean' AND NOT T2.translation IS NULL THEN 1 ELSE 0 END) > 0 THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.setCode WHERE T1.name = 'Ancestor''s Chosen'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Among the cards in the set \"Hauptset Zehnte Edition\", how many of them are designed by Adam Rex?", "sql": "SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.setCode WHERE T2.translation = 'Hauptset Zehnte Edition' AND T1.artist = 'Adam Rex'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the Simplified Chinese translation of the name of the set \"Eighth Edition\"?", "sql": "SELECT T2.translation FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE T1.name = 'Eighth Edition' AND T2.language = 'Chinese Simplified'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Did the set of cards with \"Angel of Mercy\" appear on Magic: The Gathering Online?", "sql": "SELECT CASE WHEN NOT T2.mtgoCode IS NULL THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T1.name = 'Angel of Mercy'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Among the sets in the block \"Ice Age\", how many of them have an Italian translation?", "sql": "SELECT COUNT(DISTINCT T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE T1.block = 'Ice Age' AND T2.language = 'Italian' AND NOT T2.translation IS NULL", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Is the set of cards with Adarkar Valkyrie only available outside the United States?", "sql": "SELECT CASE WHEN isForeignOnly = 1 THEN 'YES' ELSE 'NO' END FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T1.name = 'Adarkar Valkyrie'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Among the sets of cards that have an Italian translation, how many of them have a base set number of under 100?", "sql": "SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE NOT T2.translation IS NULL AND T1.baseSetSize < 100 AND T2.language = 'Italian'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which of these artists have designed a card in the set Coldsnap, Jeremy Jarvis, Aaron Miller or Chippy?", "sql": "SELECT T1.artist FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE (T2.name = 'Coldsnap' AND T1.artist = 'Chippy') OR (T2.name = 'Coldsnap' AND T1.artist = 'Aaron Miller') OR (T2.name = 'Coldsnap' AND T1.artist = 'Jeremy Jarvis') GROUP BY T1.artist", "complexity_score": 0.1063, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Among the cards with converted mana cost higher than 5 in the set Coldsnap, how many of them have unknown power?", "sql": "SELECT SUM(CASE WHEN T1.power = '*' OR T1.power IS NULL THEN 1 ELSE 0 END) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap' AND T1.convertedManaCost > 5", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the Italian flavor text of the card \"Ancestor's Chosen\"?", "sql": "SELECT T2.flavorText FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T2.uuid = T1.uuid WHERE T1.name = 'Ancestor''s Chosen' AND T2.language = 'Italian'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Please list the Italian text ruling of all the cards in the set Coldsnap.", "sql": "SELECT DISTINCT T1.text FROM foreign_data AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid INNER JOIN sets AS T3 ON T3.code = T2.setCode WHERE T3.name = 'Coldsnap' AND T1.language = 'Italian'", "complexity_score": 0.101, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Please list the Italian names of the cards in the set Coldsnap with the highest converted mana cost.", "sql": "SELECT T2.name FROM foreign_data AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid INNER JOIN sets AS T3 ON T3.code = T2.setCode WHERE T3.name = 'Coldsnap' AND T1.language = 'Italian' ORDER BY T2.convertedManaCost DESC NULLS LAST", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the percentage of the cards with a converted mana cost of 7 in the set Coldsnap?", "sql": "SELECT CAST(SUM(CASE WHEN T1.convertedManaCost = 7 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "What is the percentage of incredibly powerful cards in the set Coldsnap?", "sql": "SELECT CAST(SUM(CASE WHEN NOT T1.cardKingdomFoilId IS NULL AND NOT T1.cardKingdomId IS NULL THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'", "complexity_score": 0.0771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which of the play format has the highest number of banned status? Indicate the play format and the names of all the card meet the condition.", "sql": "WITH MaxBanned AS (SELECT format FROM legalities WHERE status = 'Banned' GROUP BY format ORDER BY COUNT(*) DESC LIMIT 1)SELECT T2.format, T1.name FROM cards AS T1 INNER JOIN legalities AS T2 ON T2.uuid = T1.uuid INNER JOIN MaxBanned MB ON MB.format = T2.format WHERE T2.status = 'Banned'", "complexity_score": 0.15, "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["CTE", "FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE", "WITH"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 1, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Which cards are ranked 1st on EDHRec? List all of the cards name and its banned play format.", "sql": "SELECT T1.name, T2.format FROM cards AS T1 INNER JOIN legalities AS T2 ON T2.uuid = T1.uuid WHERE T1.edhrecRank = 1 AND T2.status = 'Banned' GROUP BY T1.name, T2.format", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "List the names of all the cards in the set Hour of Devastation and find the formats in which these cards are legal.", "sql": "SELECT DISTINCT T2.name, CASE WHEN T1.status = 'Legal' THEN T1.format ELSE NULL END FROM legalities AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid WHERE T2.setCode IN (SELECT code FROM sets WHERE name = 'Hour of Devastation')", "complexity_score": 0.151, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "Find and list the names of sets which doesn't have Japanese translation but have Korean translation.", "sql": "SELECT name FROM sets WHERE code IN (SELECT setCode FROM set_translations WHERE language = 'Korean' AND NOT language LIKE '%Japanese%')", "complexity_score": 0.125, "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", "clauses_present": ["FROM", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "card_games", "intent": "List all the frame styles and cards Allen Williams worked on and find any banned cards if there are any.", "sql": "SELECT DISTINCT T1.frameVersion, T1.name, CASE WHEN T2.status = 'Banned' THEN T1.name ELSE 'NO' END FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.artist = 'Allen Williams'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the most common bond type?", "sql": "SELECT T.bond_type FROM (SELECT bond_type, COUNT(bond_id) FROM bond GROUP BY bond_type ORDER BY COUNT(bond_id) DESC NULLS LAST LIMIT 1) AS T", "complexity_score": 0.1021, "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "SUBQUERY"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Calculate the average number of oxygen atoms in single-bonded molecules.", "sql": "SELECT AVG(oxygen_count) FROM (SELECT T1.molecule_id, COUNT(T1.element) AS oxygen_count FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '-' AND T1.element = 'o' GROUP BY T1.molecule_id) AS oxygen_counts", "complexity_score": 0.1563, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "On average how many carcinogenic molecules are single bonded?", "sql": "SELECT AVG(single_bond_count) FROM (SELECT T3.molecule_id, COUNT(T1.bond_type) AS single_bond_count FROM bond AS T1 INNER JOIN atom AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN molecule AS T3 ON T3.molecule_id = T2.molecule_id WHERE T1.bond_type = '-' AND T3.label = '+' GROUP BY T3.molecule_id) AS subquery", "complexity_score": 0.1927, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Find the triple-bonded molecules which are carcinogenic.", "sql": "SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '#' AND T2.label = '+'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the percentage of carbon in double-bond molecules?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T1.element = 'c' THEN T1.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T1.atom_id), 0) FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '='", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What elements are in the TR004_8_9 bond atoms?", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id = 'TR004_8_9'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What elements are in a double type bond?", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN connected AS T3 ON T1.atom_id = T3.atom_id WHERE T2.bond_type = '='", "complexity_score": 0.0906, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Which type of label is the most numerous in atoms with hydrogen?", "sql": "SELECT T.label FROM (SELECT T2.label, COUNT(T2.molecule_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.element = 'h' GROUP BY T2.label ORDER BY COUNT(T2.molecule_id) DESC NULLS LAST LIMIT 1) AS t", "complexity_score": 0.1458, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Which element is the least numerous in non-carcinogenic molecules?", "sql": "SELECT T.element FROM (SELECT T1.element, COUNT(DISTINCT T1.molecule_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '-' GROUP BY T1.element ORDER BY COUNT(DISTINCT T1.molecule_id) ASC NULLS FIRST LIMIT 1) AS t", "complexity_score": 0.1458, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What type of bond is there between the atoms TR004_8 and TR004_20?", "sql": "SELECT T1.bond_type FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.atom_id = 'TR004_8' AND T2.atom_id2 = 'TR004_20' OR T2.atom_id2 = 'TR004_8' AND T2.atom_id = 'TR004_20'", "complexity_score": 0.0854, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "How many atoms with iodine and with sulfur type elements are there in single bond molecules?", "sql": "SELECT COUNT(DISTINCT CASE WHEN T1.element = 'i' THEN T1.atom_id ELSE NULL END) AS iodine_nums, COUNT(DISTINCT CASE WHEN T1.element = 's' THEN T1.atom_id ELSE NULL END) AS sulfur_nums FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_type = '-'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What percentage of carcinogenic-type molecules does not contain fluorine?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T1.element <> 'f' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the percentage of carcinogenic molecules in triple type bonds?", "sql": "SELECT CAST(COUNT(DISTINCT CASE WHEN T2.label = '+' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '#'", "complexity_score": 0.1031, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Please list top three elements of the toxicology of the molecule TR000 in alphabetical order.", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE T.molecule_id = 'TR000' ORDER BY T.element NULLS FIRST LIMIT 3", "complexity_score": 0.0177, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the percentage of double bonds in the molecule TR008? Please provide your answer as a percentage with five decimal places.", "sql": "SELECT ROUND(CAST(COUNT(CASE WHEN T.bond_type = '=' THEN T.bond_id ELSE NULL END) AS NUMERIC) * 100 / CAST(COUNT(T.bond_id) AS NUMERIC), 5) AS percentage FROM bond AS T WHERE T.molecule_id = 'TR008'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the percentage of molecules that are carcinogenic? Please provide your answer as a percentage with three decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN t.label = '+' THEN t.molecule_id ELSE NULL END) AS REAL) / NULLIF(COUNT(t.molecule_id), 0) * 100) AS NUMERIC), 3) AS percentage FROM molecule t", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "How much of the hydrogen in molecule TR206 is accounted for? Please provide your answer as a percentage with four decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN T.element = 'h' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0)) AS NUMERIC), 4) AS percentage FROM atom AS T WHERE T.molecule_id = 'TR206'", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the elements of the toxicology and label of molecule TR060?", "sql": "SELECT DISTINCT T1.element, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR060'", "complexity_score": 0.0542, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Which bond type accounted for the majority of the bonds found in molecule TR010 and state whether or not this molecule is carcinogenic?", "sql": "SELECT T.bond_type FROM (SELECT T1.bond_type, COUNT(T1.molecule_id) FROM bond AS T1 WHERE T1.molecule_id = 'TR010' GROUP BY T1.bond_type ORDER BY COUNT(T1.molecule_id) DESC NULLS LAST LIMIT 1) AS T", "complexity_score": 0.1094, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 0, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Please list top three molecules that have single bonds between two atoms and are not carcinogenic in alphabetical order.", "sql": "SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '-' AND T2.label = '-' ORDER BY T2.molecule_id NULLS FIRST LIMIT 3", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "How many bonds which involved atom 12 does molecule TR009 have?", "sql": "SELECT COUNT(T2.bond_id) FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T1.molecule_id = 'TR009' AND T2.atom_id = T1.molecule_id || '_1' OR T2.atom_id2 = T1.molecule_id || '_2'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the bond type and the atoms of the bond ID of TR001_6_9?", "sql": "SELECT T1.bond_type, T2.atom_id, T2.atom_id2 FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.bond_id = 'TR001_6_9'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "How many connections does the atom 19 have?", "sql": "SELECT COUNT(T.bond_id) FROM connected AS T WHERE RIGHT(T.atom_id, 2) = '19'", "complexity_score": 0.024, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "List all the elements of the toxicology of the molecule \"TR004\".", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE T.molecule_id = 'TR004'", "complexity_score": 0.0177, "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", "clauses_present": ["DISTINCT", "FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Among all the atoms from 21 to 25, list all the molecules that are carcinogenic.", "sql": "SELECT DISTINCT T2.molecule_id FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE RIGHT(T1.atom_id, 2) BETWEEN '21' AND '25' AND T2.label = '+'", "complexity_score": 0.0646, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the bonds that have phosphorus and nitrogen as their atom elements?", "sql": "SELECT T2.bond_id FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id IN (SELECT T3.bond_id FROM connected AS T3 INNER JOIN atom AS T4 ON T3.atom_id = T4.atom_id WHERE T4.element = 'p') AND T1.element = 'n'", "complexity_score": 0.1771, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Is the molecule with the most double bonds carcinogenic?", "sql": "SELECT T1.label FROM molecule AS T1 INNER JOIN (SELECT T.molecule_id, COUNT(T.bond_type) FROM bond AS T WHERE T.bond_type = '=' GROUP BY T.molecule_id ORDER BY COUNT(T.bond_type) DESC NULLS LAST LIMIT 1) AS T2 ON T1.molecule_id = T2.molecule_id", "complexity_score": 0.1458, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the average number of bonds the atoms with the element iodine have?", "sql": "SELECT CAST(COUNT(T2.bond_id) AS REAL) / NULLIF(COUNT(T1.atom_id), 0) FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T1.element = 'i'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "List all the elements of atoms that can not bond with any other atoms.", "sql": "SELECT DISTINCT T.element FROM atom AS T WHERE NOT T.element IN (SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id)", "complexity_score": 0.1333, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the atoms of the triple bond with the molecule \"TR041\"?", "sql": "SELECT T2.atom_id, T2.atom_id2 FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_type = '#' AND T3.molecule_id = 'TR041'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the elements of the atoms of TR144_8_19?", "sql": "SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR144_8_19'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "List the elements of all the triple bonds.", "sql": "SELECT DISTINCT T3.element FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id INNER JOIN atom AS T3 ON T2.atom_id = T3.atom_id WHERE T1.bond_type = '#'", "complexity_score": 0.0906, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What proportion of single bonds are carcinogenic? Please provide your answer as a percentage with five decimal places.", "sql": "SELECT ROUND(CAST((CAST(COUNT(CASE WHEN T2.label = '+' THEN T1.bond_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.bond_id), 0)) AS NUMERIC), 5) AS percentage FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '-'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Calculate the total atoms with triple-bond molecules containing the element phosphorus or bromine.", "sql": "SELECT COUNT(T1.atom_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '#' AND T1.element IN ('p', 'br')", "complexity_score": 0.1073, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the composition of element chlorine in percentage among the single bond molecules?", "sql": "SELECT CAST(COUNT(CASE WHEN T.element = 'cl' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0) FROM (SELECT T1.atom_id, T1.element FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '-') AS T", "complexity_score": 0.1823, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What are the elements for bond id TR001_10_11?", "sql": "SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR001_10_11'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the percentage of element chlorine in carcinogenic molecules?", "sql": "SELECT CAST(COUNT(CASE WHEN T1.element = 'cl' THEN T1.element ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.element), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+'", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Tally the toxicology element of the 4th atom of each molecule that was carcinogenic.", "sql": "SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+' AND RIGHT(T1.atom_id, 1) = '4' AND LENGTH(T1.atom_id) = 7", "complexity_score": 0.075, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "What is the ratio of Hydrogen elements in molecule ID TR006? List the ratio with its label.", "sql": "WITH SubQuery AS (SELECT DISTINCT T1.atom_id, T1.element, T1.molecule_id, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR006') SELECT CAST(COUNT(CASE WHEN element = 'h' THEN atom_id ELSE NULL END) AS REAL) / NULLIF(COUNT(atom_id), 0) AS ratio, label FROM SubQuery GROUP BY label", "complexity_score": 0.1229, "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["CTE", "DISTINCT", "FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE", "WITH"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 1, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "toxicology", "intent": "Which non-carcinogenic molecules consisted more than 5 atoms?", "sql": "SELECT T.molecule_id FROM (SELECT T1.molecule_id, COUNT(T2.atom_id) FROM molecule AS T1 INNER JOIN atom AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.label = '-' GROUP BY T1.molecule_id HAVING COUNT(T2.atom_id) > 5) AS t", "complexity_score": 0.1531, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-SUBQUERY", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "How many schools with an average score in Math greater than 400 in the SAT test are exclusively virtual?", "sql": "SELECT COUNT(DISTINCT T2.School) FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.Virtual = 'F' AND T1.AvgScrMath > 400", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Please list the codes of the schools with a total enrollment of over 500.", "sql": "SELECT T2.CDSCode FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.\"Enrollment (K-12)\" + T2.\"Enrollment (Ages 5-17)\" > 500", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Among the schools with an SAT excellence rate of over 0.3, what is the highest eligible free rate for students aged 5-17?", "sql": "SELECT MAX(CAST(T1.\"Free Meal Count (Ages 5-17)\" AS REAL) / NULLIF(T1.\"Enrollment (Ages 5-17)\", 0)) FROM frpm AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE CAST(T2.NumGE1500 AS REAL) / NULLIF(T2.NumTstTakr, 0) > 0.3", "complexity_score": 0.0604, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Rank schools by their average score in Writing where the score is greater than 499, showing their charter numbers.", "sql": "SELECT CharterNum, AvgScrWrite, RANK() OVER (ORDER BY AvgScrWrite DESC NULLS LAST) AS WritingScoreRank FROM schools AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T2.AvgScrWrite > 499 AND NOT CharterNum IS NULL", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "List the names of schools with more than 30 difference in enrollements between K-12 and ages 5-17? Please also give the full street adress of the schools.", "sql": "SELECT T1.School, T1.Street FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.\"Enrollment (K-12)\" - T2.\"Enrollment (Ages 5-17)\" > 30", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Give the names of the schools with the percent eligible for free meals in K-12 is more than 0.1 and test takers whose test score is greater than or equal to 1500?", "sql": "SELECT T2.\"School Name\" FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE CAST(T2.\"Free Meal Count (K-12)\" AS REAL) / NULLIF(T2.\"Enrollment (K-12)\", 0) > 0.1 AND T1.NumGE1500 > 0", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Name schools in Riverside which the average of average math score for SAT is grater than 400, what is the funding type of these schools?", "sql": "SELECT T1.sname, T2.\"Charter Funding Type\" FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE T2.\"District Name\" LIKE 'Riverside%' GROUP BY T1.sname, T2.\"Charter Funding Type\" HAVING CAST(SUM(T1.AvgScrMath) AS REAL) / NULLIF(COUNT(T1.cds), 0) > 400", "complexity_score": 0.074, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING", "clauses_present": ["FROM", "GROUP", "HAVING", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "State the names and full communication address of high schools in Monterey which has more than 800 free or reduced price meals for ages 15-17?", "sql": "SELECT T1.\"School Name\", T2.Street, T2.City, T2.State, T2.Zip FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Monterey' AND T1.\"Free Meal Count (Ages 5-17)\" > 800 AND T1.\"School Type\" = 'High Schools (Public)'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the average score in writing for the schools that were opened after 1991 or closed before 2000? List the school names along with the score. Also, list the communication number of the schools if there is any.", "sql": "SELECT T2.School, T1.AvgScrWrite, T2.Phone FROM schools AS T2 LEFT JOIN satscores AS T1 ON T2.CDSCode = T1.cds WHERE TO_CHAR(CAST(T2.OpenDate AS TIMESTAMP), 'YYYY') > '1991' OR TO_CHAR(CAST(T2.ClosedDate AS TIMESTAMP), 'YYYY') < '2000'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-WHERE", "clauses_present": ["FROM", "JOIN", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Consider the average difference between K-12 enrollment and 15-17 enrollment of schools that are locally funded, list the names and DOC type of schools which has a difference above this average.", "sql": "SELECT T2.School, T2.DOC FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.FundingType = 'Locally funded' AND (T1.\"Enrollment (K-12)\" - T1.\"Enrollment (Ages 5-17)\") > (SELECT AVG(T3.\"Enrollment (K-12)\" - T3.\"Enrollment (Ages 5-17)\") FROM frpm AS T3 INNER JOIN schools AS T4 ON T3.CDSCode = T4.CDSCode WHERE T4.FundingType = 'Locally funded')", "complexity_score": 0.1833, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 2, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the eligible free rate of the 10th and 11th schools with the highest enrolment for students in grades 1 through 12?", "sql": "SELECT CAST(\"Free Meal Count (K-12)\" AS REAL) / NULLIF(\"Enrollment (K-12)\", 0) FROM frpm ORDER BY \"Enrollment (K-12)\" DESC NULLS LAST LIMIT 2 OFFSET 9", "complexity_score": 0.0104, "pattern_signature": "SELECT-FROM-ORDER-LIMIT-OFFSET", "clauses_present": ["FROM", "LIMIT", "OFFSET", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the eligible free or reduced price meal rate for the top 5 schools in grades 1-12 with the highest free or reduced price meal count of the schools with the ownership code 66?", "sql": "SELECT CAST(T1.\"FRPM Count (K-12)\" AS REAL) / NULLIF(T1.\"Enrollment (K-12)\", 0) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.SOC::integer = 66 ORDER BY T1.\"FRPM Count (K-12)\" DESC NULLS LAST LIMIT 5", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the complete address of the school with the lowest excellence rate? Indicate the Street, City, Zip and State.", "sql": "SELECT T2.Street, T2.City, T2.State, T2.Zip FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY CAST(T1.NumGE1500 AS REAL) / NULLIF(T1.NumTstTakr, 0) ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Under whose administration is the school with the highest number of students scoring 1500 or more on the SAT? Indicate their full names.", "sql": "SELECT T2.AdmFName1, T2.AdmLName1, T2.AdmFName2, T2.AdmLName2, T2.AdmFName3, T2.AdmLName3 FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.NumGE1500 DESC NULLS LAST LIMIT 1", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the average number of test takers from Fresno schools that opened between 1/1/1980 and 12/31/1980?", "sql": "SELECT AVG(T1.NumTstTakr) FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE TO_CHAR(CAST(T2.OpenDate AS TIMESTAMP), 'YYYY') = '1980' AND T2.County = 'Fresno'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the telephone number for the school with the lowest average score in reading in Fresno Unified?", "sql": "SELECT T2.Phone FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.District = 'Fresno Unified' AND NOT T1.AvgScrRead IS NULL ORDER BY T1.AvgScrRead ASC NULLS FIRST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "List the names of virtual schools that are among the top 5 in their respective counties based on average reading scores.", "sql": "SELECT School FROM (SELECT T2.School, T1.AvgScrRead, RANK() OVER (PARTITION BY T2.County ORDER BY T1.AvgScrRead DESC NULLS LAST) AS rnk FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.Virtual = 'F') AS ranked_schools WHERE rnk <= 5", "complexity_score": 0.1469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "ORDER", "SELECT", "SUBQUERY", "WHERE", "WINDOW"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the average writing score of each of the schools managed by Ricci Ulrich? List the schools and the corresponding average writing scores.", "sql": "SELECT T2.School, T1.AvgScrWrite FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.AdmFName1 = 'Ricci' AND T2.AdmLName1 = 'Ulrich'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Which state special schools have the highest number of enrollees from grades 1 through 12?", "sql": "SELECT T2.School FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.DOC = '31' ORDER BY T1.\"Enrollment (K-12)\" DESC LIMIT 1", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the monthly average number of schools that opened in Alameda County under the jurisdiction of the Elementary School District in 1980?", "sql": "SELECT CAST(COUNT(School) AS REAL) / NULLIF(12, 0) FROM schools WHERE DOC = '52' AND County = 'Alameda' AND EXTRACT(YEAR FROM OpenDate) = 1980", "complexity_score": 0.0448, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the ratio of merged Unified School District schools in Orange County to merged Elementary School District schools?", "sql": "SELECT CAST(SUM(CASE WHEN DOC::integer = 54 THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN DOC::integer = 52 THEN 1 ELSE 0 END), 0) FROM schools WHERE StatusType = 'Merged' AND County = 'Orange'", "complexity_score": 0.0406, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the postal street address for the school with the 7th highest Math average? Indicate the school's name.", "sql": "SELECT T2.MailStreet, T2.School FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.AvgScrMath DESC NULLS LAST LIMIT 1 OFFSET 6", "complexity_score": 0.0469, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER-LIMIT-OFFSET", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "OFFSET", "ORDER", "SELECT"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the total number of non-chartered schools in the county of Los Angeles with a percent (%) of eligible free meals for grades 1 through 12 that is less than 0.18%?", "sql": "SELECT COUNT(T2.School) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Los Angeles' AND T2.Charter = 0 AND CAST(T1.\"Free Meal Count (K-12)\" AS REAL) * 100 / NULLIF(T1.\"Enrollment (K-12)\", 0) < 0.18", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "How many students from the ages of 5 to 17 are enrolled at the State Special School school in Fremont for the 2014-2015 academic year?", "sql": "SELECT T1.\"Enrollment (Ages 5-17)\" FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.EdOpsCode = 'SSS' AND T2.City = 'Fremont' AND T1.\"Academic Year\" = '2014-2015'", "complexity_score": 0.075, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Which schools served a grade span of Kindergarten to 9th grade in the county of Los Angeles and what is its Percent (%) Eligible FRPM (Ages 5-17)?", "sql": "SELECT T2.School, T1.\"FRPM Count (Ages 5-17)\" * 100 / NULLIF(T1.\"Enrollment (Ages 5-17)\", 0) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Los Angeles' AND T2.GSserved = 'K-9'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Between San Diego and Santa Barbara, which county offers the most number of schools that does not offer physical building? Indicate the amount.", "sql": "SELECT County, COUNT(Virtual) FROM schools WHERE (County = 'San Diego' OR County = 'Santa Barbara') AND Virtual = 'F' GROUP BY County ORDER BY COUNT(Virtual) DESC NULLS LAST LIMIT 1", "complexity_score": 0.051, "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the grade span offered in the school with the highest longitude?", "sql": "SELECT GSoffered FROM schools ORDER BY ABS(longitude) DESC NULLS LAST LIMIT 1", "complexity_score": 0.0104, "pattern_signature": "SELECT-FROM-ORDER-LIMIT", "clauses_present": ["FROM", "LIMIT", "ORDER", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "Of the schools that offers a magnet program serving a grade span of Kindergarten to 8th grade, how many offers Multiple Provision Types? List the number of cities that offers a Kindergarten to 8th grade span and indicate how many schools are there serving such grade span for each city.", "sql": "SELECT T2.City, COUNT(T2.CDSCode) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.Magnet = 1 AND T2.GSoffered = 'K-8' AND T1.\"NSLP Provision Status\" = 'Multiple Provision Types' GROUP BY T2.City", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What is the Percent (%) Eligible Free (K-12) in the school administered by an administrator whose first name is Alusine. List the district code of the school.", "sql": "SELECT T1.\"Free Meal Count (K-12)\" * 100 / NULLIF(T1.\"Enrollment (K-12)\", 0), T1.\"District Code\" FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.AdmFName1 = 'Alusine'", "complexity_score": 0.0542, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "california_schools", "intent": "What are the valid e-mail addresses of the administrator of the school located in the San Bernardino county, City of San Bernardino City Unified that opened between 1/1/2009 to 12/31/2010 whose school types are public Intermediate/Middle Schools and Unified Schools?", "sql": "SELECT T2.AdmEmail1, T2.AdmEmail2 FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'San Bernardino' AND T2.City = 'San Bernardino' AND T2.DOC::integer = 54 AND EXTRACT(YEAR FROM T2.OpenDate) BETWEEN 2009 AND 2010 AND T2.SOC::integer = 62", "complexity_score": 0.0958, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "How many accounts who choose issuance after transaction are staying in East Bohemia region?", "sql": "SELECT COUNT(T2.account_id) FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id WHERE T1.A3 = 'east Bohemia' AND T2.frequency = 'POPLATEK PO OBRATU'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "List out the no. of districts that have female average salary is more than 6000 but less than 10000?", "sql": "SELECT COUNT(DISTINCT T2.district_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'F' AND T2.A11 BETWEEN 6000 AND 10000", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "How many male customers who are living in North Bohemia have average salary greater than 8000?", "sql": "SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'M' AND T2.A3 = 'north Bohemia' AND T2.A11 > 8000", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "List out the account numbers of female clients who are oldest and has lowest average salary, calculate the gap between this lowest average salary with the highest average salary?", "sql": "SELECT T1.account_id, (SELECT MAX(A11) - MIN(A11) FROM district) FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T1.account_id = T3.account_id INNER JOIN client AS T4 ON T3.client_id = T4.client_id WHERE T2.district_id = (SELECT district_id FROM client WHERE gender = 'F' ORDER BY birth_date ASC NULLS FIRST LIMIT 1) ORDER BY T2.A11 DESC NULLS LAST LIMIT 1", "complexity_score": 0.2594, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 3, "num_subqueries": 2, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "List out the account numbers of clients who are youngest and have highest average salary?", "sql": "SELECT T1.account_id FROM account AS T1 INNER JOIN disp AS T2 ON T1.account_id = T2.account_id INNER JOIN client AS T3 ON T2.client_id = T3.client_id INNER JOIN district AS T4 ON T4.district_id = T1.district_id WHERE T2.client_id = (SELECT client_id FROM client ORDER BY birth_date DESC NULLS LAST LIMIT 1) GROUP BY T4.A11, T1.account_id", "complexity_score": 0.2063, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 3, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Among the accounts who have approved loan date in 1997, list out the accounts that have the lowest approved amount and choose weekly issuance statement.", "sql": "SELECT T2.account_id FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1997' AND T2.frequency = 'POPLATEK TYDNE' ORDER BY T1.amount NULLS FIRST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Among the accounts who have loan validity more than 12 months, list out the accounts that have the highest approved amount and have account opening date in 1993.", "sql": "SELECT T1.account_id FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T2.date AS TIMESTAMP), 'YYYY') = '1993' AND T1.duration > 12 ORDER BY T1.amount DESC NULLS LAST LIMIT 1", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Among the account opened, how many female customers who were born before 1950 and stayed in Sokolov?", "sql": "SELECT COUNT(T2.client_id) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T2.gender = 'F' AND TO_CHAR(CAST(T2.birth_date AS TIMESTAMP), 'YYYY') < '1950' AND T1.A2 = 'Sokolov'", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For the female client who was born in 1976/1/29, which district did she opened her account?", "sql": "SELECT T1.A2 FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T2.birth_date = '1976-01-29' AND T2.gender = 'F'", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For the branch which located in the south Bohemia with biggest number of inhabitants, what is the percentage of the male clients?", "sql": "SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.client_id), 0) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'south Bohemia' GROUP BY T2.A4 ORDER BY T2.A4 DESC LIMIT 1", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For the client whose loan was approved first in 1993/7/5, what is the increase rate of his/her account balance from 1993/3/22 to 1998/12/27?", "sql": "SELECT CAST((SUM(CASE WHEN T3.date = '1998-12-27' THEN T3.balance ELSE 0 END) - SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END), 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN trans AS T3 ON T3.account_id = T2.account_id WHERE T1.date = '1993-07-05'", "complexity_score": 0.1094, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What is the percentage of loan amount that has been fully paid with no issue.", "sql": "SELECT (CAST(SUM(CASE WHEN status = 'A' THEN amount ELSE 0 END) AS REAL) * 100) / NULLIF(SUM(amount), 0) FROM loan", "complexity_score": 0.0229, "pattern_signature": "SELECT-FROM", "clauses_present": ["FROM", "SELECT"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For loan amount less than USD100,000, what is the percentage of accounts that is still running with no issue.", "sql": "SELECT CAST(SUM(CASE WHEN status = 'C' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(account_id), 0) FROM loan WHERE amount < 100000", "complexity_score": 0.0302, "pattern_signature": "SELECT-FROM-WHERE", "clauses_present": ["FROM", "SELECT", "WHERE"], "num_joins": 0, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For loans contracts which are still running where client are in debt, list the district of the and the state the percentage unemployment rate increment from year 1995 to 1996.", "sql": "SELECT CAST((T3.A13 - T3.A12) AS REAL) * 100 / NULLIF(T3.A12, 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN district AS T3 ON T2.district_id = T3.district_id WHERE T1.status = 'D'", "complexity_score": 0.0906, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "List the top nine districts, by descending order, from the highest to the lowest, the number of female account holders.", "sql": "SELECT T2.A2, COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'F' GROUP BY T2.district_id, T2.A2 ORDER BY COUNT(T1.client_id) DESC NULLS LAST LIMIT 9", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Between 1/1/1995 and 12/31/1997, how many loans in the amount of at least 250,000 per account that chose monthly statement issuance were approved?", "sql": "SELECT COUNT(T1.account_id) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.date BETWEEN '1995-01-01' AND '1997-12-31' AND T1.frequency = 'POPLATEK MESICNE' AND T2.amount >= 250000", "complexity_score": 0.0813, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "How many accounts have running contracts in Branch location 1?", "sql": "SELECT COUNT(T1.account_id) FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN loan AS T3 ON T1.account_id = T3.account_id WHERE T1.district_id = 1 AND (T3.status = 'C' OR T3.status = 'D')", "complexity_score": 0.1177, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "In the branch where the second-highest number of crimes were committed in 1995 occurred, how many male clients are there?", "sql": "SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'M' AND T2.A15 = (SELECT T3.A15 FROM district AS T3 ORDER BY T3.A15 DESC NULLS LAST LIMIT 1 OFFSET 1)", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT-OFFSET-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "OFFSET", "ORDER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Which are the top ten withdrawals (non-credit card) by district names for the month of January 1996?", "sql": "SELECT DISTINCT T1.A2 FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN trans AS T3 ON T2.account_id = T3.account_id WHERE T3.type = 'VYDAJ' AND CAST(T3.date AS TEXT) LIKE '1996-01%' ORDER BY T1.A2 ASC LIMIT 10", "complexity_score": 0.101, "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["DISTINCT", "FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Who are the account holder identification numbers whose who have transactions on the credit card with the amount is less than the average, in 1998?", "sql": "SELECT T1.account_id FROM trans AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1998' AND T1.operation = 'VYBER KARTOU' AND T1.amount < (SELECT AVG(amount) FROM trans WHERE TO_CHAR(CAST(date AS TIMESTAMP), 'YYYY') = '1998')", "complexity_score": 0.1677, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-SUBQUERY", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Please list the account types that are not eligible for loans, and the average income of residents in the district where the account is located exceeds $8000 but is no more than $9000.", "sql": "SELECT T3.type FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T2.account_id = T3.account_id WHERE T3.type <> 'OWNER' AND T1.A11 BETWEEN 8000 AND 9000", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What is the average number of crimes committed in 1995 in regions where the number exceeds 4000 and the region has accounts that are opened starting from the year 1997?", "sql": "SELECT AVG(T1.A15) FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id WHERE TO_CHAR(CAST(T2.date AS TIMESTAMP), 'YYYY') >= '1997' AND T1.A15 > 4000", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "List all the withdrawals in cash transactions that the client with the id 3356 makes.", "sql": "SELECT T4.trans_id FROM client AS T1 INNER JOIN disp AS T2 ON T1.client_id = T2.client_id INNER JOIN account AS T3 ON T2.account_id = T3.account_id INNER JOIN trans AS T4 ON T3.account_id = T4.account_id WHERE T1.client_id = 3356 AND T4.operation = 'VYBER'", "complexity_score": 0.1375, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What percentage of clients who opened their accounts in the district with an average salary of over 10000 are women?", "sql": "SELECT CAST(SUM(CASE WHEN T2.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.client_id), 0) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T1.A11 > 10000", "complexity_score": 0.0667, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What was the growth rate of the total amount of loans across all accounts for a male client between 1996 and 1997?", "sql": "SELECT CAST((SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1997' THEN T1.amount ELSE 0 END) - SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1996' THEN T1.amount ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN TO_CHAR(CAST(T1.date AS TIMESTAMP), 'YYYY') = '1996' THEN T1.amount ELSE 0 END), 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN disp AS T3 ON T3.account_id = T2.account_id INNER JOIN client AS T4 ON T4.client_id = T3.client_id WHERE T4.gender = 'M' AND T3.type = 'OWNER'", "complexity_score": 0.1562, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 3, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "How often does account number 3 request an account statement to be released? What was the aim of debiting 3539 in total?", "sql": "SELECT T1.frequency, T2.k_symbol FROM account AS T1 INNER JOIN (SELECT account_id, k_symbol, SUM(amount) AS total_amount FROM \"order\" GROUP BY account_id, k_symbol) AS T2 ON T1.account_id = T2.account_id WHERE T1.account_id = 3 AND T2.total_amount = 3539", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", "clauses_present": ["FROM", "GROUP", "JOIN", "JOIN_INNER", "SELECT", "SUBQUERY", "WHERE"], "num_joins": 1, "num_subqueries": 1, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What percentage of male clients request for weekly statements to be issued?", "sql": "SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.client_id), 0) FROM client AS T1 INNER JOIN district AS T3 ON T1.district_id = T3.district_id INNER JOIN account AS T2 ON T2.district_id = T3.district_id INNER JOIN disp AS T4 ON T1.client_id = T4.client_id AND T2.account_id = T4.account_id WHERE T2.frequency = 'POPLATEK TYDNE'", "complexity_score": 0.15, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 2, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Name the account numbers of female clients who are oldest and have lowest average salary?", "sql": "SELECT T3.account_id FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN account AS T3 ON T2.district_id = T3.district_id INNER JOIN disp AS T4 ON T1.client_id = T4.client_id AND T4.account_id = T3.account_id WHERE T1.gender = 'F' ORDER BY T1.birth_date ASC NULLS FIRST, T2.A11 ASC NULLS FIRST LIMIT 1", "complexity_score": 0.1375, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "LIMIT", "ORDER", "SELECT", "WHERE"], "num_joins": 3, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "What is the average amount of loan which are still on running contract with statement issuance after each transaction?", "sql": "SELECT AVG(T2.amount) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.status IN ('C', 'D') AND T1.frequency = 'POPLATEK PO OBRATU'", "complexity_score": 0.0708, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 1, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "Provide the IDs and age of the client with high level credit card, which is eligible for loans.", "sql": "SELECT T1.client_id, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T3.birth_date) AS age FROM disp AS T1 INNER JOIN card AS T2 ON T2.disp_id = T1.disp_id INNER JOIN client AS T3 ON T1.client_id = T3.client_id WHERE T2.type = 'gold' AND T1.type = 'OWNER'", "complexity_score": 0.101, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 2, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "For accounts in 1993 with statement issued after transaction, list the account ID, district name and district region.", "sql": "SELECT T1.account_id, T2.A2, T2.A3 FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.frequency = 'POPLATEK PO OBRATU' AND EXTRACT(YEAR FROM T1.date) = 1993", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} +{"db_id": "financial", "intent": "From Year 1995 to 2000, who are the accounts holders from 'east Bohemia'. State the account ID the frequency of statement issuance.", "sql": "SELECT T1.account_id, T1.frequency FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'east Bohemia' AND EXTRACT(YEAR FROM T1.date) BETWEEN 1995 AND 2000", "complexity_score": 0.0646, "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", "clauses_present": ["FROM", "JOIN", "JOIN_INNER", "SELECT", "WHERE"], "num_joins": 1, "num_subqueries": 0, "num_ctes": 0, "num_aggregations": 0, "document_type": "query_intent_pairs"} diff --git a/src/query_intent_vectordb/search_similar_query.py b/src/query_intent_vectordb/search_similar_query.py index f7ccbfb..de26c5a 100644 --- a/src/query_intent_vectordb/search_similar_query.py +++ b/src/query_intent_vectordb/search_similar_query.py @@ -107,9 +107,9 @@ def mmr_select( if not candidates: return [] - # Convert distance → similarity + # Convert distance → similarity (assuming cosine hnsw space) for c in candidates: - c["_sim"] = 1.0 / (1.0 + float(c["dist"])) + c["_sim"] = 1.0 - float(c["dist"]) remaining = sorted(candidates, key=lambda x: -x["_sim"]) selected = [remaining.pop(0)] diff --git a/src/skills/california-schools-semantic-model/SKILL.md b/src/skills/california-schools-semantic-model/SKILL.md new file mode 100644 index 0000000..3373904 --- /dev/null +++ b/src/skills/california-schools-semantic-model/SKILL.md @@ -0,0 +1,100 @@ +--- +name: california-schools-semantic-model +description: Semantic model for the california_schools database. Contains business term definitions, metric formulas, known query patterns, and critical gotchas for the California Schools dataset (FRPM eligibility, SAT scores, district/school hierarchy). Load this skill when the user is querying the california_schools database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-23T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# California Schools — Semantic Model + +## Available Resources + +This skill includes reference files with extended documentation. Load them +when you need deeper detail beyond what is in this file. + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Edge cases, NULL handling details, type pitfalls | `read_skill_resource("california-schools-semantic-model", "references/gotchas.md")` | +| Metric definitions | Full formulas for FRPM rate, SAT composite, etc. | `read_skill_resource("california-schools-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for common questions (top schools, county stats, etc.) | `read_skill_resource("california-schools-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If you are unsure about a metric formula → load `references/metrics.md` +- If the query is complex or involves edge cases → load `references/gotchas.md` +- If the query matches a common pattern (top-N, aggregation by county, etc.) → load `references/query_patterns.md` +- For simple, straightforward queries → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "free meal eligible" / "FRPM eligible" | `frpm."FRPM Count (K-12)"` — students eligible for Free or Reduced Price Meals | verified | +| "free meal rate" / "FRPM rate" | `frpm."FRPM Count (K-12)" / frpm."Enrollment (K-12)"` | verified | +| "free lunch" (strict) | `frpm."Free Meal Count (K-12)"` (excludes reduced-price) | verified | +| "SAT score" | Usually `satscores.AvgScrMath + satscores.AvgScrRead + satscores.AvgScrWrite` (total). Clarify if user wants a single subject. | verified | +| "test takers" | `satscores.NumTstTakr` | verified | +| "school type" | `schools.StatusType` — values include `Active`, `Closed`, `Merged` | verified | +| "charter school" | `frpm."Charter School (Y/N)" = 1` | verified | + +## Gotchas + +1. **`satscores` uses `cds`, not `CDSCode`** — to join with `schools`, use + `schools.CDSCode = satscores.cds`. Using `satscores.CDSCode` will fail + (column does not exist). + +2. **Column names with spaces in `frpm`** — columns like `Free Meal Count (K-12)` + must be double-quoted in PostgreSQL: + `frpm."Free Meal Count (K-12)"`. Never use backticks. + +3. **NULL SAT scores** — schools that did not administer the SAT have NULL in + `AvgScrMath`, `AvgScrRead`, `AvgScrWrite`, and `NumTstTakr`. Always + filter `WHERE satscores.NumTstTakr IS NOT NULL` (or use `COALESCE`) + unless the user explicitly wants all schools including non-participants. + +4. **CDSCode is a string** — `schools.CDSCode` and `satscores.cds` are both + `VARCHAR`/`TEXT`. Do NOT cast to integer or numeric. + +5. **`frpm` contains both district-level and school-level rows** — school-level + rows have a non-null `School Name`. Filter `WHERE frpm."School Name" IS NOT NULL` + when you need school-level data only. + +For extended gotchas and edge cases, call: +```python +read_skill_resource( + skill_name="california-schools-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +schools.CDSCode ──→ frpm.CDSCode (school ↔ FRPM data) +schools.CDSCode ──→ satscores.cds (school ↔ SAT scores — note different col name) +``` + +There is no direct join between `frpm` and `satscores`; always go through `schools`. + +## Frequently Asked Queries + +For canonical query patterns (top schools by SAT score, FRPM rate by county, etc.), call: +```python +read_skill_resource( + skill_name="california-schools-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas and calculation details, call: +```python +read_skill_resource( + skill_name="california-schools-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/california-schools-semantic-model/references/gotchas.md b/src/skills/california-schools-semantic-model/references/gotchas.md new file mode 100644 index 0000000..696b4ee --- /dev/null +++ b/src/skills/california-schools-semantic-model/references/gotchas.md @@ -0,0 +1,83 @@ +# Gotchas — california_schools_template + +## 1. `satscores` join column is `cds`, not `CDSCode` + +**Problem**: The `schools` table uses `CDSCode` as its primary key. But +`satscores` uses the column name `cds` for the same identifier. A common +mistake is writing `satscores.CDSCode` which fails immediately. + +**Correct join**: +```sql +-- CORRECT +JOIN satscores sat ON s.CDSCode = sat.cds + +-- WRONG — column does not exist +JOIN satscores sat ON s.CDSCode = sat.CDSCode +``` + +--- + +## 2. Column names with spaces must be double-quoted + +**Problem**: The `frpm` table has columns like `Free Meal Count (K-12)`, +`Enrollment (K-12)`, `FRPM Count (K-12)`, `Percent (%) Eligible Free (K-12)`. +PostgreSQL requires double quotes around identifiers with spaces or special chars. + +**Correct usage**: +```sql +-- CORRECT +frpm."Free Meal Count (K-12)" +frpm."Enrollment (K-12)" +frpm."FRPM Count (K-12)" +frpm."Percent (%) Eligible Free (K-12)" + +-- WRONG — syntax error +frpm.Free Meal Count (K-12) +frpm.`Free Meal Count (K-12)` -- backticks are MySQL syntax, not PostgreSQL +``` + +--- + +## 3. NULL SAT scores for non-participating schools + +**Problem**: Many schools have no SAT data. Their rows in `satscores` have +`NULL` for `AvgScrMath`, `AvgScrRead`, `AvgScrWrite`, and `NumTstTakr`. +Including them in averages or rankings silently skews results. + +**Fix**: Always filter when ranking or aggregating SAT scores: +```sql +WHERE sat.NumTstTakr IS NOT NULL +``` + +Or when computing averages across schools, use `AVG()` which naturally ignores +NULLs but be aware the denominator excludes non-participants. + +--- + +## 4. `frpm` contains both school-level and district-level rows + +**Problem**: The `frpm` table includes aggregate rows for entire districts, not +just individual schools. If you aggregate without filtering, district rows +double-count students. + +**Fix**: Filter to school-level rows only: +```sql +WHERE frpm."School Name" IS NOT NULL +``` +District-only rows have `NULL` in `School Name`. + +--- + +## 5. CDSCode is a string, not a number + +**Problem**: `CDSCode` looks numeric (14 digits) but is stored as `VARCHAR`/`TEXT`. +Casting to integer will fail for codes with leading zeros. + +**Fix**: Always treat as string — no CAST, no arithmetic operations on it. +```sql +-- CORRECT +WHERE s.CDSCode = '01100170109835' + +-- WRONG — CAST fails or loses leading zeros +WHERE CAST(s.CDSCode AS BIGINT) = 1100170109835 +``` diff --git a/src/skills/california-schools-semantic-model/references/metrics.md b/src/skills/california-schools-semantic-model/references/metrics.md new file mode 100644 index 0000000..8294b0b --- /dev/null +++ b/src/skills/california-schools-semantic-model/references/metrics.md @@ -0,0 +1,62 @@ +# Metrics — california_schools_template + +## FRPM Rate (Free or Reduced Price Meal Eligibility Rate) +**Definition**: Percentage of K-12 students eligible for free or reduced-price +meals. A proxy for school-level poverty rate. +**Confidence**: verified + +```sql +SELECT + s."School", + s."County", + f."FRPM Count (K-12)"::float / NULLIF(f."Enrollment (K-12)", 0) AS frpm_rate +FROM schools s +JOIN frpm f ON s.CDSCode = f.CDSCode +WHERE f."School Name" IS NOT NULL +ORDER BY frpm_rate DESC; +``` + +--- + +## Free Meal Rate (Strict — excludes reduced-price) +**Definition**: Percentage eligible for FREE meals only (not reduced-price). +**Confidence**: verified + +```sql +SELECT + s."School", + f."Free Meal Count (K-12)"::float / NULLIF(f."Enrollment (K-12)", 0) AS free_meal_rate +FROM schools s +JOIN frpm f ON s.CDSCode = f.CDSCode +WHERE f."School Name" IS NOT NULL; +``` + +--- + +## SAT Composite Score (Total) +**Definition**: Sum of average math + reading + writing scores for a school. +Used when user asks for "SAT score" without specifying subject. +**Confidence**: verified + +```sql +SELECT + s."School", + sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite AS sat_composite +FROM schools s +JOIN satscores sat ON s.CDSCode = sat.cds +WHERE sat.NumTstTakr IS NOT NULL +ORDER BY sat_composite DESC; +``` + +--- + +## SAT Math Average +**Definition**: Average SAT math section score for a school. +**Confidence**: verified + +```sql +SELECT s."School", sat.AvgScrMath +FROM schools s +JOIN satscores sat ON s.CDSCode = sat.cds +WHERE sat.NumTstTakr IS NOT NULL; +``` diff --git a/src/skills/california-schools-semantic-model/references/query_patterns.md b/src/skills/california-schools-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..cd25be3 --- /dev/null +++ b/src/skills/california-schools-semantic-model/references/query_patterns.md @@ -0,0 +1,99 @@ +# Query Patterns — california_schools_template + +## Top N Schools by SAT Score +**Trigger phrases**: "best SAT scores", "top schools by SAT", "highest SAT", +"schools with best test scores" +**Confidence**: verified (canonical BIRD-CRITIC pattern) + +```sql +SELECT + s."School", + s."County", + sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite AS sat_composite +FROM schools s +JOIN satscores sat ON s.CDSCode = sat.cds +WHERE sat.NumTstTakr IS NOT NULL +ORDER BY sat_composite DESC +LIMIT {{n}}; +``` + +--- + +## FRPM Rate by County +**Trigger phrases**: "free meal rate by county", "poverty rate by county", +"FRPM eligibility by county", "which county has most eligible students" +**Confidence**: verified + +```sql +SELECT + f."County Name", + SUM(f."FRPM Count (K-12)") AS total_frpm, + SUM(f."Enrollment (K-12)") AS total_enrollment, + SUM(f."FRPM Count (K-12)")::float / NULLIF(SUM(f."Enrollment (K-12)"), 0) + AS county_frpm_rate +FROM frpm f +WHERE f."School Name" IS NOT NULL +GROUP BY f."County Name" +ORDER BY county_frpm_rate DESC; +``` + +--- + +## Schools with Both SAT Scores and FRPM Data +**Trigger phrases**: "compare SAT and poverty", "schools with high SAT and low FRPM", +"correlation between meals and scores" +**Confidence**: verified + +```sql +SELECT + s."School", + s."County", + sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite AS sat_composite, + f."FRPM Count (K-12)"::float / NULLIF(f."Enrollment (K-12)", 0) AS frpm_rate +FROM schools s +JOIN satscores sat ON s.CDSCode = sat.cds +JOIN frpm f ON s.CDSCode = f.CDSCode +WHERE sat.NumTstTakr IS NOT NULL + AND f."School Name" IS NOT NULL +ORDER BY sat_composite DESC; +``` + +--- + +## Charter vs Non-Charter School Comparison +**Trigger phrases**: "charter schools", "charter vs public", "do charter schools +perform better" +**Confidence**: verified + +```sql +SELECT + f."Charter School (Y/N)" AS is_charter, + COUNT(*) AS school_count, + AVG(sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite) AS avg_sat_composite, + AVG(f."FRPM Count (K-12)"::float / NULLIF(f."Enrollment (K-12)", 0)) + AS avg_frpm_rate +FROM schools s +JOIN frpm f ON s.CDSCode = f.CDSCode +JOIN satscores sat ON s.CDSCode = sat.cds +WHERE sat.NumTstTakr IS NOT NULL + AND f."School Name" IS NOT NULL + AND f."Charter School (Y/N)" IS NOT NULL +GROUP BY f."Charter School (Y/N)" +ORDER BY is_charter; +``` + +--- + +## School Enrollment by County +**Trigger phrases**: "how many students", "enrollment by county", "largest counties" +**Confidence**: verified + +```sql +SELECT + f."County Name", + SUM(f."Enrollment (K-12)") AS total_enrollment +FROM frpm f +WHERE f."School Name" IS NOT NULL +GROUP BY f."County Name" +ORDER BY total_enrollment DESC; +``` diff --git a/src/skills/card-games-semantic-model/SKILL.md b/src/skills/card-games-semantic-model/SKILL.md new file mode 100644 index 0000000..043b81d --- /dev/null +++ b/src/skills/card-games-semantic-model/SKILL.md @@ -0,0 +1,101 @@ +--- +name: card-games-semantic-model +description: "Semantic model for the card_games database (Magic: The Gathering card data). Contains definitions for cards, sets, legalities, rulings, and foreign language data. Load this skill when the user is querying the card_games database." +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# Card Games — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Compound type fields, text power/toughness, color encoding, promo NULLs | `read_skill_resource("card-games-semantic-model", "references/gotchas.md")` | +| Metric definitions | Card counts by rarity, set size, color distribution | `read_skill_resource("card-games-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for card searches, legality queries, set lookups | `read_skill_resource("card-games-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If filtering by card type, color, or power/toughness → load `references/gotchas.md` (these fields are not simple scalars) +- If querying legality across formats → load `references/gotchas.md` + `references/query_patterns.md` +- If counting or aggregating cards → load `references/metrics.md` +- For simple name or set lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "creature card" | `cards.type LIKE '%Creature%'` — type field contains compound values | verified | +| "instant" / "sorcery" | `cards.type LIKE '%Instant%'` / `cards.type LIKE '%Sorcery%'` | verified | +| "rarity" | `cards.rarity` — values: `'common'`, `'uncommon'`, `'rare'`, `'mythic'` (all lowercase) | verified | +| "mana cost" | `cards.manaCost` (formatted string like `'{2}{W}{U}'`) | verified | +| "converted mana cost" / "CMC" | `cards.convertedManaCost` (numeric) | verified | +| "set" / "edition" | `sets` table — join via `cards.setCode = sets.code` | verified | +| "format legality" | `legalities` table — join via `cards.uuid = legalities.uuid` | verified | +| "ruling" | `rulings` table — join via `cards.uuid = rulings.uuid` | verified | +| "non-English card text" | `foreign_data` table — join via `cards.uuid = foreign_data.uuid` | verified | + +## Gotchas + +1. **`cards.type` is a compound string** — a card can be `"Legendary Creature — Dragon"`. + Never filter with `= 'Creature'`; always use `LIKE '%Creature%'`. + +2. **`cards.power` and `cards.toughness` are TEXT** — they can be `'*'`, `'X'`, + `'1+*'`, or a number stored as text. Do not cast to integer without guarding + for non-numeric values. + +3. **`cards.colors` is a pipe-separated string** — e.g. `'W'`, `'U|B'`, `'R|G'`. + To filter for a specific color, use `LIKE '%W%'` or + `'W' = ANY(string_to_array(colors, '|'))`. + +4. **Rarity values are lowercase** — `'common'`, `'uncommon'`, `'rare'`, + `'mythic'`. Never use `'Rare'` or `'RARE'`. + +5. **Promotional cards have NULL in many columns** — `number`, `multiverseId`, + and set-related fields are often NULL for promos. Use `IS NULL` checks + rather than assuming all cards have complete data. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="card-games-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +cards.setCode ──→ sets.code (card ↔ its set/edition) +cards.uuid ──→ legalities.uuid (card ↔ format legality) +cards.uuid ──→ rulings.uuid (card ↔ official rulings) +cards.uuid ──→ foreign_data.uuid (card ↔ non-English text) +sets.code ──→ set_translations.setCode (set ↔ translated set names) +``` + +There is no direct join between `legalities` and `sets`; go through `cards`. + +## Frequently Asked Queries + +For canonical query patterns (cards by format, rarity breakdowns, set contents), +call: +```python +read_skill_resource( + skill_name="card-games-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (card counts, color distribution, CMC stats), call: +```python +read_skill_resource( + skill_name="card-games-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/card-games-semantic-model/references/gotchas.md b/src/skills/card-games-semantic-model/references/gotchas.md new file mode 100644 index 0000000..0db9871 --- /dev/null +++ b/src/skills/card-games-semantic-model/references/gotchas.md @@ -0,0 +1,103 @@ +# Gotchas — card_games + +## 1. `cards.type` is a compound string — use `LIKE`, not `=` + +**Problem**: A card's `type` field combines supertypes, types, and subtypes into +one string, e.g. `"Legendary Creature — Dragon"` or `"Artifact Creature — Construct"`. +Filtering with `= 'Creature'` always returns zero rows. + +**Correct usage**: +```sql +-- CORRECT +SELECT name FROM cards WHERE type LIKE '%Creature%'; +SELECT name FROM cards WHERE type LIKE '%Instant%'; +SELECT name FROM cards WHERE type LIKE '%Legendary%' AND type LIKE '%Creature%'; + +-- WRONG — zero rows +SELECT name FROM cards WHERE type = 'Creature'; +SELECT name FROM cards WHERE type = 'Legendary Creature'; +``` + +--- + +## 2. `cards.power` and `cards.toughness` are TEXT, not numeric + +**Problem**: Power and toughness are stored as strings to handle non-numeric +values like `'*'`, `'X'`, `'1+*'`, `'2+*'`. Casting directly to integer or +using numeric comparisons fails for these rows. + +**Correct usage**: +```sql +-- CORRECT: filter to numeric-only values before casting +SELECT name, power::integer AS power_int +FROM cards +WHERE power ~ '^\d+$' -- only rows that are pure integers +ORDER BY power_int DESC; + +-- CORRECT: count cards with non-numeric power +SELECT COUNT(*) FROM cards WHERE power !~ '^\d+$'; + +-- WRONG — error on rows with '*' or 'X' +SELECT name FROM cards ORDER BY power::integer DESC; +``` + +--- + +## 3. `cards.colors` is a pipe-separated string + +**Problem**: Multi-color cards store colors as a pipe-delimited string: `'W|U'`, +`'R|G|B'`. A simple `= 'W'` check misses multi-color cards that include white. + +**Correct usage**: +```sql +-- CORRECT: cards that include White (may also be other colors) +SELECT name FROM cards WHERE colors LIKE '%W%'; + +-- CORRECT: strictly mono-White cards +SELECT name FROM cards WHERE colors = 'W'; + +-- CORRECT: using array splitting for precise matching +SELECT name FROM cards +WHERE 'W' = ANY(string_to_array(colors, '|')); + +-- WRONG — misses 'W|U', 'W|B|R', etc. +SELECT name FROM cards WHERE colors = 'W'; -- only finds mono-White +``` + +--- + +## 4. `rarity` values are lowercase strings + +**Problem**: Rarity is stored as lowercase: `'common'`, `'uncommon'`, `'rare'`, +`'mythic'`. Using title case or uppercase returns zero rows. + +**Correct usage**: +```sql +-- CORRECT +SELECT name FROM cards WHERE rarity = 'rare'; +SELECT name FROM cards WHERE rarity = 'mythic'; + +-- WRONG +SELECT name FROM cards WHERE rarity = 'Rare'; +SELECT name FROM cards WHERE rarity = 'MYTHIC'; +``` + +--- + +## 5. Promotional and special cards have many NULL fields + +**Problem**: Promo cards (`promoTypes IS NOT NULL` or `isPromo = 1`) often +have NULL values for `multiverseId`, `number`, and other standard fields. +Aggregations that assume all cards have complete data will silently drop promos. + +**Correct usage**: +```sql +-- CORRECT: exclude promos when you need complete data +SELECT * FROM cards WHERE isPromo = 0 OR isPromo IS NULL; + +-- CORRECT: check for promos explicitly +SELECT COUNT(*) FROM cards WHERE isPromo = 1; + +-- Gotcha: 'number' is also NULL for some non-promo reprint sets +-- Always use NULLIF or filter before using 'number' in ORDER BY +``` diff --git a/src/skills/card-games-semantic-model/references/metrics.md b/src/skills/card-games-semantic-model/references/metrics.md new file mode 100644 index 0000000..ad9e505 --- /dev/null +++ b/src/skills/card-games-semantic-model/references/metrics.md @@ -0,0 +1,96 @@ +# Metric Definitions — card_games + +## Card Count by Rarity + +```sql +-- Distribution of cards across rarity tiers +SELECT + rarity, + COUNT(*) AS card_count, + ROUND(COUNT(*)::numeric / SUM(COUNT(*)) OVER (), 4) AS fraction +FROM cards +GROUP BY rarity +ORDER BY + CASE rarity + WHEN 'common' THEN 1 + WHEN 'uncommon' THEN 2 + WHEN 'rare' THEN 3 + WHEN 'mythic' THEN 4 + ELSE 5 + END; +``` + +--- + +## Cards per Set (Set Size) + +```sql +-- Number of unique cards in each set, joined to set name +SELECT + s.name AS set_name, + s.releaseDate, + COUNT(c.id) AS card_count +FROM sets s +LEFT JOIN cards c ON c.setCode = s.code +GROUP BY s.code, s.name, s.releaseDate +ORDER BY s.releaseDate DESC; +``` + +--- + +## Average Converted Mana Cost by Card Type + +```sql +-- Average CMC for each major card type category +SELECT + CASE + WHEN type LIKE '%Creature%' THEN 'Creature' + WHEN type LIKE '%Instant%' THEN 'Instant' + WHEN type LIKE '%Sorcery%' THEN 'Sorcery' + WHEN type LIKE '%Enchantment%' THEN 'Enchantment' + WHEN type LIKE '%Artifact%' THEN 'Artifact' + WHEN type LIKE '%Planeswalker%' THEN 'Planeswalker' + WHEN type LIKE '%Land%' THEN 'Land' + ELSE 'Other' + END AS card_category, + COUNT(*) AS card_count, + ROUND(AVG(convertedManaCost), 2) AS avg_cmc +FROM cards +WHERE convertedManaCost IS NOT NULL +GROUP BY card_category +ORDER BY avg_cmc DESC; +``` + +--- + +## Color Distribution + +```sql +-- How many cards are each color (including multi-color) +SELECT + CASE + WHEN colors IS NULL OR colors = '' THEN 'Colorless' + WHEN colors NOT LIKE '%|%' THEN colors -- mono-color + ELSE 'Multi' + END AS color_category, + COUNT(*) AS card_count +FROM cards +GROUP BY color_category +ORDER BY card_count DESC; +``` + +--- + +## Format Legality Breakdown + +```sql +-- Count of cards that are legal in each major format +SELECT + format, + SUM(CASE WHEN status = 'Legal' THEN 1 ELSE 0 END) AS legal_count, + SUM(CASE WHEN status = 'Banned' THEN 1 ELSE 0 END) AS banned_count, + SUM(CASE WHEN status = 'Restricted' THEN 1 ELSE 0 END) AS restricted_count +FROM legalities +GROUP BY format +ORDER BY legal_count DESC; +``` diff --git a/src/skills/card-games-semantic-model/references/query_patterns.md b/src/skills/card-games-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..f7817c0 --- /dev/null +++ b/src/skills/card-games-semantic-model/references/query_patterns.md @@ -0,0 +1,68 @@ +# Query Patterns — card_games + +## "Find all rare and mythic creatures in a specific set" + +```sql +-- Use LIKE for type matching; rarity values are lowercase +SELECT c.name, c.type, c.rarity, c.convertedManaCost +FROM cards c +JOIN sets s ON c.setCode = s.code +WHERE s.name = 'Innistrad' + AND c.type LIKE '%Creature%' + AND c.rarity IN ('rare', 'mythic') +ORDER BY c.rarity, c.convertedManaCost; +``` + +--- + +## "Which cards are legal in Modern but banned in Legacy?" + +```sql +SELECT c.name, c.setCode +FROM cards c +JOIN legalities l_mod ON c.uuid = l_mod.uuid AND l_mod.format = 'modern' AND l_mod.status = 'Legal' +JOIN legalities l_leg ON c.uuid = l_leg.uuid AND l_leg.format = 'legacy' AND l_leg.status = 'Banned' +ORDER BY c.name; +``` + +--- + +## "List all rulings for a specific card" + +```sql +-- Find rulings by card name +SELECT c.name, r.date, r.text +FROM cards c +JOIN rulings r ON c.uuid = r.uuid +WHERE c.name = 'Black Lotus' +ORDER BY r.date; +``` + +--- + +## "Find the highest-CMC cards that are not lands" + +```sql +-- power/toughness are text; use convertedManaCost (numeric) for sorting +SELECT name, type, convertedManaCost, manaCost +FROM cards +WHERE type NOT LIKE '%Land%' + AND convertedManaCost IS NOT NULL +ORDER BY convertedManaCost DESC +LIMIT 20; +``` + +--- + +## "Get the French translation of cards in a set" + +```sql +-- foreign_data joins via uuid; filter by language +SELECT c.name AS english_name, fd.name AS french_name, fd.text AS french_text +FROM cards c +JOIN foreign_data fd ON c.uuid = fd.uuid +JOIN sets s ON c.setCode = s.code +WHERE fd.language = 'French' + AND s.name = 'Core Set 2021' +ORDER BY c.name; +``` diff --git a/src/skills/codebase-community-semantic-model/SKILL.md b/src/skills/codebase-community-semantic-model/SKILL.md new file mode 100644 index 0000000..9e5b333 --- /dev/null +++ b/src/skills/codebase-community-semantic-model/SKILL.md @@ -0,0 +1,104 @@ +--- +name: codebase-community-semantic-model +description: Semantic model for the codebase_community database (StackOverflow-like Q&A community — posts, users, comments, votes, tags, badges). Load this skill when the user is querying the codebase_community database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 5 +--- + +# Codebase Community — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | PostTypeId filtering, tag string format, NULL OwnerUserId, PostLinks types | `read_skill_resource("codebase-community-semantic-model", "references/gotchas.md")` | +| Metric definitions | Answer acceptance rate, user engagement, tag popularity | `read_skill_resource("codebase-community-semantic-model", "references/metrics.md")` | +| Query patterns | Top users, unanswered questions, tag-filtered posts, duplicate detection | `read_skill_resource("codebase-community-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If querying the `posts` table → load `references/gotchas.md` (must filter by PostTypeId) +- If filtering by tag → load `references/gotchas.md` (tags are a delimited string, not a join) +- If computing engagement metrics → load `references/metrics.md` +- For simple user or reputation lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "question" | `posts.PostTypeId = 1` | verified | +| "answer" | `posts.PostTypeId = 2` | verified | +| "accepted answer" | `posts.AcceptedAnswerId IS NOT NULL` (question has an accepted answer) | verified | +| "answer to a question" | `answers.ParentId = question.Id` (self-join on `posts`) | verified | +| "tag" | substring of `posts.Tags` — format: `''` | verified | +| "reputation" | `users.Reputation` — numeric score | verified | +| "post owner" | `posts.OwnerUserId` → `users.Id` (nullable — deleted users are NULL) | verified | +| "duplicate question" | `postlinks.LinkTypeId = 3` | verified | +| "related question" | `postlinks.LinkTypeId = 1` | verified | +| "upvote" | `votes.VoteTypeId = 2` | verified | + +## Gotchas + +1. **`posts` contains questions AND answers — always filter by `PostTypeId`** — + `PostTypeId = 1` for questions, `2` for answers. Omitting the filter mixes + question metrics with answer metrics. + +2. **`posts.Tags` is a concatenated string, not a join** — tags are stored as + `''`. Use `LIKE '%%'` to filter. The `tags` table + stores global tag statistics, not per-post membership. + +3. **`posts.OwnerUserId` can be NULL** — deleted accounts are anonymised and + their posts have `NULL` in `OwnerUserId`. Use `LEFT JOIN users` and handle + NULL in output. + +4. **An answer's parent question is `posts.ParentId`** — to join answers to + their questions, do a self-join: `JOIN posts q ON a.ParentId = q.Id`. + +5. **`VoteTypeId` is not simply up/down** — `2` = UpVote, `3` = DownVote, + `5` = Favorite. There are other types for spam flags, close votes, etc. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="codebase-community-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +posts.OwnerUserId ──→ users.Id (post ↔ author, nullable) +posts.AcceptedAnswerId ──→ posts.Id (question ↔ accepted answer) +posts.ParentId ──→ posts.Id (answer ↔ its question) +comments.PostId ──→ posts.Id +comments.UserId ──→ users.Id +votes.PostId ──→ posts.Id +badges.UserId ──→ users.Id +postlinks.PostId ──→ posts.Id (source) +postlinks.RelatedPostId ──→ posts.Id (target) +``` + +## Frequently Asked Queries + +For canonical query patterns (top users, unanswered questions, tag analysis), +call: +```python +read_skill_resource( + skill_name="codebase-community-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (acceptance rate, answer latency, tag popularity), call: +```python +read_skill_resource( + skill_name="codebase-community-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/codebase-community-semantic-model/references/gotchas.md b/src/skills/codebase-community-semantic-model/references/gotchas.md new file mode 100644 index 0000000..cc2fa6c --- /dev/null +++ b/src/skills/codebase-community-semantic-model/references/gotchas.md @@ -0,0 +1,118 @@ +# Gotchas — codebase_community + +## 1. `posts` contains both questions and answers — always filter by `PostTypeId` + +**Problem**: All posts — questions, answers, wiki entries — share the same table. +Omitting the `PostTypeId` filter mixes question and answer rows and skews all +aggregations. + +**Correct usage**: +```sql +-- CORRECT: questions only +SELECT COUNT(*) FROM posts WHERE PostTypeId = 1; + +-- CORRECT: answers only +SELECT COUNT(*) FROM posts WHERE PostTypeId = 2; + +-- WRONG — counts questions + answers + other post types +SELECT COUNT(*) FROM posts; +SELECT AVG(Score) FROM posts; -- averages across heterogeneous post types +``` + +--- + +## 2. `posts.Tags` is a delimited string `''` — use LIKE, not a join + +**Problem**: Tags are stored inline as `''`. The `tags` +table holds aggregate statistics, not per-post membership. To filter posts by +tag, use `LIKE`. + +**Correct usage**: +```sql +-- CORRECT: posts tagged with 'python' +SELECT Id, Title FROM posts +WHERE PostTypeId = 1 + AND Tags LIKE '%%'; + +-- CORRECT: posts tagged with both 'python' and 'pandas' +SELECT Id, Title FROM posts +WHERE Tags LIKE '%%' + AND Tags LIKE '%%'; + +-- WRONG — tags table is not per-post; this join is not valid +JOIN tags t ON posts.Tags = t.TagName +``` + +--- + +## 3. `posts.OwnerUserId` is NULL for deleted/anonymous users + +**Problem**: When a user deletes their account, their posts remain but +`OwnerUserId` becomes NULL. `INNER JOIN users` silently drops these posts. + +**Correct usage**: +```sql +-- CORRECT: include all posts, show 'deleted' for anonymous +SELECT + p.Title, + COALESCE(u.DisplayName, '[deleted]') AS author +FROM posts p +LEFT JOIN users u ON p.OwnerUserId = u.Id +WHERE p.PostTypeId = 1; + +-- WRONG — drops posts from deleted users +INNER JOIN users u ON p.OwnerUserId = u.Id +``` + +--- + +## 4. To link an answer to its question, self-join `posts` on `ParentId` + +**Problem**: Answers don't have a separate table — they are rows in `posts` +with `PostTypeId = 2` and `ParentId` pointing to the question's `Id`. Joining +answer to question requires a self-join. + +**Correct usage**: +```sql +-- CORRECT: get each question with its answers +SELECT + q.Title AS question, + a.Body AS answer, + a.Score AS answer_score +FROM posts q +JOIN posts a ON a.ParentId = q.Id +WHERE q.PostTypeId = 1 + AND a.PostTypeId = 2; + +-- WRONG — no separate 'answers' table +FROM answers JOIN posts ... +``` + +--- + +## 5. `VoteTypeId` is not simply 2 = upvote, 3 = downvote + +**Problem**: There are more VoteTypeId values than just up/down. Summing all +vote types as if they were upvotes overcounts engagement. + +**Key VoteTypeId values**: +| VoteTypeId | Meaning | +|---|---| +| 1 | AcceptedByOriginator | +| 2 | UpMod (upvote) | +| 3 | DownMod (downvote) | +| 4 | Offensive | +| 5 | Favorite | +| 8 | BountyStart | +| 9 | BountyClose | + +```sql +-- CORRECT: count only upvotes +SELECT PostId, COUNT(*) AS upvote_count +FROM votes +WHERE VoteTypeId = 2 +GROUP BY PostId; + +-- WRONG — counts all vote types as upvotes +SELECT PostId, COUNT(*) AS upvote_count FROM votes GROUP BY PostId; +``` diff --git a/src/skills/codebase-community-semantic-model/references/metrics.md b/src/skills/codebase-community-semantic-model/references/metrics.md new file mode 100644 index 0000000..cfbb177 --- /dev/null +++ b/src/skills/codebase-community-semantic-model/references/metrics.md @@ -0,0 +1,85 @@ +# Metric Definitions — codebase_community + +## Answer Acceptance Rate + +```sql +-- Fraction of questions that have an accepted answer +SELECT + ROUND( + COUNT(*) FILTER (WHERE AcceptedAnswerId IS NOT NULL)::numeric / COUNT(*), + 4 + ) AS acceptance_rate, + COUNT(*) AS total_questions, + COUNT(*) FILTER (WHERE AcceptedAnswerId IS NOT NULL) AS accepted_count +FROM posts +WHERE PostTypeId = 1; +``` + +--- + +## Questions with No Answers + +```sql +SELECT + COUNT(*) AS unanswered_questions, + ROUND( + COUNT(*)::numeric / (SELECT COUNT(*) FROM posts WHERE PostTypeId = 1), + 4 + ) AS unanswered_rate +FROM posts +WHERE PostTypeId = 1 + AND AnswerCount = 0; +``` + +--- + +## Top Users by Reputation + +```sql +SELECT + Id, + DisplayName, + Reputation, + UpVotes, + DownVotes, + Views AS profile_views +FROM users +ORDER BY Reputation DESC +LIMIT 20; +``` + +--- + +## Most Popular Tags by Post Count + +```sql +SELECT + TagName, + Count AS post_count +FROM tags +ORDER BY Count DESC +LIMIT 30; +``` + +--- + +## Average Answer Score by Question Tag + +```sql +-- Filter to top tags; tags stored as '' substring +SELECT + 'python' AS tag, + COUNT(*) AS answer_count, + ROUND(AVG(a.Score), 2) AS avg_answer_score +FROM posts q +JOIN posts a ON a.ParentId = q.Id AND a.PostTypeId = 2 +WHERE q.Tags LIKE '%%' +UNION ALL +SELECT + 'sql', + COUNT(*), + ROUND(AVG(a.Score), 2) +FROM posts q +JOIN posts a ON a.ParentId = q.Id AND a.PostTypeId = 2 +WHERE q.Tags LIKE '%%'; +``` diff --git a/src/skills/codebase-community-semantic-model/references/query_patterns.md b/src/skills/codebase-community-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..c43b450 --- /dev/null +++ b/src/skills/codebase-community-semantic-model/references/query_patterns.md @@ -0,0 +1,91 @@ +# Query Patterns — codebase_community + +## "Find the top-voted questions tagged with a specific tag" + +```sql +-- Tags stored as '' substrings — use LIKE +SELECT + p.Id, + p.Title, + p.Score, + p.AnswerCount, + p.ViewCount, + COALESCE(u.DisplayName, '[deleted]') AS author +FROM posts p +LEFT JOIN users u ON p.OwnerUserId = u.Id +WHERE p.PostTypeId = 1 + AND p.Tags LIKE '%%' +ORDER BY p.Score DESC +LIMIT 20; +``` + +--- + +## "Which questions have the most answers?" + +```sql +SELECT + p.Id, + p.Title, + p.AnswerCount, + p.Score, + p.AcceptedAnswerId IS NOT NULL AS has_accepted_answer +FROM posts p +WHERE p.PostTypeId = 1 +ORDER BY p.AnswerCount DESC +LIMIT 20; +``` + +--- + +## "Show all answers to a specific question, ordered by votes" + +```sql +-- Self-join posts: answers have ParentId pointing to the question's Id +SELECT + a.Id AS answer_id, + a.Score, + a.CreationDate, + COALESCE(u.DisplayName, '[deleted]') AS answerer, + q.AcceptedAnswerId = a.Id AS is_accepted +FROM posts q +JOIN posts a ON a.ParentId = q.Id AND a.PostTypeId = 2 +LEFT JOIN users u ON a.OwnerUserId = u.Id +WHERE q.Id = 11227809 -- replace with target question Id +ORDER BY (q.AcceptedAnswerId = a.Id) DESC, a.Score DESC; +``` + +--- + +## "Find duplicate questions (linked as duplicates)" + +```sql +-- LinkTypeId = 3 means the source is a duplicate of the target +SELECT + q_orig.Title AS original_question, + q_dup.Title AS duplicate_question, + pl.CreationDate AS marked_duplicate_on +FROM postlinks pl +JOIN posts q_orig ON pl.RelatedPostId = q_orig.Id +JOIN posts q_dup ON pl.PostId = q_dup.Id +WHERE pl.LinkTypeId = 3 +ORDER BY pl.CreationDate DESC +LIMIT 20; +``` + +--- + +## "Which users have earned the most badges?" + +```sql +SELECT + u.DisplayName, + u.Reputation, + COUNT(b.Id) AS badge_count, + COUNT(DISTINCT b.Name) AS unique_badge_types +FROM users u +JOIN badges b ON u.Id = b.UserId +GROUP BY u.Id, u.DisplayName, u.Reputation +ORDER BY badge_count DESC +LIMIT 20; +``` diff --git a/src/skills/debit-card-specializing-semantic-model/SKILL.md b/src/skills/debit-card-specializing-semantic-model/SKILL.md new file mode 100644 index 0000000..fd8b1b8 --- /dev/null +++ b/src/skills/debit-card-specializing-semantic-model/SKILL.md @@ -0,0 +1,100 @@ +--- +name: debit-card-specializing-semantic-model +description: Semantic model for the debit_card_specializing database (Czech fuel card transactions — gas stations, customers, products, monthly aggregates). Load this skill when the user is querying the debit_card_specializing database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# Debit Card Specializing — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | YYYYMM date format, Czech product names, country codes, segment values | `read_skill_resource("debit-card-specializing-semantic-model", "references/gotchas.md")` | +| Metric definitions | Spend per customer, monthly consumption, station-level aggregates | `read_skill_resource("debit-card-specializing-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for customer spend, station queries, product filtering | `read_skill_resource("debit-card-specializing-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If filtering by date or month → load `references/gotchas.md` (date is an integer, not a DATE column) +- If filtering by product type or country → load `references/gotchas.md` (Czech text and abbreviations) +- If aggregating spend or consumption → load `references/metrics.md` +- For simple transaction lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "monthly data" / "monthly consumption" | `yearmonth` table — `Date` column is an integer in YYYYMM format (e.g. `201207`) | verified | +| "transaction" | `transactions_1k` table — a sample of 1000 transactions | verified | +| "customer segment" | `customers.Segment` — values: `'SME'`, `'LAM'`, `'KAM'` (company size tiers) | verified | +| "gas station country" | `gasstations.Country` — values: `'CZE'`, `'SVK'`, `'HUN'` (not full names) | verified | +| "diesel" | `products.Description = 'Nafta'` (Czech for diesel) | verified | +| "station segment" | `gasstations.Segment` — values like `'Premium'`, `'Value'` | verified | + +## Gotchas + +1. **`yearmonth.Date` is an integer in YYYYMM format** — e.g. `201207` means + July 2012. It is not a SQL DATE. To filter by year or month, use integer + arithmetic: `Date / 100 = 2012` for year, `Date % 100 = 7` for month. + +2. **Product descriptions are in Czech** — `'Nafta'` = diesel, + `'Rucní zadání'` = manual entry. Filtering on English product names returns + zero rows. + +3. **Country codes are 3-letter abbreviations** — `'CZE'` (Czech Republic), + `'SVK'` (Slovakia), `'HUN'` (Hungary). There are no full country names. + +4. **`transactions_1k` is a 1000-row sample** — not the full transaction history. + The `yearmonth` table has complete monthly aggregates per customer and is + more reliable for total-spend queries. + +5. **`customers.Segment` values are business size categories** — `'SME'` (small + and medium enterprise), `'LAM'` (large account management), `'KAM'` (key + account management). Not geographic segments. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="debit-card-specializing-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +customers.CustomerID ──→ transactions_1k.CustomerID (customer ↔ transactions) +customers.CustomerID ──→ yearmonth.CustomerID (customer ↔ monthly aggregates) +gasstations.GasStationID ──→ transactions_1k.GasStationID (station ↔ transactions) +products.ProductID ──→ transactions_1k.ProductID (product ↔ transactions) +``` + +`yearmonth` has no direct join to `gasstations` or `products` — it aggregates +consumption at the customer level only. + +## Frequently Asked Queries + +For canonical query patterns (spend by segment, monthly trends, station country +breakdowns), call: +```python +read_skill_resource( + skill_name="debit-card-specializing-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (total spend, monthly consumption, station-level +aggregates), call: +```python +read_skill_resource( + skill_name="debit-card-specializing-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/debit-card-specializing-semantic-model/references/gotchas.md b/src/skills/debit-card-specializing-semantic-model/references/gotchas.md new file mode 100644 index 0000000..cfbb249 --- /dev/null +++ b/src/skills/debit-card-specializing-semantic-model/references/gotchas.md @@ -0,0 +1,108 @@ +# Gotchas — debit_card_specializing + +## 1. `yearmonth.Date` is an integer in YYYYMM format, not a DATE + +**Problem**: The `yearmonth` table's `Date` column stores months as integers +like `201207` (= July 2012). It cannot be compared to ISO date strings or used +with `DATE_TRUNC`. Filter using integer arithmetic. + +**Correct usage**: +```sql +-- CORRECT: get all records for the year 2012 +SELECT * FROM yearmonth WHERE Date / 100 = 2012; + +-- CORRECT: get July of any year +SELECT * FROM yearmonth WHERE Date % 100 = 7; + +-- CORRECT: get a specific month +SELECT * FROM yearmonth WHERE Date = 201207; + +-- WRONG — type mismatch or silent wrong results +WHERE Date = '2012-07-01' +WHERE Date BETWEEN '2012-01-01' AND '2012-12-31' +``` + +--- + +## 2. Product descriptions are Czech text + +**Problem**: The `products.Description` column uses Czech vocabulary. +Searching for English product names (e.g. 'Diesel') returns zero rows. + +**Known Czech product description values**: +| Czech | English meaning | +|---|---| +| `'Nafta'` | Diesel | +| `'Rucní zadání'` | Manual/cash entry | +| `'Special'` | Special fuel type | + +```sql +-- CORRECT +SELECT * FROM transactions_1k t +JOIN products p ON t.ProductID = p.ProductID +WHERE p.Description = 'Nafta'; -- diesel transactions + +-- WRONG +WHERE p.Description = 'Diesel' -- returns zero rows +``` + +--- + +## 3. Gas station country codes are 3-letter abbreviations + +**Problem**: `gasstations.Country` uses ISO-like 3-letter codes, not full +country names. `'Czech Republic'` or `'CZ'` will not match. + +**Country code values**: +| Code | Country | +|---|---| +| `'CZE'` | Czech Republic | +| `'SVK'` | Slovakia | +| `'HUN'` | Hungary | + +```sql +-- CORRECT +SELECT COUNT(*) FROM gasstations WHERE Country = 'CZE'; + +-- WRONG +WHERE Country = 'Czech Republic' -- zero rows +WHERE Country = 'CZ' -- zero rows +``` + +--- + +## 4. `transactions_1k` is a sample — use `yearmonth` for totals + +**Problem**: `transactions_1k` contains only 1000 rows (a sample). Any +customer-level total spend computed from this table will be incomplete. +For monthly totals, use the `yearmonth` table which has full aggregates. + +```sql +-- CORRECT: monthly total consumption per customer +SELECT CustomerID, Date, Consumption +FROM yearmonth +WHERE Date / 100 = 2012 +ORDER BY Consumption DESC; + +-- MISLEADING: partial spend from the sample only +SELECT CustomerID, SUM(Amount) FROM transactions_1k GROUP BY CustomerID; +-- (This underestimates true spend since only 1000 transactions are present) +``` + +--- + +## 5. `customers.Segment` and `gasstations.Segment` use different value sets + +**Problem**: Both `customers` and `gasstations` have a `Segment` column but +they contain different categories — customer segments classify company size +while station segments classify service tier. Do not conflate them. + +```sql +-- Customer segments (company size) +SELECT DISTINCT Segment FROM customers; +-- Returns: 'SME', 'LAM', 'KAM' + +-- Gas station segments (service tier) +SELECT DISTINCT Segment FROM gasstations; +-- Returns: 'Premium', 'Value', etc. (varies by data version) +``` diff --git a/src/skills/debit-card-specializing-semantic-model/references/metrics.md b/src/skills/debit-card-specializing-semantic-model/references/metrics.md new file mode 100644 index 0000000..4e51778 --- /dev/null +++ b/src/skills/debit-card-specializing-semantic-model/references/metrics.md @@ -0,0 +1,79 @@ +# Metric Definitions — debit_card_specializing + +## Total Annual Consumption per Customer + +```sql +-- Use yearmonth for complete data (transactions_1k is a sample only) +SELECT + CustomerID, + Date / 100 AS year, + SUM(Consumption) AS total_consumption +FROM yearmonth +GROUP BY CustomerID, Date / 100 +ORDER BY total_consumption DESC; +``` + +--- + +## Total Spend per Customer Segment (from transactions_1k) + +```sql +-- Note: transactions_1k is a sample — results are indicative, not exact totals +SELECT + c.Segment, + COUNT(DISTINCT t.CustomerID) AS customer_count, + SUM(t.Amount) AS total_amount, + ROUND(AVG(t.Amount), 2) AS avg_transaction_amount +FROM transactions_1k t +JOIN customers c ON t.CustomerID = c.CustomerID +GROUP BY c.Segment +ORDER BY total_amount DESC; +``` + +--- + +## Transactions by Gas Station Country + +```sql +SELECT + g.Country, + COUNT(*) AS transaction_count, + SUM(t.Amount) AS total_amount +FROM transactions_1k t +JOIN gasstations g ON t.GasStationID = g.GasStationID +GROUP BY g.Country +ORDER BY transaction_count DESC; +``` + +--- + +## Monthly Consumption Trend (all customers) + +```sql +-- Total consumption across all customers by month +SELECT + Date AS year_month, + Date / 100 AS year, + Date % 100 AS month, + SUM(Consumption) AS total_consumption, + COUNT(DISTINCT CustomerID) AS active_customers +FROM yearmonth +GROUP BY Date +ORDER BY Date; +``` + +--- + +## Product Mix by Transaction Volume + +```sql +SELECT + p.ProductID, + p.Description, + COUNT(*) AS transaction_count, + SUM(t.Amount) AS total_amount +FROM transactions_1k t +JOIN products p ON t.ProductID = p.ProductID +GROUP BY p.ProductID, p.Description +ORDER BY transaction_count DESC; +``` diff --git a/src/skills/debit-card-specializing-semantic-model/references/query_patterns.md b/src/skills/debit-card-specializing-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..a6b4639 --- /dev/null +++ b/src/skills/debit-card-specializing-semantic-model/references/query_patterns.md @@ -0,0 +1,85 @@ +# Query Patterns — debit_card_specializing + +## "Which customers spent the most on diesel in 2012?" + +```sql +-- yearmonth for totals; transactions_1k for product-level detail +SELECT + t.CustomerID, + c.Segment, + SUM(t.Amount) AS diesel_spend +FROM transactions_1k t +JOIN customers c ON t.CustomerID = c.CustomerID +JOIN products p ON t.ProductID = p.ProductID +WHERE p.Description = 'Nafta' -- Czech for diesel + AND t.Date LIKE '2012%' -- transactions_1k.Date is text 'YYYY-MM-DD' +GROUP BY t.CustomerID, c.Segment +ORDER BY diesel_spend DESC +LIMIT 10; +``` + +--- + +## "How many gas stations are in each country?" + +```sql +-- Country codes: 'CZE', 'SVK', 'HUN' +SELECT + Country, + COUNT(*) AS station_count +FROM gasstations +GROUP BY Country +ORDER BY station_count DESC; +``` + +--- + +## "What is the monthly consumption trend for SME customers?" + +```sql +-- yearmonth has full monthly aggregates (not sampled) +SELECT + ym.Date AS year_month, + SUM(ym.Consumption) AS total_consumption, + COUNT(DISTINCT ym.CustomerID) AS sme_customers +FROM yearmonth ym +JOIN customers c ON ym.CustomerID = c.CustomerID +WHERE c.Segment = 'SME' +GROUP BY ym.Date +ORDER BY ym.Date; +``` + +--- + +## "Show transactions at Premium gas stations in Slovakia" + +```sql +SELECT + t.Date, + t.CustomerID, + t.Amount, + g.GasStationID, + g.Segment AS station_segment +FROM transactions_1k t +JOIN gasstations g ON t.GasStationID = g.GasStationID +WHERE g.Country = 'SVK' + AND g.Segment = 'Premium' +ORDER BY t.Date DESC; +``` + +--- + +## "What is the average transaction amount per product type?" + +```sql +SELECT + p.ProductID, + p.Description AS product_name, + COUNT(*) AS txn_count, + ROUND(AVG(t.Amount), 2) AS avg_amount, + SUM(t.Amount) AS total_amount +FROM transactions_1k t +JOIN products p ON t.ProductID = p.ProductID +GROUP BY p.ProductID, p.Description +ORDER BY avg_amount DESC; +``` diff --git a/src/skills/european-football-2-semantic-model/SKILL.md b/src/skills/european-football-2-semantic-model/SKILL.md new file mode 100644 index 0000000..429c3d4 --- /dev/null +++ b/src/skills/european-football-2-semantic-model/SKILL.md @@ -0,0 +1,104 @@ +--- +name: european-football-2-semantic-model +description: Semantic model for the european_football_2 database (Kaggle European Soccer dataset — matches, players, teams, leagues across 11 European countries). Load this skill when the user is querying the european_football_2 database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# European Football — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | API IDs vs primary keys, time-series attribute joins, home/away goal logic | `read_skill_resource("european-football-2-semantic-model", "references/gotchas.md")` | +| Metric definitions | Win rates, average goals per match, player ratings, form metrics | `read_skill_resource("european-football-2-semantic-model", "references/metrics.md")` | +| Query patterns | Team standings, top-rated players, head-to-head records | `read_skill_resource("european-football-2-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If joining teams or players to matches → load `references/gotchas.md` (API ID vs id is critical) +- If querying `Player_Attributes` or `Team_Attributes` → load `references/gotchas.md` (time-series trap) +- If computing total goals or wins → load `references/gotchas.md` + `references/metrics.md` +- For simple league or country lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "home team" | `Match.home_team_api_id` (join to `Team.team_api_id`) | verified | +| "away team" | `Match.away_team_api_id` (join to `Team.team_api_id`) | verified | +| "overall rating" | `Player_Attributes.overall_rating` (0–100 scale) | verified | +| "season" | `Match.season` — stored as text: `'2008/2009'`, `'2009/2010'`, etc. | verified | +| "league" | `League.name` — join: `Match.league_id → League.id` | verified | +| "country" | `Country.name` — join: `League.country_id → Country.id` | verified | +| "team rating" | `Team_Attributes.buildUpPlaySpeed` / `overall` etc. — time-series, filter by date | verified | +| "lineup" | `Match.home_player_1` … `Match.home_player_11` — store `player_api_id` values | verified | + +## Gotchas + +1. **Always join on `team_api_id` / `player_api_id`, NOT `id`** — the `id` + column is an internal SQLite/PostgreSQL row ID. The stable cross-table key + is `team_api_id` for teams and `player_api_id` for players. + +2. **`Player_Attributes` and `Team_Attributes` are time-series** — each player/team + has multiple rows across different dates. Joining without a date filter creates + a Cartesian product. Use a subquery to get the most recent record. + +3. **A team's total goals requires combining home and away** — `Match` stores + `home_team_goal` and `away_team_goal` separately. You need a CASE expression + to aggregate from both perspectives. + +4. **`Match.season` is a text field** — format is `'2008/2009'`. Filter with + `= '2008/2009'`, not `= 2008` or `= 2009`. + +5. **`Match` has 11 player columns per side** — `home_player_1` through + `home_player_11` each store a `player_api_id`. There is no normalised + player-per-match table; lineup queries require unpivoting these columns. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="european-football-2-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +Match.home_team_api_id ──→ Team.team_api_id (match ↔ home team) +Match.away_team_api_id ──→ Team.team_api_id (match ↔ away team) +Match.league_id ──→ League.id (match ↔ league) +League.country_id ──→ Country.id (league ↔ country) +Player_Attributes.player_api_id ──→ Player.player_api_id (attributes ↔ player) +Team_Attributes.team_api_id ──→ Team.team_api_id (attributes ↔ team) +Match.home_player_1..11 ──→ Player.player_api_id (lineup ↔ player) +``` + +There is no direct join between `Match` and `Player_Attributes`. Go through +`Player` via `player_api_id`. + +## Frequently Asked Queries + +For canonical query patterns (season standings, top scorers, player ratings), +call: +```python +read_skill_resource( + skill_name="european-football-2-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (goals per game, win rates, player rating trends), call: +```python +read_skill_resource( + skill_name="european-football-2-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/european-football-2-semantic-model/references/gotchas.md b/src/skills/european-football-2-semantic-model/references/gotchas.md new file mode 100644 index 0000000..6ef6a5f --- /dev/null +++ b/src/skills/european-football-2-semantic-model/references/gotchas.md @@ -0,0 +1,114 @@ +# Gotchas — european_football_2 + +## 1. Join on `team_api_id` / `player_api_id`, NOT the `id` column + +**Problem**: Every table has an `id` primary key, but the cross-table join key +is `team_api_id` (for teams) and `player_api_id` (for players). Joining on +`id` produces wrong matches or zero rows. + +**Correct usage**: +```sql +-- CORRECT: team name from a match +SELECT t.team_long_name +FROM Match m +JOIN Team t ON m.home_team_api_id = t.team_api_id +WHERE m.id = 1; + +-- WRONG — joins the match's row-id to the team's row-id (meaningless) +JOIN Team t ON m.id = t.id +``` + +--- + +## 2. `Player_Attributes` and `Team_Attributes` are time-series — always filter by date + +**Problem**: Each player and team has multiple attribute rows recorded at +different points in time. Joining without a date filter multiplies rows +(Cartesian explosion) and skews aggregations. + +**Correct pattern — most recent attributes**: +```sql +-- CORRECT: latest Player_Attributes per player +SELECT p.player_name, pa.overall_rating +FROM Player p +JOIN Player_Attributes pa ON p.player_api_id = pa.player_api_id +WHERE pa.date = ( + SELECT MAX(pa2.date) + FROM Player_Attributes pa2 + WHERE pa2.player_api_id = p.player_api_id +); + +-- WRONG — every historical snapshot, multiplied +JOIN Player_Attributes pa ON p.player_api_id = pa.player_api_id +-- (returns N rows per player where N = number of recorded snapshots) +``` + +--- + +## 3. A team's total goals must aggregate both home and away appearances + +**Problem**: `Match` records goals from each team's perspective separately: +`home_team_goal` when the team played at home, `away_team_goal` when away. +Summing only `home_team_goal` misses all away goals. + +**Correct pattern**: +```sql +-- CORRECT: total goals for a team across all matches +SELECT + t.team_long_name, + SUM( + CASE + WHEN m.home_team_api_id = t.team_api_id THEN m.home_team_goal + WHEN m.away_team_api_id = t.team_api_id THEN m.away_team_goal + ELSE 0 + END + ) AS total_goals +FROM Team t +JOIN Match m ON m.home_team_api_id = t.team_api_id + OR m.away_team_api_id = t.team_api_id +GROUP BY t.team_api_id, t.team_long_name; + +-- WRONG — only home goals +SELECT team_long_name, SUM(home_team_goal) FROM Match ... +``` + +--- + +## 4. `Match.season` is a text field, not a year integer + +**Problem**: Season is stored as `'2008/2009'`, not as an integer. Filtering +with `= 2008` or `EXTRACT(year FROM season)` fails. + +**Correct usage**: +```sql +-- CORRECT +SELECT COUNT(*) FROM Match WHERE season = '2008/2009'; + +-- CORRECT: all seasons containing '2012' +SELECT COUNT(*) FROM Match WHERE season LIKE '%2012%'; + +-- WRONG — type mismatch or zero rows +WHERE season = 2009 +WHERE EXTRACT(year FROM season) = 2009 -- season is text, not date +``` + +--- + +## 5. Player lineup columns (`home_player_1`…`home_player_11`) are `player_api_id` values + +**Problem**: To look up player names from a match lineup, join these columns +against `Player.player_api_id`, not `Player.id`. There are 22 such columns +per match (11 home + 11 away) — normalising them requires UNION or CROSS JOIN +LATERAL. + +**Correct usage**: +```sql +-- CORRECT: look up a specific home player slot +SELECT p.player_name +FROM Match m +JOIN Player p ON m.home_player_1 = p.player_api_id +WHERE m.id = 1; + +-- WRONG — home_player_1 contains player_api_id, not player.id +JOIN Player p ON m.home_player_1 = p.id +``` diff --git a/src/skills/european-football-2-semantic-model/references/metrics.md b/src/skills/european-football-2-semantic-model/references/metrics.md new file mode 100644 index 0000000..381a817 --- /dev/null +++ b/src/skills/european-football-2-semantic-model/references/metrics.md @@ -0,0 +1,85 @@ +# Metric Definitions — european_football_2 + +## Average Goals per Match by League and Season + +```sql +SELECT + l.name AS league_name, + m.season, + COUNT(*) AS match_count, + ROUND(AVG(m.home_team_goal + m.away_team_goal), 2) AS avg_goals_per_match +FROM Match m +JOIN League l ON m.league_id = l.id +GROUP BY l.name, m.season +ORDER BY l.name, m.season; +``` + +--- + +## Team Win Rate Across a Season + +```sql +-- Win = scored more than opponent (home or away) +SELECT + t.team_long_name, + COUNT(*) AS total_matches, + SUM( + CASE + WHEN m.home_team_api_id = t.team_api_id AND m.home_team_goal > m.away_team_goal THEN 1 + WHEN m.away_team_api_id = t.team_api_id AND m.away_team_goal > m.home_team_goal THEN 1 + ELSE 0 + END + ) AS wins, + ROUND( + SUM( + CASE + WHEN m.home_team_api_id = t.team_api_id AND m.home_team_goal > m.away_team_goal THEN 1 + WHEN m.away_team_api_id = t.team_api_id AND m.away_team_goal > m.home_team_goal THEN 1 + ELSE 0 + END + )::numeric / COUNT(*), + 4 + ) AS win_rate +FROM Team t +JOIN Match m ON m.home_team_api_id = t.team_api_id OR m.away_team_api_id = t.team_api_id +WHERE m.season = '2015/2016' +GROUP BY t.team_api_id, t.team_long_name +ORDER BY win_rate DESC; +``` + +--- + +## Top Players by Average Overall Rating (Most Recent Snapshot) + +```sql +WITH latest_attrs AS ( + SELECT player_api_id, overall_rating, + ROW_NUMBER() OVER (PARTITION BY player_api_id ORDER BY date DESC) AS rn + FROM Player_Attributes + WHERE overall_rating IS NOT NULL +) +SELECT + p.player_name, + la.overall_rating +FROM Player p +JOIN latest_attrs la ON p.player_api_id = la.player_api_id AND la.rn = 1 +ORDER BY la.overall_rating DESC +LIMIT 20; +``` + +--- + +## Home vs Away Goal Differential per Team + +```sql +SELECT + t.team_long_name, + SUM(CASE WHEN m.home_team_api_id = t.team_api_id THEN m.home_team_goal ELSE 0 END) AS home_goals_scored, + SUM(CASE WHEN m.away_team_api_id = t.team_api_id THEN m.away_team_goal ELSE 0 END) AS away_goals_scored, + SUM(CASE WHEN m.home_team_api_id = t.team_api_id THEN m.home_team_goal - m.away_team_goal ELSE 0 END) AS home_goal_diff, + SUM(CASE WHEN m.away_team_api_id = t.team_api_id THEN m.away_team_goal - m.home_team_goal ELSE 0 END) AS away_goal_diff +FROM Team t +JOIN Match m ON m.home_team_api_id = t.team_api_id OR m.away_team_api_id = t.team_api_id +GROUP BY t.team_api_id, t.team_long_name +ORDER BY home_goal_diff + away_goal_diff DESC; +``` diff --git a/src/skills/european-football-2-semantic-model/references/query_patterns.md b/src/skills/european-football-2-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..2074f37 --- /dev/null +++ b/src/skills/european-football-2-semantic-model/references/query_patterns.md @@ -0,0 +1,93 @@ +# Query Patterns — european_football_2 + +## "Which teams had the most wins in the Premier League in 2015/2016?" + +```sql +SELECT + t.team_long_name, + SUM( + CASE + WHEN m.home_team_api_id = t.team_api_id AND m.home_team_goal > m.away_team_goal THEN 1 + WHEN m.away_team_api_id = t.team_api_id AND m.away_team_goal > m.home_team_goal THEN 1 + ELSE 0 + END + ) AS wins +FROM Team t +JOIN Match m ON m.home_team_api_id = t.team_api_id OR m.away_team_api_id = t.team_api_id +JOIN League l ON m.league_id = l.id +WHERE l.name = 'England Premier League' + AND m.season = '2015/2016' +GROUP BY t.team_api_id, t.team_long_name +ORDER BY wins DESC +LIMIT 10; +``` + +--- + +## "What is the head-to-head record between two teams?" + +```sql +-- Replace team_api_ids with actual IDs from the Team table +SELECT + m.season, + m.date, + t_home.team_long_name AS home_team, + m.home_team_goal, + m.away_team_goal, + t_away.team_long_name AS away_team +FROM Match m +JOIN Team t_home ON m.home_team_api_id = t_home.team_api_id +JOIN Team t_away ON m.away_team_api_id = t_away.team_api_id +WHERE (m.home_team_api_id = 9825 AND m.away_team_api_id = 8650) + OR (m.home_team_api_id = 8650 AND m.away_team_api_id = 9825) +ORDER BY m.date; +``` + +--- + +## "Who are the highest-rated players in a specific league?" + +```sql +-- Uses most recent Player_Attributes snapshot +WITH latest_rating AS ( + SELECT player_api_id, overall_rating, + ROW_NUMBER() OVER (PARTITION BY player_api_id ORDER BY date DESC) AS rn + FROM Player_Attributes + WHERE overall_rating IS NOT NULL +) +SELECT + p.player_name, + lr.overall_rating, + t.team_long_name +FROM Player p +JOIN latest_rating lr ON p.player_api_id = lr.player_api_id AND lr.rn = 1 +JOIN Match m ON p.player_api_id IN ( + m.home_player_1, m.home_player_2, m.home_player_3, + m.home_player_4, m.home_player_5 +) +JOIN League l ON m.league_id = l.id +JOIN Team t ON m.home_team_api_id = t.team_api_id +WHERE l.name = 'Spain LIGA BBVA' + AND m.season = '2015/2016' +ORDER BY lr.overall_rating DESC +LIMIT 20; +``` + +--- + +## "How many goals per game were scored in each country's league in a season?" + +```sql +SELECT + c.name AS country, + l.name AS league, + COUNT(*) AS matches_played, + SUM(m.home_team_goal + m.away_team_goal) AS total_goals, + ROUND(AVG(m.home_team_goal + m.away_team_goal), 2) AS goals_per_match +FROM Match m +JOIN League l ON m.league_id = l.id +JOIN Country c ON l.country_id = c.id +WHERE m.season = '2015/2016' +GROUP BY c.name, l.name +ORDER BY goals_per_match DESC; +``` diff --git a/src/skills/financial-semantic-model/SKILL.md b/src/skills/financial-semantic-model/SKILL.md new file mode 100644 index 0000000..8736561 --- /dev/null +++ b/src/skills/financial-semantic-model/SKILL.md @@ -0,0 +1,106 @@ +--- +name: financial-semantic-model +description: Semantic model for the financial database (Czech banking PKDD 1999 dataset). Contains business definitions for banking — loans, accounts, transactions, clients, districts. Load this skill when the user is querying the financial database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 5 +--- + +# Financial — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Date format (YYMMDD integer), Czech text codes, district column names | `read_skill_resource("financial-semantic-model", "references/gotchas.md")` | +| Metric definitions | Loan default rates, avg balances, transaction flows | `read_skill_resource("financial-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for regional stats, client loans, account owners | `read_skill_resource("financial-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If the query involves dates or date arithmetic → load `references/gotchas.md` (YYMMDD format is critical) +- If the query involves loan status or default analysis → load `references/gotchas.md` + `references/metrics.md` +- If the query spans client → account → loan → district → load `references/query_patterns.md` +- For simple account or transaction lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "loan status" | `loan.status` — single letter: 'A'=Finished/OK, 'B'=Finished/Unpaid, 'C'=Running/OK, 'D'=Running/Debt | verified | +| "account owner" | `disp.type = 'OWNER'` — the primary account holder | verified | +| "disponent" | `disp.type = 'DISPONENT'` — secondary card holder, not owner | verified | +| "district name" | `district.a2` (lowercase) — e.g. 'Hl.m. Praha' | verified | +| "region" | `district.a3` (lowercase) — e.g. 'Prague', 'central Bohemia' | verified | +| "incoming transaction" | `trans.type = 'PRIJEM'` (Czech for credit/incoming) | verified | +| "outgoing transaction" | `trans.type = 'VYDAJ'` (Czech for debit/outgoing) | verified | +| "gold card" / "classic card" | `card.type` — values: 'gold', 'classic', 'electron' | verified | + +## Gotchas + +1. **Date columns are integers in YYMMDD format** — `account.date`, `loan.date`, + and `trans.date` store dates as integers like `930101` (= 1993-01-01). Never + compare them directly to ISO strings. Cast with `TO_DATE(date::text, 'YYMMDD')`. + +2. **`district` columns use cryptic codes `a1`–`a16` (all lowercase)** — there + are no human-readable column names. Key ones: `a1`=district_id, `a2`=name, + `a3`=region, `a4`=population, `a11`=avg salary. + +3. **Always join client→account through `disp`** — there is no direct FK from + `client` to `account`. The path is always: + `client.client_id → disp.client_id → disp.account_id → account.account_id`. + +4. **`trans.type` and `trans.operation` are Czech text** — `'PRIJEM'` means + credit, `'VYDAJ'` means debit. Operation values include `'VKLAD'` (cash + deposit), `'PREVOD Z UCTU'` (transfer from another account). + +5. **`disp.type` must be filtered when finding the account owner** — an account + can have both an OWNER and one or more DISPONENTs. Always add + `WHERE disp.type = 'OWNER'` when you want the primary client for an account. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="financial-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +client.client_id ──→ disp.client_id ──→ account.account_id +account.district_id ──→ district.district_id (account's home district) +client.district_id ──→ district.district_id (client's home district) +account.account_id ──→ loan.account_id (account ↔ loans) +account.account_id ──→ trans.account_id (account ↔ transactions) +account.account_id ──→ order.account_id (account ↔ standing orders) +disp.disp_id ──→ card.disp_id (disposition ↔ issued card) +``` + +Note: `client` has its own `district_id` (where the client lives); `account` +has a separate `district_id` (where the account was opened). These can differ. + +## Frequently Asked Queries + +For canonical query patterns (loan defaults by region, client demographics, +account ownership), call: +```python +read_skill_resource( + skill_name="financial-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (default rates, average loan amounts, transaction +balances), call: +```python +read_skill_resource( + skill_name="financial-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/financial-semantic-model/references/gotchas.md b/src/skills/financial-semantic-model/references/gotchas.md new file mode 100644 index 0000000..561cf33 --- /dev/null +++ b/src/skills/financial-semantic-model/references/gotchas.md @@ -0,0 +1,116 @@ +# Gotchas — financial + +## 1. Date columns are integers in YYMMDD format, not DATE types + +**Problem**: `account.date`, `loan.date`, `trans.date`, and `card.issued` store +dates as integers like `930101` (meaning 1993-01-01). Standard date comparisons +and `DATE_TRUNC` fail unless you cast first. + +**Correct usage**: +```sql +-- CORRECT: convert to DATE for comparison +SELECT * +FROM loan +WHERE TO_DATE(date::text, 'YYMMDD') BETWEEN '1997-01-01' AND '1997-12-31'; + +-- CORRECT: extract year +SELECT EXTRACT(year FROM TO_DATE(date::text, 'YYMMDD')) AS loan_year +FROM loan; + +-- WRONG — integer comparison gives wrong or nonsensical results +WHERE date > 970101 -- syntactically OK but semantically wrong +WHERE date::date ... -- CAST fails because 930101 is not a valid DATE literal +``` + +--- + +## 2. `district` columns have cryptic names `a1` through `a16` (all lowercase) + +**Problem**: The `district` table has no human-readable column names. All +demographic columns are named `a1`, `a2`, ..., `a16` in lowercase. Using +uppercase (e.g. `A2`) may work on case-insensitive systems but will fail on +case-sensitive PostgreSQL if quoted. + +| Column | Meaning | +|---|---| +| `a1` | district_id (PK) | +| `a2` | district name | +| `a3` | region name | +| `a4` | population | +| `a11` | average salary | + +**Correct usage**: +```sql +-- CORRECT +SELECT a2 AS district_name, a11 AS avg_salary +FROM district +WHERE a3 = 'south Bohemia'; + +-- WRONG — columns don't exist by these names +SELECT name, avg_salary FROM district; +SELECT "Name", "AvgSalary" FROM district; +``` + +--- + +## 3. No direct link from `client` to `account` — always go through `disp` + +**Problem**: There is no FK column `client.account_id` or `account.client_id`. +The `disp` (disposition) table is the required bridge. Skipping it leads to +a query that fails or returns wrong results. + +**Correct join path**: +```sql +-- CORRECT +SELECT c.client_id, a.account_id +FROM client c +JOIN disp d ON c.client_id = d.client_id +JOIN account a ON d.account_id = a.account_id; + +-- WRONG — no such column exists +JOIN account ON client.account_id = account.account_id +``` + +--- + +## 4. Filter `disp.type = 'OWNER'` to find the primary account holder + +**Problem**: One account can have multiple rows in `disp` — one OWNER plus +one or more DISPONENTs (authorised secondary card holders). Joining without +the type filter returns duplicate rows and non-owner clients. + +**Correct usage**: +```sql +-- CORRECT: primary holder only +SELECT c.client_id, a.account_id +FROM client c +JOIN disp d ON c.client_id = d.client_id AND d.type = 'OWNER' +JOIN account a ON d.account_id = a.account_id; + +-- WRONG — returns both owner and disponents, causing row duplication +JOIN disp d ON c.client_id = d.client_id -- missing type filter +``` + +--- + +## 5. `trans.type` and `trans.operation` are Czech-language strings + +**Problem**: Transaction direction uses Czech vocabulary, not English. +Filtering on English terms returns zero rows. + +| Column | Czech value | English meaning | +|---|---|---| +| `trans.type` | `'PRIJEM'` | credit / incoming | +| `trans.type` | `'VYDAJ'` | debit / outgoing | +| `trans.operation` | `'VKLAD'` | cash deposit | +| `trans.operation` | `'PREVOD Z UCTU'` | transfer from another account | +| `trans.operation` | `'PREVOD NA UCET'` | transfer to another account | + +```sql +-- CORRECT +SELECT SUM(amount) FROM trans WHERE type = 'PRIJEM'; -- total credits +SELECT SUM(amount) FROM trans WHERE type = 'VYDAJ'; -- total debits + +-- WRONG +WHERE type = 'CREDIT' OR type = 'INCOMING' -- returns zero rows +``` diff --git a/src/skills/financial-semantic-model/references/metrics.md b/src/skills/financial-semantic-model/references/metrics.md new file mode 100644 index 0000000..523016e --- /dev/null +++ b/src/skills/financial-semantic-model/references/metrics.md @@ -0,0 +1,81 @@ +# Metric Definitions — financial + +## Loan Default Rate (Finished Loans Only) + +```sql +-- Among finished loans, what fraction ended with an unpaid balance? +-- status 'A' = finished OK, 'B' = finished unpaid (defaulted) +SELECT + ROUND( + SUM(CASE WHEN status = 'B' THEN 1 ELSE 0 END)::numeric / COUNT(*), + 4 + ) AS default_rate +FROM loan +WHERE status IN ('A', 'B'); +``` + +--- + +## Average Loan Amount by Status + +```sql +-- Average loan size for each status category +SELECT + status, + CASE status + WHEN 'A' THEN 'Finished/OK' + WHEN 'B' THEN 'Finished/Unpaid' + WHEN 'C' THEN 'Running/OK' + WHEN 'D' THEN 'Running/Debt' + END AS status_description, + COUNT(*) AS loan_count, + ROUND(AVG(amount), 2) AS avg_amount +FROM loan +GROUP BY status +ORDER BY status; +``` + +--- + +## Net Transaction Flow per Account + +```sql +-- Credit minus debit per account (net balance change from transactions) +SELECT + account_id, + SUM(CASE WHEN type = 'PRIJEM' THEN amount ELSE 0 END) AS total_credit, + SUM(CASE WHEN type = 'VYDAJ' THEN amount ELSE 0 END) AS total_debit, + SUM(CASE WHEN type = 'PRIJEM' THEN amount ELSE -amount END) AS net_flow +FROM trans +GROUP BY account_id +ORDER BY net_flow DESC; +``` + +--- + +## Average Salary by Region + +```sql +-- Average salary across districts, grouped by region +SELECT + a3 AS region, + ROUND(AVG(a11), 2) AS avg_salary, + COUNT(*) AS district_count +FROM district +GROUP BY a3 +ORDER BY avg_salary DESC; +``` + +--- + +## Card Type Distribution + +```sql +-- How many of each card type have been issued? +SELECT + type AS card_type, + COUNT(*) AS issued_count +FROM card +GROUP BY type +ORDER BY issued_count DESC; +``` diff --git a/src/skills/financial-semantic-model/references/query_patterns.md b/src/skills/financial-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..54cc989 --- /dev/null +++ b/src/skills/financial-semantic-model/references/query_patterns.md @@ -0,0 +1,91 @@ +# Query Patterns — financial + +## "Find all account owners in a specific district" + +```sql +-- Uses district.a2 for district name (not a column called 'name') +SELECT c.client_id, a.account_id, dist.a2 AS district_name +FROM client c +JOIN disp d ON c.client_id = d.client_id AND d.type = 'OWNER' +JOIN account a ON d.account_id = a.account_id +JOIN district dist ON c.district_id = dist.a1 +WHERE dist.a2 = 'Hl.m. Praha' +ORDER BY c.client_id; +``` + +--- + +## "List loans that are currently in debt (running with missed payments)" + +```sql +-- status 'D' = running loan with arrears +SELECT + l.loan_id, + l.account_id, + l.amount, + l.payments, + TO_DATE(l.date::text, 'YYMMDD') AS loan_start_date +FROM loan l +WHERE l.status = 'D' +ORDER BY l.amount DESC; +``` + +--- + +## "Show the complete client → account → loan chain for a specific client" + +```sql +SELECT + c.client_id, + c.birth_date, + a.account_id, + TO_DATE(a.date::text, 'YYMMDD') AS account_opened, + l.loan_id, + l.amount AS loan_amount, + l.status AS loan_status +FROM client c +JOIN disp d ON c.client_id = d.client_id AND d.type = 'OWNER' +JOIN account a ON d.account_id = a.account_id +LEFT JOIN loan l ON a.account_id = l.account_id +WHERE c.client_id = 1; +``` + +--- + +## "What is the transaction history for a given account in a date range?" + +```sql +-- Dates stored as YYMMDD integers — must cast for range comparison +SELECT + trans_id, + TO_DATE(date::text, 'YYMMDD') AS trans_date, + type, + operation, + amount, + balance +FROM trans +WHERE account_id = 1 + AND TO_DATE(date::text, 'YYMMDD') BETWEEN '1998-01-01' AND '1998-12-31' +ORDER BY date; +``` + +--- + +## "Which regions have the highest average loan default rates?" + +```sql +SELECT + dist.a3 AS region, + COUNT(l.loan_id) AS total_loans, + SUM(CASE WHEN l.status = 'B' THEN 1 ELSE 0 END) AS defaulted, + ROUND( + SUM(CASE WHEN l.status = 'B' THEN 1 ELSE 0 END)::numeric / + NULLIF(SUM(CASE WHEN l.status IN ('A','B') THEN 1 ELSE 0 END), 0), + 4 + ) AS default_rate +FROM district dist +JOIN account a ON a.district_id = dist.a1 +JOIN loan l ON l.account_id = a.account_id +GROUP BY dist.a3 +ORDER BY default_rate DESC NULLS LAST; +``` diff --git a/src/skills/formula-1-semantic-model/SKILL.md b/src/skills/formula-1-semantic-model/SKILL.md new file mode 100644 index 0000000..d7987d3 --- /dev/null +++ b/src/skills/formula-1-semantic-model/SKILL.md @@ -0,0 +1,104 @@ +--- +name: formula-1-semantic-model +description: Semantic model for the formula_1 database (Ergast F1 historical dataset — races, drivers, constructors, results, qualifying, pit stops, lap times). Load this skill when the user is querying the formula_1 database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 5 +--- + +# Formula 1 — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Time string vs milliseconds, NULL positions, positionText values, standings pitfalls | `read_skill_resource("formula-1-semantic-model", "references/gotchas.md")` | +| Metric definitions | Points totals, win counts, pit stop averages, championship standings | `read_skill_resource("formula-1-semantic-model", "references/metrics.md")` | +| Query patterns | Driver standings, constructor wins, fastest laps, DNF analysis | `read_skill_resource("formula-1-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If the query involves timing or lap times → load `references/gotchas.md` (time columns are strings) +- If the query involves standings or season totals → load `references/gotchas.md` (standings are cumulative) +- If aggregating wins, points, or positions → load `references/metrics.md` +- For simple race or driver lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "race winner" | `results.position = 1` (integer — NULL for non-finishers) | verified | +| "did not finish" / "DNF" | `results.position IS NULL` or `status.status` not equal to `'Finished'` | verified | +| "constructor" / "team" | `constructors.name` — joined via `results.constructorId` | verified | +| "grid position" | `results.grid` (starting position) — separate from finishing `results.position` | verified | +| "fastest lap" | `results.rank = 1` (fastest lap rank within the race) | verified | +| "season" | `races.year` (integer, e.g. `2021`) | verified | +| "race time" | `results.milliseconds` — use this for arithmetic; `results.time` is a formatted string | verified | +| "DNF reason" | `status.status` — joined via `results.statusId → status.statusId` | verified | + +## Gotchas + +1. **Time columns are strings — use `milliseconds` for arithmetic** — `results.time`, + `qualifying.q1/q2/q3`, `laptimes.time`, and `pitstops.duration` are formatted + strings like `"1:23.456"`. Only the `milliseconds` integer column is safe for + math and aggregation. + +2. **`results.position` is NULL for non-finishers** — drivers who retired, + were disqualified, or did not start have NULL in `position`. Use `positionOrder` + (always populated) to rank all starters, or filter on `status` for DNF analysis. + +3. **`driverstandings` and `constructorstandings` are cumulative per race** — + these tables store the running championship total after each race, not per-race + points. For the season total, filter to the last race of the season. + +4. **`results.positionText` contains non-numeric codes** — values include `'R'` + (retired), `'D'` (disqualified), `'W'` (withdrawn), `'F'` (failed to qualify), + `'N'` (not classified). Never cast `positionText` to integer without guarding. + +5. **`pitstops` has both `duration` (text) and `milliseconds` (integer)** — + always use `milliseconds` for pit stop duration math. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="formula-1-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +races.raceId ──→ results.raceId ──→ drivers.driverId +races.raceId ──→ results.raceId ──→ constructors.constructorId +races.raceId ──→ qualifying.raceId ──→ drivers.driverId +races.raceId ──→ laptimes.raceId ──→ drivers.driverId +races.raceId ──→ pitstops.raceId ──→ drivers.driverId +races.circuitId ──→ circuits.circuitId +results.statusId ──→ status.statusId (DNF reason) +races.raceId ──→ driverstandings.raceId +races.raceId ──→ constructorstandings.raceId +``` + +## Frequently Asked Queries + +For canonical query patterns (season champions, win counts, fastest laps), call: +```python +read_skill_resource( + skill_name="formula-1-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (points per season, pit stop averages, constructor wins), +call: +```python +read_skill_resource( + skill_name="formula-1-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/formula-1-semantic-model/references/gotchas.md b/src/skills/formula-1-semantic-model/references/gotchas.md new file mode 100644 index 0000000..d09a00f --- /dev/null +++ b/src/skills/formula-1-semantic-model/references/gotchas.md @@ -0,0 +1,114 @@ +# Gotchas — formula_1 + +## 1. Time columns are formatted strings — use `milliseconds` for arithmetic + +**Problem**: `results.time`, `qualifying.q1`, `qualifying.q2`, `qualifying.q3`, +`laptimes.time`, and `pitstops.duration` are text strings like `"1:23.456"`. +Arithmetic, MIN/MAX, and ORDER BY on these strings gives wrong results. + +**Correct usage**: +```sql +-- CORRECT: fastest race completion time using milliseconds +SELECT d.forename, d.surname, MIN(r.milliseconds) AS fastest_ms +FROM results r +JOIN drivers d ON r.driverId = d.driverId +WHERE r.milliseconds IS NOT NULL +GROUP BY d.driverId +ORDER BY fastest_ms; + +-- WRONG — string comparison, not numeric +SELECT MIN(r.time) FROM results r -- '1:20.000' sorts before '1:19.999' as strings +``` + +--- + +## 2. `results.position` is NULL for non-finishers + +**Problem**: Drivers who retired, were disqualified, or failed to start have +`NULL` in `results.position`. Filtering `WHERE position > 0` silently drops +these rows; aggregating position can give misleading averages. + +**Correct usage**: +```sql +-- CORRECT: all finishers +SELECT * FROM results WHERE position IS NOT NULL; + +-- CORRECT: all starters in finishing order (including DNFs) +SELECT * FROM results ORDER BY positionOrder; + +-- CORRECT: count DNFs +SELECT COUNT(*) FROM results r +JOIN status s ON r.statusId = s.statusId +WHERE s.status != 'Finished'; + +-- WRONG — drops non-finishers silently +WHERE position BETWEEN 1 AND 20 +``` + +--- + +## 3. `driverstandings` / `constructorstandings` are cumulative, not per-race + +**Problem**: These tables store the running championship points AFTER each race. +Summing all rows for a season returns the sum of all running totals, not the +season total. + +**Correct usage — season final standings**: +```sql +-- CORRECT: championship standings after the last race of 2021 +SELECT + d.forename, d.surname, + ds.points AS season_total, + ds.position AS championship_position +FROM driverstandings ds +JOIN drivers d ON ds.driverId = d.driverId +WHERE ds.raceId = ( + SELECT MAX(raceId) FROM races WHERE year = 2021 +) +ORDER BY ds.position; + +-- WRONG — sums all intermediate totals +SELECT driverId, SUM(points) FROM driverstandings +WHERE raceId IN (SELECT raceId FROM races WHERE year = 2021) +GROUP BY driverId; +``` + +--- + +## 4. `results.positionText` contains non-numeric codes + +**Problem**: `positionText` stores things like `'R'` (retired), `'D'` +(disqualified), `'W'` (withdrawn). Casting to integer fails for these rows. + +**Correct usage**: +```sql +-- CORRECT: only numeric positions +SELECT * FROM results WHERE positionText ~ '^\d+$'; + +-- CORRECT: cast safely +SELECT CASE WHEN positionText ~ '^\d+$' THEN positionText::integer + ELSE NULL END AS position_int +FROM results; + +-- WRONG — error on 'R', 'D', etc. +SELECT positionText::integer FROM results; +``` + +--- + +## 5. `results.grid = 0` means started from the pit lane + +**Problem**: A `grid` value of `0` does not mean the driver started first — it +means they started from the pit lane (e.g. after a penalty or car change). + +**Correct usage**: +```sql +-- CORRECT: exclude pit lane starts when analysing grid positions +SELECT * FROM results WHERE grid > 0; + +-- To identify pit lane starts: +SELECT r.raceId, d.forename, d.surname +FROM results r +JOIN drivers d ON r.driverId = d.driverId +WHERE r.grid = 0; +``` diff --git a/src/skills/formula-1-semantic-model/references/metrics.md b/src/skills/formula-1-semantic-model/references/metrics.md new file mode 100644 index 0000000..c1cff61 --- /dev/null +++ b/src/skills/formula-1-semantic-model/references/metrics.md @@ -0,0 +1,94 @@ +# Metric Definitions — formula_1 + +## Total Championship Points per Driver in a Season + +```sql +-- Use the last race of the season to get final standings +SELECT + d.forename || ' ' || d.surname AS driver_name, + d.nationality, + ds.points AS season_points, + ds.wins, + ds.position AS championship_rank +FROM driverstandings ds +JOIN drivers d ON ds.driverId = d.driverId +WHERE ds.raceId = ( + SELECT MAX(raceId) FROM races WHERE year = 2021 +) +ORDER BY ds.position; +``` + +--- + +## Win Count by Driver (All Time) + +```sql +SELECT + d.forename || ' ' || d.surname AS driver_name, + d.nationality, + COUNT(*) AS race_wins +FROM results r +JOIN drivers d ON r.driverId = d.driverId +WHERE r.position = 1 +GROUP BY d.driverId, d.forename, d.surname, d.nationality +ORDER BY race_wins DESC +LIMIT 20; +``` + +--- + +## Constructor Wins by Season + +```sql +SELECT + c.name AS constructor, + ra.year AS season, + COUNT(*) AS wins +FROM results r +JOIN constructors c ON r.constructorId = c.constructorId +JOIN races ra ON r.raceId = ra.raceId +WHERE r.position = 1 +GROUP BY c.constructorId, c.name, ra.year +ORDER BY ra.year DESC, wins DESC; +``` + +--- + +## Average Pit Stop Duration per Driver per Race + +```sql +-- pitstops.milliseconds is reliable; pitstops.duration is a text string +SELECT + ra.name AS race_name, + d.forename || ' ' || d.surname AS driver_name, + COUNT(ps.stop) AS pit_stop_count, + ROUND(AVG(ps.milliseconds), 0) AS avg_pit_ms, + SUM(ps.milliseconds) AS total_pit_ms +FROM pitstops ps +JOIN races ra ON ps.raceId = ra.raceId +JOIN drivers d ON ps.driverId = d.driverId +WHERE ra.year = 2021 +GROUP BY ra.raceId, ra.name, d.driverId, d.forename, d.surname +ORDER BY avg_pit_ms; +``` + +--- + +## DNF Rate by Constructor + +```sql +SELECT + c.name AS constructor, + COUNT(*) AS total_entries, + SUM(CASE WHEN s.status != 'Finished' AND s.status NOT LIKE '+%' THEN 1 ELSE 0 END) AS dnfs, + ROUND( + SUM(CASE WHEN s.status != 'Finished' AND s.status NOT LIKE '+%' THEN 1 ELSE 0 END)::numeric + / COUNT(*), + 4 + ) AS dnf_rate +FROM results r +JOIN constructors c ON r.constructorId = c.constructorId +JOIN status s ON r.statusId = s.statusId +GROUP BY c.constructorId, c.name +ORDER BY dnf_rate DESC; +``` diff --git a/src/skills/formula-1-semantic-model/references/query_patterns.md b/src/skills/formula-1-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..05caca7 --- /dev/null +++ b/src/skills/formula-1-semantic-model/references/query_patterns.md @@ -0,0 +1,95 @@ +# Query Patterns — formula_1 + +## "Who won the most races in a given season?" + +```sql +SELECT + d.forename || ' ' || d.surname AS driver_name, + COUNT(*) AS wins +FROM results r +JOIN drivers d ON r.driverId = d.driverId +JOIN races ra ON r.raceId = ra.raceId +WHERE r.position = 1 + AND ra.year = 2021 +GROUP BY d.driverId, d.forename, d.surname +ORDER BY wins DESC; +``` + +--- + +## "What were the final championship standings for the 2021 season?" + +```sql +-- Use the last race of the season for final points totals +SELECT + ds.position AS rank, + d.forename || ' ' || d.surname AS driver, + d.nationality, + ds.points, + ds.wins +FROM driverstandings ds +JOIN drivers d ON ds.driverId = d.driverId +WHERE ds.raceId = ( + SELECT MAX(raceId) FROM races WHERE year = 2021 +) +ORDER BY ds.position; +``` + +--- + +## "Why did a driver retire from a specific race?" + +```sql +-- Join results to status for the DNF reason +SELECT + d.forename || ' ' || d.surname AS driver, + ra.name AS race, + ra.year, + s.status AS retirement_reason, + r.laps AS laps_completed +FROM results r +JOIN drivers d ON r.driverId = d.driverId +JOIN races ra ON r.raceId = ra.raceId +JOIN status s ON r.statusId = s.statusId +WHERE ra.name = 'British Grand Prix' + AND ra.year = 2021 + AND s.status != 'Finished' +ORDER BY r.positionOrder; +``` + +--- + +## "Which circuit has the most races in F1 history?" + +```sql +SELECT + ci.name AS circuit_name, + ci.country, + COUNT(*) AS race_count +FROM races ra +JOIN circuits ci ON ra.circuitId = ci.circuitId +GROUP BY ci.circuitId, ci.name, ci.country +ORDER BY race_count DESC +LIMIT 10; +``` + +--- + +## "What is the qualifying vs race position change for each driver in a race?" + +```sql +SELECT + d.forename || ' ' || d.surname AS driver, + r.grid AS qualifying_position, + r.position AS finish_position, + r.grid - r.position AS positions_gained, + s.status +FROM results r +JOIN drivers d ON r.driverId = d.driverId +JOIN races ra ON r.raceId = ra.raceId +JOIN status s ON r.statusId = s.statusId +WHERE ra.name = 'Monaco Grand Prix' + AND ra.year = 2021 + AND r.grid > 0 -- exclude pit lane starts +ORDER BY r.positionOrder; +``` diff --git a/src/skills/student-club-semantic-model/SKILL.md b/src/skills/student-club-semantic-model/SKILL.md new file mode 100644 index 0000000..34550b1 --- /dev/null +++ b/src/skills/student-club-semantic-model/SKILL.md @@ -0,0 +1,103 @@ +--- +name: student-club-semantic-model +description: Semantic model for the student_club database (college student club events, members, budgets, expenses, income). Load this skill when the user is querying the student_club database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# Student Club — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Airtable-style IDs, FK column naming, boolean-as-string, budget vs expense columns | `read_skill_resource("student-club-semantic-model", "references/gotchas.md")` | +| Metric definitions | Attendance counts, budget utilisation, expense totals | `read_skill_resource("student-club-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for event attendance, expense approvals, member roles | `read_skill_resource("student-club-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If joining `attendance`, `expense`, or `budget` tables → load `references/gotchas.md` (non-standard FK naming) +- If filtering by `expense.approved` → load `references/gotchas.md` (stored as string, not boolean) +- If computing budget utilisation → load `references/metrics.md` +- For simple member or event lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "event attendance" | `attendance` table — `link_to_event` + `link_to_member` (composite PK) | verified | +| "event type" | `event.type` — values: `'Meeting'`, `'Election'`, `'Social'`, `'Speaker'`, etc. | verified | +| "event status" | `event.status` — `'Open'` or `'Closed'` | verified | +| "approved expense" | `expense.approved = 'true'` (string, not SQL boolean) | verified | +| "budget amount" | `budget.amount` — the budgeted allocation | verified | +| "actual spend" | `budget.spent` — amount actually spent (separate from `budget.amount`) | verified | +| "remaining budget" | `budget.remaining` = `budget.amount - budget.spent` (pre-computed) | verified | +| "member role" | `member.role` — e.g. `'Member'`, `'Officer'` | verified | + +## Gotchas + +1. **All primary keys are Airtable-style base64 strings** — IDs start with `rec` + followed by alphanumeric characters. Never cast to integer. + +2. **FK columns use `link_to_*` naming, not `_id` suffix** — the FK from + `attendance` to `event` is `link_to_event`, not `event_id`. Likewise for + `link_to_member`, `link_to_budget`. + +3. **`expense.approved` is a string `'true'` or `'false'`**, not a SQL boolean. + Filter with `WHERE approved = 'true'`, not `WHERE approved = TRUE`. + +4. **`budget.amount` and `budget.spent` are different columns** — `amount` + is the allocated budget; `spent` is what was actually spent. Do not treat + them as the same metric. + +5. **`member.zip` joins to `zip_code.zip_code`** — for city/state lookups, + join on this column (not a typical `_id` FK). + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="student-club-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +attendance.link_to_event ──→ event.event_id +attendance.link_to_member ──→ member.member_id +budget.link_to_event ──→ event.event_id +expense.link_to_member ──→ member.member_id +expense.link_to_budget ──→ budget.budget_id +member.zip ──→ zip_code.zip_code +member.major ──→ major.major_name (if FK exists) +``` + +There is no direct join between `expense` and `event` — go through +`expense → budget → event`. + +## Frequently Asked Queries + +For canonical query patterns (event attendance, expense approvals, budget +utilisation), call: +```python +read_skill_resource( + skill_name="student-club-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (total spend, attendance per event, budget utilisation), +call: +```python +read_skill_resource( + skill_name="student-club-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/student-club-semantic-model/references/gotchas.md b/src/skills/student-club-semantic-model/references/gotchas.md new file mode 100644 index 0000000..825ce23 --- /dev/null +++ b/src/skills/student-club-semantic-model/references/gotchas.md @@ -0,0 +1,98 @@ +# Gotchas — student_club + +## 1. All IDs are Airtable-style base64 strings — never cast to integer + +**Problem**: Primary keys look like `recABC123XYZ` — they are base64-encoded +Airtable record IDs. Casting to integer fails; using them in numeric comparisons +gives wrong results. + +**Correct usage**: +```sql +-- CORRECT +SELECT * FROM event WHERE event_id = 'recChpCTUhNMc3BsS'; + +-- WRONG — fails or returns zero rows +WHERE event_id = 1 +WHERE event_id::integer = 1 +``` + +--- + +## 2. FK columns use `link_to_*` naming, not `_id` suffix + +**Problem**: The `attendance` table has `link_to_event` and `link_to_member` +as FK columns — not `event_id` or `member_id`. Trying to join on conventional +`_id` column names fails. + +**Correct join**: +```sql +-- CORRECT +SELECT e.event_name, m.name AS member_name +FROM attendance a +JOIN event e ON a.link_to_event = e.event_id +JOIN member m ON a.link_to_member = m.member_id; + +-- WRONG — column does not exist +JOIN event e ON a.event_id = e.event_id +``` + +--- + +## 3. `expense.approved` is a string `'true'`/`'false'`, not a SQL boolean + +**Problem**: The approved column stores string literals, not SQL boolean TRUE/FALSE. +Using `WHERE approved = TRUE` may coerce or return wrong results. + +**Correct usage**: +```sql +-- CORRECT +SELECT * FROM expense WHERE approved = 'true'; +SELECT * FROM expense WHERE approved = 'false'; + +-- WRONG — type mismatch, may silently fail +WHERE approved = TRUE +WHERE approved IS TRUE +``` + +--- + +## 4. `budget.amount` ≠ `budget.spent` — they measure different things + +**Problem**: `budget.amount` is the allocated budget for a category; +`budget.spent` is what was actually disbursed. `budget.remaining` is a +pre-computed column (`amount - spent`). Conflating these gives wrong financials. + +**Correct usage**: +```sql +-- CORRECT: budget utilisation rate +SELECT + category, + amount AS budgeted, + spent AS actual_spend, + remaining, + ROUND(spent::numeric / NULLIF(amount, 0), 4) AS utilisation_rate +FROM budget; + +-- WRONG — treating amount as spend +SELECT category, SUM(amount) AS total_spend FROM budget GROUP BY category; +-- (This returns the budgeted total, not the actual spend) +``` + +--- + +## 5. To link `expense` to `event`, go through `budget` + +**Problem**: There is no direct FK from `expense` to `event`. The path is +`expense → budget → event` via `link_to_budget` then `link_to_event`. + +**Correct join chain**: +```sql +-- CORRECT +SELECT e.event_name, ex.expense_description, ex.cost +FROM expense ex +JOIN budget b ON ex.link_to_budget = b.budget_id +JOIN event e ON b.link_to_event = e.event_id; + +-- WRONG — no such column +JOIN event e ON ex.link_to_event = e.event_id +``` diff --git a/src/skills/student-club-semantic-model/references/metrics.md b/src/skills/student-club-semantic-model/references/metrics.md new file mode 100644 index 0000000..248e1de --- /dev/null +++ b/src/skills/student-club-semantic-model/references/metrics.md @@ -0,0 +1,84 @@ +# Metric Definitions — student_club + +## Attendance Count per Event + +```sql +SELECT + e.event_name, + e.type AS event_type, + e.event_date, + COUNT(a.link_to_member) AS attendee_count +FROM event e +LEFT JOIN attendance a ON a.link_to_event = e.event_id +GROUP BY e.event_id, e.event_name, e.type, e.event_date +ORDER BY attendee_count DESC; +``` + +--- + +## Budget Utilisation by Category + +```sql +-- amount = allocated, spent = actual, remaining = pre-computed +SELECT + category, + SUM(amount) AS total_budgeted, + SUM(spent) AS total_spent, + SUM(remaining) AS total_remaining, + ROUND(SUM(spent)::numeric / NULLIF(SUM(amount), 0), 4) AS utilisation_rate +FROM budget +GROUP BY category +ORDER BY utilisation_rate DESC; +``` + +--- + +## Total Approved Expenses per Member + +```sql +-- expense.approved is a string 'true'/'false' +SELECT + m.name AS member_name, + m.role, + COUNT(*) AS approved_expense_count, + SUM(ex.cost) AS total_approved_spend +FROM expense ex +JOIN member m ON ex.link_to_member = m.member_id +WHERE ex.approved = 'true' +GROUP BY m.member_id, m.name, m.role +ORDER BY total_approved_spend DESC; +``` + +--- + +## Income by Source + +```sql +SELECT + source, + COUNT(*) AS income_entries, + SUM(amount) AS total_income +FROM income +GROUP BY source +ORDER BY total_income DESC; +``` + +--- + +## Member Attendance Rate (Events Attended / Total Events) + +```sql +SELECT + m.name, + m.role, + COUNT(a.link_to_event) AS events_attended, + (SELECT COUNT(*) FROM event) AS total_events, + ROUND( + COUNT(a.link_to_event)::numeric / NULLIF((SELECT COUNT(*) FROM event), 0), + 4 + ) AS attendance_rate +FROM member m +LEFT JOIN attendance a ON m.member_id = a.link_to_member +GROUP BY m.member_id, m.name, m.role +ORDER BY attendance_rate DESC; +``` diff --git a/src/skills/student-club-semantic-model/references/query_patterns.md b/src/skills/student-club-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..ceb3ce9 --- /dev/null +++ b/src/skills/student-club-semantic-model/references/query_patterns.md @@ -0,0 +1,82 @@ +# Query Patterns — student_club + +## "Who attended a specific event?" + +```sql +-- FK columns use link_to_* naming, not _id suffix +SELECT m.name, m.role, m.email +FROM attendance a +JOIN event e ON a.link_to_event = e.event_id +JOIN member m ON a.link_to_member = m.member_id +WHERE e.event_name = 'October Meeting' +ORDER BY m.name; +``` + +--- + +## "What expenses have been approved for a specific event?" + +```sql +-- No direct expense→event FK; go through budget +SELECT + e.event_name, + b.category, + ex.expense_description, + ex.cost, + ex.expense_date +FROM expense ex +JOIN budget b ON ex.link_to_budget = b.budget_id +JOIN event e ON b.link_to_event = e.event_id +WHERE ex.approved = 'true' -- string, not boolean + AND e.event_name = 'Annual Banquet' +ORDER BY ex.cost DESC; +``` + +--- + +## "Which events are currently open?" + +```sql +SELECT + event_id, + event_name, + type, + event_date, + location +FROM event +WHERE status = 'Open' +ORDER BY event_date; +``` + +--- + +## "Show the budget vs actual spend for all events" + +```sql +SELECT + e.event_name, + e.event_date, + SUM(b.amount) AS total_budgeted, + SUM(b.spent) AS total_spent, + SUM(b.remaining) AS total_remaining +FROM event e +JOIN budget b ON b.link_to_event = e.event_id +GROUP BY e.event_id, e.event_name, e.event_date +ORDER BY e.event_date; +``` + +--- + +## "Which members are officers?" + +```sql +SELECT + member_id, + name, + email, + role, + major +FROM member +WHERE role = 'Officer' +ORDER BY name; +``` diff --git a/src/skills/superhero-semantic-model/SKILL.md b/src/skills/superhero-semantic-model/SKILL.md new file mode 100644 index 0000000..624b913 --- /dev/null +++ b/src/skills/superhero-semantic-model/SKILL.md @@ -0,0 +1,106 @@ +--- +name: superhero-semantic-model +description: Semantic model for the superhero database (comic book heroes and villains — publishers, physical attributes, superpowers, alignment). Load this skill when the user is querying the superhero database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# Superhero — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Zero sentinel for height/weight, three colour FK columns, NULL publishers, alignment values | `read_skill_resource("superhero-semantic-model", "references/gotchas.md")` | +| Metric definitions | Average height/weight by publisher, power score distributions | `read_skill_resource("superhero-semantic-model", "references/metrics.md")` | +| Query patterns | Heroes by alignment, publisher comparisons, power queries | `read_skill_resource("superhero-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If aggregating height or weight → load `references/gotchas.md` (zero sentinel values skew averages) +- If joining to the `colour` table → load `references/gotchas.md` (three FK columns, all to the same table) +- If counting powers or attribute scores → load `references/metrics.md` +- For simple alignment or publisher lookups → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "hero" / "villain" | `alignment.alignment = 'Good'` / `alignment.alignment = 'Bad'` | verified | +| "neutral" | `alignment.alignment = 'Neutral'` | verified | +| "unknown alignment" | `alignment.alignment = '-'` | verified | +| "publisher" | `publisher.publisher_name` — e.g. `'DC Comics'`, `'Marvel Comics'` | verified | +| "eye colour" | `superhero.eye_colour_id` → `colour.colour` | verified | +| "hair colour" | `superhero.hair_colour_id` → `colour.colour` | verified | +| "skin colour" | `superhero.skin_colour_id` → `colour.colour` | verified | +| "power score" | `hero_attribute.attribute_value` (0–100) for a specific `attribute.attribute_name` | verified | +| "no colour" | `colour.colour = 'No Colour'` — treat as missing/not applicable | verified | + +## Gotchas + +1. **`height_cm` and `weight_kg` use `0` as the sentinel for missing data** — + always filter `WHERE height_cm != 0` and `WHERE weight_kg != 0` before + aggregating physical measurements. + +2. **Three colour FK columns all join to the same `colour` table** — you must + alias the table three times: once for eye colour, once for hair colour, once + for skin colour. Joining without aliases causes ambiguity errors. + +3. **`publisher_id` is NULL for some heroes** — not all heroes have a known + publisher. Use `LEFT JOIN publisher` and handle NULL in output. + +4. **`alignment.alignment` includes `'-'` for unknown** — do not assume the + three string values 'Good', 'Bad', 'Neutral' are exhaustive. + +5. **`hero_power` is a junction table — one row per hero-power pair** — to + count all powers for a hero, `COUNT(*)` on `hero_power` after filtering by + `hero_id`. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="superhero-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +superhero.alignment_id ──→ alignment.id +superhero.gender_id ──→ gender.id +superhero.race_id ──→ race.id +superhero.publisher_id ──→ publisher.id (nullable) +superhero.eye_colour_id ──→ colour.id (alias: eye_col) +superhero.hair_colour_id ──→ colour.id (alias: hair_col) +superhero.skin_colour_id ──→ colour.id (alias: skin_col) +hero_attribute.hero_id ──→ superhero.id +hero_attribute.attribute_id ─→ attribute.id +hero_power.hero_id ──→ superhero.id +hero_power.power_id ──→ superpower.id +``` + +## Frequently Asked Queries + +For canonical query patterns (heroes by publisher, power counts, attribute +comparisons), call: +```python +read_skill_resource( + skill_name="superhero-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (average attributes, power distributions, hero counts), +call: +```python +read_skill_resource( + skill_name="superhero-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/superhero-semantic-model/references/gotchas.md b/src/skills/superhero-semantic-model/references/gotchas.md new file mode 100644 index 0000000..8674022 --- /dev/null +++ b/src/skills/superhero-semantic-model/references/gotchas.md @@ -0,0 +1,115 @@ +# Gotchas — superhero + +## 1. `height_cm` and `weight_kg` use `0` as the sentinel for missing data + +**Problem**: Heroes without known height or weight have `0` stored — not NULL. +Averaging without filtering includes zeroes and significantly skews results. + +**Correct usage**: +```sql +-- CORRECT: average height for heroes with valid data +SELECT + p.publisher_name, + ROUND(AVG(s.height_cm), 1) AS avg_height_cm +FROM superhero s +JOIN publisher p ON s.publisher_id = p.id +WHERE s.height_cm != 0 -- exclude missing values +GROUP BY p.publisher_name; + +-- WRONG — includes zeroes, lowering the average +SELECT p.publisher_name, AVG(s.height_cm) +FROM superhero s JOIN publisher p ON s.publisher_id = p.id +GROUP BY p.publisher_name; +``` + +--- + +## 2. Three colour FK columns all reference the same `colour` table — must alias + +**Problem**: `superhero` has `eye_colour_id`, `hair_colour_id`, and +`skin_colour_id`, all FKs to `colour.id`. Joining the `colour` table once +and not aliasing causes PostgreSQL to error or return ambiguous results. + +**Correct usage**: +```sql +-- CORRECT: alias colour table three times +SELECT + s.superhero_name, + ec.colour AS eye_colour, + hc.colour AS hair_colour, + sc.colour AS skin_colour +FROM superhero s +LEFT JOIN colour ec ON s.eye_colour_id = ec.id +LEFT JOIN colour hc ON s.hair_colour_id = hc.id +LEFT JOIN colour sc ON s.skin_colour_id = sc.id; + +-- WRONG — ambiguous, or only one colour joined +JOIN colour c ON s.eye_colour_id = c.id -- hair and skin are missing +``` + +--- + +## 3. `publisher_id` is NULL for some heroes + +**Problem**: Independent or unknown-publisher heroes have `NULL` in +`publisher_id`. Using `INNER JOIN publisher` silently drops these heroes. + +**Correct usage**: +```sql +-- CORRECT: keep all heroes, show NULL publisher as 'Unknown' +SELECT + s.superhero_name, + COALESCE(p.publisher_name, 'Unknown') AS publisher +FROM superhero s +LEFT JOIN publisher p ON s.publisher_id = p.id; + +-- WRONG — drops heroes with no publisher record +INNER JOIN publisher p ON s.publisher_id = p.id +``` + +--- + +## 4. `alignment.alignment` includes `'-'` for unknown alignment + +**Problem**: The alignment table has four values: `'Good'`, `'Bad'`, +`'Neutral'`, and `'-'` (unknown). Filtering `WHERE alignment IN ('Good','Bad','Neutral')` +silently excludes heroes with unknown alignment. + +**Correct usage**: +```sql +-- Heroes with a defined alignment +SELECT COUNT(*) FROM superhero s +JOIN alignment a ON s.alignment_id = a.id +WHERE a.alignment != '-'; + +-- Heroes with unknown alignment +SELECT COUNT(*) FROM superhero s +JOIN alignment a ON s.alignment_id = a.id +WHERE a.alignment = '-'; +``` + +--- + +## 5. `hero_power` is a many-to-many junction — aggregate at the hero level + +**Problem**: Each superpower a hero has is one row in `hero_power`. Joining +`hero_power` without aggregating multiplies rows — one result row per power. + +**Correct usage**: +```sql +-- CORRECT: count of powers per hero +SELECT + s.superhero_name, + COUNT(hp.power_id) AS power_count +FROM superhero s +LEFT JOIN hero_power hp ON s.id = hp.hero_id +GROUP BY s.id, s.superhero_name +ORDER BY power_count DESC; + +-- CORRECT: list powers for a specific hero +SELECT sp.power_name +FROM superhero s +JOIN hero_power hp ON s.id = hp.hero_id +JOIN superpower sp ON hp.power_id = sp.id +WHERE s.superhero_name = 'Superman'; +``` diff --git a/src/skills/superhero-semantic-model/references/metrics.md b/src/skills/superhero-semantic-model/references/metrics.md new file mode 100644 index 0000000..cbe0561 --- /dev/null +++ b/src/skills/superhero-semantic-model/references/metrics.md @@ -0,0 +1,83 @@ +# Metric Definitions — superhero + +## Hero Count by Publisher + +```sql +SELECT + COALESCE(p.publisher_name, 'Unknown') AS publisher, + COUNT(*) AS hero_count +FROM superhero s +LEFT JOIN publisher p ON s.publisher_id = p.id +GROUP BY p.publisher_name +ORDER BY hero_count DESC; +``` + +--- + +## Average Physical Attributes by Publisher (Excluding Missing Values) + +```sql +-- height_cm = 0 and weight_kg = 0 are sentinels for missing data +SELECT + p.publisher_name, + ROUND(AVG(s.height_cm) FILTER (WHERE s.height_cm != 0), 1) AS avg_height_cm, + ROUND(AVG(s.weight_kg) FILTER (WHERE s.weight_kg != 0), 1) AS avg_weight_kg, + COUNT(*) AS hero_count +FROM superhero s +JOIN publisher p ON s.publisher_id = p.id +GROUP BY p.publisher_name +ORDER BY hero_count DESC; +``` + +--- + +## Power Count Distribution + +```sql +-- How many heroes have each number of superpowers? +SELECT + power_count, + COUNT(*) AS hero_count +FROM ( + SELECT s.id, COUNT(hp.power_id) AS power_count + FROM superhero s + LEFT JOIN hero_power hp ON s.id = hp.hero_id + GROUP BY s.id +) counts +GROUP BY power_count +ORDER BY power_count; +``` + +--- + +## Average Attribute Score by Alignment + +```sql +-- attribute scores 0-100 for Intelligence, Strength, Speed, Durability, Power, Combat +SELECT + a.alignment, + attr.attribute_name, + ROUND(AVG(ha.attribute_value), 1) AS avg_score +FROM superhero s +JOIN alignment a ON s.alignment_id = a.id +JOIN hero_attribute ha ON s.id = ha.hero_id +JOIN attribute attr ON ha.attribute_id = attr.id +WHERE a.alignment IN ('Good', 'Bad', 'Neutral') +GROUP BY a.alignment, attr.attribute_name +ORDER BY attr.attribute_name, a.alignment; +``` + +--- + +## Most Common Superpowers Across All Heroes + +```sql +SELECT + sp.power_name, + COUNT(*) AS hero_count +FROM hero_power hp +JOIN superpower sp ON hp.power_id = sp.id +GROUP BY sp.power_id, sp.power_name +ORDER BY hero_count DESC +LIMIT 20; +``` diff --git a/src/skills/superhero-semantic-model/references/query_patterns.md b/src/skills/superhero-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..17cea48 --- /dev/null +++ b/src/skills/superhero-semantic-model/references/query_patterns.md @@ -0,0 +1,84 @@ +# Query Patterns — superhero + +## "Find all villains (bad alignment) published by DC Comics" + +```sql +SELECT s.superhero_name, s.full_name +FROM superhero s +JOIN alignment a ON s.alignment_id = a.id +JOIN publisher p ON s.publisher_id = p.id +WHERE a.alignment = 'Bad' + AND p.publisher_name = 'DC Comics' +ORDER BY s.superhero_name; +``` + +--- + +## "Which heroes have the most superpowers?" + +```sql +SELECT + s.superhero_name, + COALESCE(p.publisher_name, 'Unknown') AS publisher, + COUNT(hp.power_id) AS power_count +FROM superhero s +LEFT JOIN publisher p ON s.publisher_id = p.id +LEFT JOIN hero_power hp ON s.id = hp.hero_id +GROUP BY s.id, s.superhero_name, p.publisher_name +ORDER BY power_count DESC +LIMIT 20; +``` + +--- + +## "Who has the highest Intelligence score?" + +```sql +-- hero_attribute.attribute_value (0–100); attribute_name = 'Intelligence' +SELECT + s.superhero_name, + COALESCE(p.publisher_name, 'Unknown') AS publisher, + ha.attribute_value AS intelligence +FROM superhero s +JOIN hero_attribute ha ON s.id = ha.hero_id +JOIN attribute attr ON ha.attribute_id = attr.id +LEFT JOIN publisher p ON s.publisher_id = p.id +WHERE attr.attribute_name = 'Intelligence' +ORDER BY ha.attribute_value DESC +LIMIT 10; +``` + +--- + +## "Show all colour attributes for a specific hero" + +```sql +-- Three colour FK columns all join the same colour table — must alias +SELECT + s.superhero_name, + ec.colour AS eye_colour, + hc.colour AS hair_colour, + sc.colour AS skin_colour +FROM superhero s +LEFT JOIN colour ec ON s.eye_colour_id = ec.id +LEFT JOIN colour hc ON s.hair_colour_id = hc.id +LEFT JOIN colour sc ON s.skin_colour_id = sc.id +WHERE s.superhero_name = 'Batman'; +``` + +--- + +## "Compare average strength between Marvel and DC heroes" + +```sql +SELECT + p.publisher_name, + ROUND(AVG(ha.attribute_value), 1) AS avg_strength +FROM superhero s +JOIN publisher p ON s.publisher_id = p.id +JOIN hero_attribute ha ON s.id = ha.hero_id +JOIN attribute attr ON ha.attribute_id = attr.id +WHERE attr.attribute_name = 'Strength' + AND p.publisher_name IN ('DC Comics', 'Marvel Comics') +GROUP BY p.publisher_name; +``` diff --git a/src/skills/toxicology-semantic-model/SKILL.md b/src/skills/toxicology-semantic-model/SKILL.md new file mode 100644 index 0000000..d1c8fcb --- /dev/null +++ b/src/skills/toxicology-semantic-model/SKILL.md @@ -0,0 +1,101 @@ +--- +name: toxicology-semantic-model +description: Semantic model for the toxicology database (mutagenesis molecular data — molecules, atoms, bonds, connectivity). Load this skill when the user is querying the toxicology database. +metadata: + author: manual + version: "1.1" + last_updated: "2026-02-25T00:00:00Z" + learned_patterns: 0 + verified_patterns: 4 +--- + +# Toxicology — Semantic Model + +## Available Resources + +| Resource | What it contains | How to load | +|---|---|---| +| Extended gotchas | Label encoding, atom ID format, graph traversal pitfalls | `read_skill_resource("toxicology-semantic-model", "references/gotchas.md")` | +| Metric definitions | Atom counts, toxicity prevalence, bond type distributions | `read_skill_resource("toxicology-semantic-model", "references/metrics.md")` | +| Query patterns | Canonical SQL for toxic molecules, element queries, graph traversal | `read_skill_resource("toxicology-semantic-model", "references/query_patterns.md")` | + +**When to load resources:** +- If querying for toxic/non-toxic molecules → load `references/gotchas.md` (label encoding is critical) +- If traversing the molecular graph (paths, connectivity) → load `references/gotchas.md` + `references/query_patterns.md` +- If counting atoms, bonds, or computing distributions → load `references/metrics.md` +- For simple lookups by molecule ID → the information below is sufficient + +## Key Concepts + +| Term (user says) | Actual meaning | Confidence | +|---|---|---| +| "toxic" / "mutagenic" / "positive" | `molecule.label = '+'` — string plus sign, NOT integer 1 | verified | +| "non-toxic" / "non-mutagenic" / "negative" | `molecule.label = '-'` — string minus sign, NOT integer 0 | verified | +| "single bond" | `bond.bond_type = '-'` | verified | +| "double bond" | `bond.bond_type = '='` | verified | +| "triple bond" | `bond.bond_type = '#'` | verified | +| "aromatic bond" | `bond.bond_type = ':'` | verified | +| "carbon atom" | `atom.element = 'c'` (lowercase) | verified | +| "connected atoms" | `connected` table — links atom pairs via `atom_id`, `atom_id2`, `bond_id` | verified | + +## Gotchas + +1. **`molecule.label` is a string, not an integer** — toxic molecules have + `label = '+'`, non-toxic have `label = '-'`. Writing `WHERE label = 1` + will silently return zero rows. + +2. **`atom.element` values are lowercase** — carbon is `'c'`, not `'C'` or + `'Carbon'`. Chlorine is `'cl'`, nitrogen is `'n'`, oxygen is `'o'`. + +3. **Atom and bond IDs encode structure** — `'TR000_1'` means molecule TR000, + atom position 1. Bond ID `'TR000_1_2'` is the bond between atoms 1 and 2 + in TR000. Do not treat these as opaque strings when debugging. + +4. **Graph traversal requires recursive CTEs** — single-hop joins on `connected` + only find immediate neighbours. For path-length queries, use `WITH RECURSIVE`. + +5. **`bond` and `connected` serve different purposes** — `bond` stores bond type + per molecule; `connected` maps which atom pairs share a bond. Both are needed + for element-and-bond-type queries. + +For extended gotchas and SQL examples, call: +```python +read_skill_resource( + skill_name="toxicology-semantic-model", + resource_name="references/gotchas.md" +) +``` + +## Core Join Paths + +```text +molecule.molecule_id ──→ atom.molecule_id (molecule ↔ its atoms) +molecule.molecule_id ──→ bond.molecule_id (molecule ↔ its bonds) +atom.atom_id ──→ connected.atom_id (atom ↔ connections, one end) +atom.atom_id ──→ connected.atom_id2 (atom ↔ connections, other end) +bond.bond_id ──→ connected.bond_id (bond ↔ atom pair sharing it) +``` + +There is no direct FK between `atom` and `bond`; go through `connected` to +link a specific atom to the bonds it participates in. + +## Frequently Asked Queries + +For canonical query patterns (toxic molecules by element, bond type filters, +graph traversal), call: +```python +read_skill_resource( + skill_name="toxicology-semantic-model", + resource_name="references/query_patterns.md" +) +``` + +## Metric Definitions + +For full metric formulas (atom counts, toxicity rates, bond distributions), call: +```python +read_skill_resource( + skill_name="toxicology-semantic-model", + resource_name="references/metrics.md" +) +``` diff --git a/src/skills/toxicology-semantic-model/references/gotchas.md b/src/skills/toxicology-semantic-model/references/gotchas.md new file mode 100644 index 0000000..da7764e --- /dev/null +++ b/src/skills/toxicology-semantic-model/references/gotchas.md @@ -0,0 +1,104 @@ +# Gotchas — toxicology + +## 1. `molecule.label` is a string character, not an integer + +**Problem**: The `molecule` table uses `label = '+'` for mutagenic (toxic) +molecules and `label = '-'` for non-mutagenic. A very common mistake is +filtering `WHERE label = 1` (integer) — this will return zero rows without +an error because PostgreSQL will attempt an implicit cast. + +**Correct usage**: +```sql +-- CORRECT: toxic molecules +SELECT molecule_id FROM molecule WHERE label = '+'; + +-- CORRECT: non-toxic molecules +SELECT molecule_id FROM molecule WHERE label = '-'; + +-- WRONG — returns zero rows (integer vs. text mismatch or cast failure) +SELECT molecule_id FROM molecule WHERE label = 1; +SELECT molecule_id FROM molecule WHERE label = 0; +``` + +--- + +## 2. `atom.element` symbols are lowercase + +**Problem**: Element symbols are stored in lowercase: `'c'` (carbon), `'n'` +(nitrogen), `'o'` (oxygen), `'cl'` (chlorine), `'s'` (sulphur), `'p'` +(phosphorus), `'h'` (hydrogen). Querying with uppercase or full names returns +zero rows. + +**Correct usage**: +```sql +-- CORRECT +SELECT * FROM atom WHERE element = 'c'; -- carbon +SELECT * FROM atom WHERE element = 'cl'; -- chlorine +SELECT * FROM atom WHERE element = 'n'; -- nitrogen + +-- WRONG — case mismatch +SELECT * FROM atom WHERE element = 'C'; +SELECT * FROM atom WHERE element = 'Carbon'; +``` + +--- + +## 3. Bond type characters conflict with SQL operators + +**Problem**: `bond.bond_type` values are single characters: `'-'` (single), +`'='` (double), `'#'` (triple), `':'` (aromatic). These must be quoted as +string literals — they look like SQL operators but are data values. + +**Correct usage**: +```sql +-- CORRECT +SELECT * FROM bond WHERE bond_type = '-'; -- single bond +SELECT * FROM bond WHERE bond_type = '='; -- double bond +SELECT * FROM bond WHERE bond_type = '#'; -- triple bond +SELECT * FROM bond WHERE bond_type = ':'; -- aromatic bond + +-- Note: single bond '-' is the same character as SQL minus — always quote it +``` + +--- + +## 4. Atom IDs and bond IDs encode molecule and position + +**Problem**: IDs are composite strings, not opaque keys. `atom.atom_id = +'TR000_1'` means molecule `TR000`, atom position 1. `bond.bond_id = +'TR000_1_2'` means the bond between atoms 1 and 2 in molecule TR000. Filtering +on partial strings (e.g. `LIKE 'TR000%'`) is a valid and idiomatic way to +retrieve all atoms/bonds for a molecule when you don't want to join on +`molecule_id`. + +```sql +-- Both of these return the same atoms: +SELECT * FROM atom WHERE molecule_id = 'TR000'; +SELECT * FROM atom WHERE atom_id LIKE 'TR000_%'; +``` + +--- + +## 5. Graph traversal needs `connected`, not just `bond` + +**Problem**: `bond` stores bond type per molecule but does NOT directly list +which two atoms are connected. The `connected` table provides the atom-pair +mapping (`atom_id`, `atom_id2`, `bond_id`). For any query that needs to walk +the molecular graph, you must join through `connected`. + +**Correct multi-hop traversal skeleton**: +```sql +WITH RECURSIVE graph(molecule_id, current_atom, depth) AS ( + -- Base: start from a specific atom + SELECT c.atom_id, c.atom_id2, 1 + FROM connected c + WHERE c.atom_id = 'TR000_1' + UNION ALL + -- Recursive: extend one hop at a time + SELECT g.molecule_id, c.atom_id2, g.depth + 1 + FROM graph g + JOIN connected c ON c.atom_id = g.current_atom + WHERE g.depth < 5 -- guard against infinite cycles +) +SELECT DISTINCT current_atom FROM graph; +``` diff --git a/src/skills/toxicology-semantic-model/references/metrics.md b/src/skills/toxicology-semantic-model/references/metrics.md new file mode 100644 index 0000000..c3ed0df --- /dev/null +++ b/src/skills/toxicology-semantic-model/references/metrics.md @@ -0,0 +1,83 @@ +# Metric Definitions — toxicology + +## Toxicity Prevalence Rate + +```sql +-- Fraction of molecules that are mutagenic (label = '+') +SELECT + ROUND( + COUNT(*) FILTER (WHERE label = '+')::numeric / COUNT(*), + 4 + ) AS toxicity_rate +FROM molecule; +``` + +--- + +## Atom Count per Molecule + +```sql +-- Number of atoms in each molecule, sorted descending +SELECT + a.molecule_id, + m.label, + COUNT(a.atom_id) AS atom_count +FROM atom a +JOIN molecule m ON a.molecule_id = m.molecule_id +GROUP BY a.molecule_id, m.label +ORDER BY atom_count DESC; +``` + +--- + +## Element Distribution Across All Molecules + +```sql +-- How often each element appears (across all molecules) +SELECT + element, + COUNT(*) AS occurrences, + COUNT(DISTINCT molecule_id) AS molecules_containing +FROM atom +GROUP BY element +ORDER BY occurrences DESC; +``` + +--- + +## Bond Type Distribution + +```sql +-- Count of each bond type across the dataset +SELECT + bond_type, + CASE bond_type + WHEN '-' THEN 'single' + WHEN '=' THEN 'double' + WHEN '#' THEN 'triple' + WHEN ':' THEN 'aromatic' + ELSE 'other' + END AS bond_description, + COUNT(*) AS bond_count +FROM bond +GROUP BY bond_type +ORDER BY bond_count DESC; +``` + +--- + +## Average Atom Count by Toxicity Label + +```sql +-- Do toxic molecules tend to be larger? +SELECT + m.label, + ROUND(AVG(atom_counts.cnt), 2) AS avg_atom_count +FROM molecule m +JOIN ( + SELECT molecule_id, COUNT(*) AS cnt + FROM atom + GROUP BY molecule_id +) atom_counts ON m.molecule_id = atom_counts.molecule_id +GROUP BY m.label; +``` diff --git a/src/skills/toxicology-semantic-model/references/query_patterns.md b/src/skills/toxicology-semantic-model/references/query_patterns.md new file mode 100644 index 0000000..81edf0a --- /dev/null +++ b/src/skills/toxicology-semantic-model/references/query_patterns.md @@ -0,0 +1,73 @@ +# Query Patterns — toxicology + +## "Find all toxic molecules that contain a chlorine atom" + +```sql +SELECT DISTINCT m.molecule_id +FROM molecule m +JOIN atom a ON m.molecule_id = a.molecule_id +WHERE m.label = '+' + AND a.element = 'cl'; +``` + +--- + +## "How many toxic vs. non-toxic molecules contain a double bond?" + +```sql +SELECT + m.label, + COUNT(DISTINCT m.molecule_id) AS molecule_count +FROM molecule m +JOIN bond b ON m.molecule_id = b.molecule_id +WHERE b.bond_type = '=' +GROUP BY m.label; +``` + +--- + +## "List all atoms and their element type for a specific molecule" + +```sql +-- Replace 'TR001' with the target molecule_id +SELECT + atom_id, + element +FROM atom +WHERE molecule_id = 'TR001' +ORDER BY atom_id; +``` + +--- + +## "Find molecules that have both nitrogen and oxygen atoms" + +```sql +SELECT molecule_id +FROM atom +WHERE element IN ('n', 'o') +GROUP BY molecule_id +HAVING COUNT(DISTINCT element) = 2; +``` + +--- + +## "List all bonds (with type) between atoms in a specific molecule" + +```sql +-- Replace 'TR001' with the target molecule_id +SELECT + c.atom_id, + c.atom_id2, + b.bond_type, + CASE b.bond_type + WHEN '-' THEN 'single' + WHEN '=' THEN 'double' + WHEN '#' THEN 'triple' + WHEN ':' THEN 'aromatic' + END AS bond_description +FROM connected c +JOIN bond b ON c.bond_id = b.bond_id +WHERE b.molecule_id = 'TR001' +ORDER BY c.atom_id; +``` diff --git a/tests/inspect_chroma_db.py b/tests/inspect_chroma_db.py index 9582b0e..1098fa9 100644 --- a/tests/inspect_chroma_db.py +++ b/tests/inspect_chroma_db.py @@ -8,42 +8,60 @@ os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src") ) -# Path to ChromaDB (persistent) +# Path to ChromaDB (persistent) — accepts a db name argument or defaults to all DBs PRJ_ROOT = Path(__file__).resolve().parents[1] -CHROMA_PATH = PRJ_ROOT / "src" / "chroma_db" -COLLECTION_NAME = "query_intents" +CHROMA_BASE = PRJ_ROOT / "src" / "db_confirmed_fixes" / "chroma" +COLLECTION_NAME = "db_confirmed_fixes" -def inspect_chroma(): - print(f"Connecting to ChromaDB at {CHROMA_PATH.resolve()}") +def inspect_chroma(db_name: str | None = None): + if db_name: + db_dirs = [CHROMA_BASE / db_name] + else: + if not CHROMA_BASE.exists(): + print(f"ChromaDB base path not found: {CHROMA_BASE}") + return + db_dirs = sorted(p for p in CHROMA_BASE.iterdir() if p.is_dir()) - client = chromadb.PersistentClient(path=str(CHROMA_PATH)) - collection = client.get_collection(COLLECTION_NAME) + for db_path in db_dirs: + print(f"\n{'=' * 60}") + print(f"Database: {db_path.name}") + print(f"Path: {db_path.resolve()}") + print(f"{'=' * 60}") - count = collection.count() - print(f"Collection '{COLLECTION_NAME}' has {count} records.") + try: + client = chromadb.PersistentClient(path=str(db_path)) + collection = client.get_collection(COLLECTION_NAME) + except Exception as e: + print(f" Error: {e}") + continue - if count == 0: - return + count = collection.count() + print(f" Collection '{COLLECTION_NAME}' has {count} records.") - print("\nFetching first 5 records...\n") + if count == 0: + continue - results = collection.get( - limit=min(5, count), - include=["documents", "metadatas"], - ) + print(f"\n First {min(5, count)} records:\n") - ids = results.get("ids", []) + results = collection.get( + limit=min(5, count), + include=["documents", "metadatas"], + ) - for i in range(len(ids)): - print(f"--- Record #{i + 1} ---") - print(f"ID: {ids[i]}") - print(f"Intent (document): {results['documents'][i]}") - print("Metadata:") - for k, v in results["metadatas"][i].items(): - print(f" {k}: {v}") - print() + ids = results.get("ids", []) + + for i in range(len(ids)): + print(f" --- Record #{i + 1} ---") + print(f" ID: {ids[i]}") + print(f" Intent (document): {results['documents'][i]}") + print(" Metadata:") + for k, v in results["metadatas"][i].items(): + print(f" {k}: {v}") + print() if __name__ == "__main__": - inspect_chroma() \ No newline at end of file + # Usage: python tests/inspect_chroma_db.py [db_name] + db = sys.argv[1] if len(sys.argv) > 1 else None + inspect_chroma(db) \ No newline at end of file diff --git a/tests/output/validate_with_db_benchmark_results.json b/tests/output/validate_with_db_benchmark_results.json new file mode 100644 index 0000000..cb77f00 --- /dev/null +++ b/tests/output/validate_with_db_benchmark_results.json @@ -0,0 +1,18662 @@ +{ + "summary": { + "total_queries": 514, + "valid": 264, + "invalid": 250, + "exceptions": 0, + "skipped": 0, + "tag_distribution": { + "schema_hallucination_table": 100, + "schema_hallucination_col": 66, + "schema_unknown_error": 20, + "logical_grouping_error": 28, + "syntax_error": 87, + "syntax_invalid_token": 27, + "schema_type_mismatch": 12, + "schema_ambiguous_col": 18, + "syntax_keyword_misuse": 9, + "logical_windowing_error": 1, + "syntax_unbalanced_tokens": 12, + "schema_undefined_function": 23, + "value_format_mismatch": 4, + "syntax_unterminated_string": 1 + }, + "per_database": { + "financial": { + "valid": 18, + "invalid": 33 + }, + "codebase_community": { + "valid": 3, + "invalid": 15 + }, + "student_club": { + "valid": 24, + "invalid": 18 + }, + "debit_card_specializing": { + "valid": 9, + "invalid": 27 + }, + "card_games": { + "valid": 31, + "invalid": 20 + }, + "european_football_2": { + "valid": 34, + "invalid": 37 + }, + "superhero": { + "valid": 20, + "invalid": 19 + }, + "toxicology": { + "valid": 33, + "invalid": 30 + }, + "formula_1": { + "valid": 29, + "invalid": 14 + }, + "california_schools": { + "valid": 16, + "invalid": 11 + }, + "thrombosis_prediction": { + "valid": 22, + "invalid": 10 + }, + "erolp": { + "valid": 19, + "invalid": 9 + }, + "esophageal": { + "valid": 4, + "invalid": 4 + }, + "global_atlas": { + "valid": 2, + "invalid": 1 + }, + "spotify": { + "valid": 0, + "invalid": 2 + } + }, + "per_category": { + "Query": { + "valid": 152, + "invalid": 133 + }, + "Management": { + "valid": 29, + "invalid": 51 + }, + "Personalization": { + "valid": 83, + "invalid": 66 + } + } + }, + "results": [ + { + "instance_id": "PostgreSQL_0", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account_id, MAX(payments) AS max_payment, MIN(payments) AS min_payment FROM loan GROUP BY account_id HAVING COUNT(account_id) > 1 AND (MAX(payments) - MIN(payments)) > 2;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0594, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_1", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CreationDate::time FROM comments;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "comments" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_3", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "CREATE UNIQUE INDEX unique_name ON event(event_name, event_date) where event_name is not null;CREATE UNIQUE INDEX unique_location ON event(location, event_date) where location is not null;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE", + "clauses_present": [ + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_4", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE transactions_1k\n SET Amount = 100\n FROM ( SELECT TransactionID FROM transactions_1k WHERE Amount = 50 ORDER BY Date LIMIT 100 FOR UPDATE ) sub\n WHERE transactions_1k.TransactionID = sub.TransactionID RETURNING *;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN UPDATE transactions_1k | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1042, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-LOCKING-UPDATE-RETURNING-SUBQUERY", + "clauses_present": [ + "FROM", + "LIMIT", + "LOCKING", + "ORDER", + "RETURNING", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_5", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT users.Id, COUNT(posts.Id) as answered FROM users LEFT JOIN posts ON users.Id = posts.OwnerUserId GROUP BY users.Id ORDER BY answered DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column posts.owneruserid does not exist | LINE 1: ...answered FROM users LEFT JOIN posts ON users.Id = posts.Owne... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'OwnerUserId' does not exist in table 'posts' (referenced as 'posts.OwnerUserId')", + "taxonomy_category": "semantic", + "context": "posts.OwnerUserId", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "posts", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_6", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS users;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot drop table users because other objects depend on it | constraint posthistory_userid_fkey on table posthistory depends on table users | constraint badges_userid_fkey on table badges depends on table users | constraint comments_userid_fkey on table comments depends on table users | constraint posts_lasteditoruserid_fkey on table posts_backup depends on table users | constraint posts_owneruserid_fkey on table posts_backup depends on table users | constraint votes_userid_fkey on table votes depends on table users | Use DROP ... CASCADE to drop the dependent objects too.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "2BP01" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "users" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_7", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ARRAY_AGG(DISTINCT u.id) AS ids, ARRAY_AGG(DISTINCT u.username) AS usernames, ARRAY_AGG(DISTINCT u.ref1) AS refs1, ARRAY_AGG(DISTINCT u.ref2) AS refs2, COUNT(DISTINCT a.id) AS asset_count FROM assets a JOIN users u ON a.owner = u.ref1 OR a.owner = u.ref2 GROUP BY a.owner ORDER BY MIN(a.id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0948, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "assets", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_8", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH CTE AS ( SELECT link_to_event, COUNT(link_to_member) AS count FROM attendance GROUP BY link_to_event ) SELECT CTE.link_to_event, CTE.count AS newCount, budget.count AS oldCount FROM budget JOIN CTE ON budget.link_to_event = CTE.link_to_event WHERE budget.count != CTE.count;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in WHERE | LINE 1: ...ON budget.link_to_event = CTE.link_to_event WHERE budget.cou... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "attendance", + "budget", + "cte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_9", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "INSERT INTO attendance VALUES ('recEVTik3MlqbvLFi', 'rec280Sk7o31iG0Tx', 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_10", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE account\n SET date__timestamp = date__bigint::timestamp;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"date__bigint\" does not exist | LINE 2: SET date__timestamp = date__bigint::timestamp; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__timestamp" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__bigint' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__bigint" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_11", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM cards GROUP BY artist;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"cards.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT * FROM cards GROUP BY artist; | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_12", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "IF SELECT * FROM transactions_1k WHERE CustomerID = 3 AND Date = '2012-08-24' RETURNS NO ROWS\nTHEN SELECT * FROM transactions_1k WHERE CustomerID = 7626 AND Date = '2012-08-24'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"IF\" | LINE 1: IF SELECT * FROM transactions_1k WHERE CustomerID = 3 AND Da... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_13", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_name\n FROM information_schema.columns As c\n WHERE table_name = 'account'\n AND c.column_name NOT IN('account_id', 'date')\n), ',') || ' FROM accountAs o' As sqlstmt", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "columns" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_14", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 0 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_id = l.account_id\n WHERE account.district_id = '18'\n AND l.date >= (NOW() - INTERVAL '48 hours')\n ORDER BY l.date DESC NULLS LAST\n LIMIT 6\n)\nUNION\n(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 1 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_i", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column l.date does not exist | LINE 6: l.date AS loan_date, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_15", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Array_agg(rw) FROM (SELECT link_to_event, (SELECT To_(Array_agg(Row_to_(t))) FROM (SELECT link_to_member FROM public.attendance WHERE link_to_event = b.link_to_event) t) rw FROM attendance b GROUP BY link_to_event);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: EXPLAIN SELECT Array_agg(rw) FROM (SELECT link_to_event, (SE... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_16", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT to_char(generate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FROM\" | LINE 1: ...)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 123.\n rate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') \u001b[4mFROM\u001b[0m loan;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0125, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_17", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account_id, amount FROM (SELECT account_id, amount, ROW_NUMBER() OVER(PARTITION BY account_id ORDER BY amount DESC) AS rn FROM loan) AS a WHERE rn = 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"amount\" does not exist | LINE 1: ...ELECT account_id, amount FROM (SELECT account_id, amount, RO... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "amount", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_18", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE client_information ( client_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) GENERATED ALWAYS AS (concat(first_name, ' ', last_name)) STORED, PRIMARY KEY (client_id) );", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "generation expression is not immutable", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P17" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "client_information" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_19", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO cards(uuid, name) VALUES ('5f8287b1-5bb6-5f4c-ad17-316a40d5bb0c', 'Ancestor''s Chosen') ON CONFLICT DO NOTHING RETURNING id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT-RETURNING", + "clauses_present": [ + "INSERT", + "RETURNING", + "VALUES" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_20", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (account_id, district_id, frequency, date) VALUES (1, 18, 'POPLATEK MESICNE', CURRENT_DATE) ON CONFLICT (account_id) DO UPDATE SET date = CURRENT_DATE", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"date\" is of type bigint but expression is of type date | LINE 1: ...equency, date) VALUES (1, 18, 'POPLATEK MESICNE', CURRENT_DA... | ^ | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_21", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) -1 AS count, MAX(releaseDate), MIN(releaseDate) FROM (SELECT *, date(releaseDate) - row_number() OVER (PARTITION BY releaseDate ORDER BY date(releaseDate)) * INTERVAL '1 day' AS filter FROM sets_releaseInfo ) t1 GROUP BY filter HAVING COUNT(*) -1 > 0 ORDER BY count DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "sets_releaseinfo" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_22", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE path_cte AS (SELECT id, nextCardId, id::TEXT AS Path FROM collection WHERE nextCardId IS NULL UNION ALL SELECT collection.id, collection.nextCardId, collection.id || ' --> ' || cte.Path FROM collection JOIN path_cte cte ON collection.nextCardId = cte.id) SELECT Path FROM path_cte ORDER BY id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "collection", + "path_cte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_23", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_24", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\\n a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) as referencing_table,\\n UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as referencing_col,\\n pg_get_constraintdef(c.oid) contraint_sql FROM pg_constraint c join pg_attribute a on c.confrelid=a.attrelid and a.attnum = ANY(confkey)\\n WHERE c.", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\\\" | LINE 1: ..._class r where r.oid = c.confrelid) as base_table,\\n a... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 83.\n SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\u001b[4m\\\u001b[0mn a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) a", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pg_class" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_25", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT first_value(bank ignore nulls) over (partition by account_id order by date rows unbounded following) as next_bank FROM trans;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"ignore\" | LINE 1: EXPLAIN SELECT first_value(bank ignore nulls) over (partitio... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_26", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team_api_id, team_short_name FROM Team as data FULL OUTER JOIN (SELECT buildUpPlaySpeed, team_api_id FROM Team_Attributes ta WHERE team_api_id = data.team_api_id) AS subquery_alias ON data.team_api_id = subquery_alias.team_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "invalid reference to FROM-clause entry for table \"data\" | LINE 1: ...pi_id FROM Team_Attributes ta WHERE team_api_id = data.team_... | ^ | There is an entry for table \"data\", but it cannot be referenced from this part of the query.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team_attributes, team", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_27", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH one AS ( SELECT date_trunc('year', date) as timeOne, COUNT(*) as trans_count FROM trans ORDER BY timeOne ), two AS ( SELECT date_trunc('year', date) as timeTwo, COUNT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count) as count FROM one, two ORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"trans.date\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN WITH one AS ( SELECT date_trunc('year', date) as tim... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "syntax_keyword_misuse", + "message": "The number of provided arguments (2) is greater than the maximum number of supported arguments (1). Line 1, Col: 270.\n NT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count\u001b[4m)\u001b[0m as count FROM one, two ORDER BY 1;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "logical_grouping_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "loan", + "one", + "trans", + "two" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_28", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH gen_transactions AS ( SELECT CustomerID, Amount FROM transactions_1k CROSS JOIN LATERAL generate_series(1, CAST(Amount AS INTEGER)) ) SELECT CustomerID, Amount, ROW_NUMBER() OVER (ORDER BY random()) AS rn FROM gen_transactions LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..._transactions AS ( SELECT CustomerID, Amount FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0927, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "gen_transactions", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_29", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO card_information(price) SELECT jsonb_agg(price) FROM (SELECT price FROM card_information) AS subquery;SELECT * FROM card_information;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "card_information" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_30", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.k_symbol, t.operation, t.amount, t.balance, a.frequency FROM trans t INNER JOIN account a ON t.account_id = a.account_id WHERE t.account_id = 1 AND t.type = 'PRIJEM' GROUP BY t.k_symbol", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"t.operation\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT t.k_symbol, t.operation, t.amount, t.balance,... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "trans" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_31", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT user_id, COUNT(*) AS num_consecutive_months FROM (SELECT user_id, purchase_date, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) AS month_date, ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD'))) - ROW_NUMBER() OVER(PARTITION BY user_id, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) - INTERVAL '1 month' * ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purcha", + "valid": false, + "errors": [ + { + "tag": "logical_windowing_error", + "message": "window functions are not allowed in window definitions | LINE 1: ...e || '-01', 'YYYY-MM-DD')) - INTERVAL '1 month' * ROW_NUMBER... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P20" + } + ], + "tags": [ + "logical_windowing_error" + ], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "purchase" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_32", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH tab_with_cardid AS (\n select split(cardid, '-', 3)ivm_arr,\n\n type,\n last_refresh_date\n FROM db.scema.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"as\" | LINE 8: ...UMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp OR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'table' does not exist in schema", + "taxonomy_category": "semantic", + "context": "table", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 71.\n ma.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) \u001b[4mas\u001b[0m temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\n\n\nRequired keyword: 'this' missing for . Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\nalias does not support CTE. Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "table" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_33", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT player_api_id, MAX(date), FIRST(overall_rating) FROM Player_Attributes GROUP BY player_api_id ORDER BY date desc;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function first(bigint) does not exist | LINE 1: EXPLAIN SELECT player_api_id, MAX(date), FIRST(overall_ratin... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_34", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT Age::numeric FROM users;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "users" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_35", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "begin insert into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.WebsiteUrl, '.', '-'), charindex('@', replace(new.WebsiteUrl, '.', '-')) - 1);return new;end;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"insert\" | LINE 1: begin insert into profiles (Id, CreationDate, WebsiteUrl) se... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 12.\n begin \u001b[4minsert\u001b[0m into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.Webs", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_36", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM cards WHERE availability = 'paper' AND bordercolor = 'black' AND rarity = 'uncommon' AND types = 'Creature';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.049, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_37", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "insert into event (event_id, event_name, event_date, type, notes, location, status) values ('recAlAwtBZ0Fqbr5K', 'Annual Gala', '2023-12-15T19:00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"insert\" | LINE 1: ...rand Ballroom', 'Open') on conflict (event_id) do insert int... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Unknown option DO. Line 1, Col: 251.\n :00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do \u001b[4minsert\u001b[0m into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');\n\nInvalid expression / Unexpected token. Line 1, Col: 244.\n :00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) \u001b[4mdo\u001b[0m insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_38", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION log_player_name_changes() RETURNS trigger AS $BODY$ BEGIN IF NEW.player_name <> OLD.player_name THEN INSERT INTO player_audits(player_id, old_player_name, changed_on) VALUES(OLD.id, OLD.player_name, now()); END IF; RETURN NEW; END; $BODY$ CREATE TRIGGER tr_change_playername AFTER UPDATE OF player_name ON player FOR EACH ROW EXECUTE PROCEDURE log_player_name_changes();", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"CREATE\" | LINE 1: ...yer_name, now()); END IF; RETURN NEW; END; $BODY$ CREATE TRI... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_39", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT userid, tag\nFROM preference_tag\nWHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text[] @> character varying[] | LINE 3: WHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]); | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "preference_tag" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_40", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM account_info WHERE ((condition->0->>'conditions')::json->>'rootcompanyid')::json->>'$in' = '[5]';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "account_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_41", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE hero_power ADD CONSTRAINT unique_active_hero_power UNIQUE (hero_id, power_id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "hero_power" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_42", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT(user_id), email FROM orders o WHERE (o.segment = 'luxury' AND o.destination = 'New York') OR (o.segment = 'luxury' AND o.destination = 'London')", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.049, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_43", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT version FROM cars ORDER BY SUBSTRING(version, '^[0-9]+') DESC, SUBSTRING(version, '[0-9]+\\.[0-9]+\\.([0-9]+)-') DESC, CAST(SUBSTRING(version, '[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+)') AS INTEGER) DESC, SUBSTRING(version, '[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\.([0-9]+)') DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "cars" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_44", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.driverId, ((SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId) - (SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId)) AS total_points FROM results r GROUP BY r.driverId", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"races\" | LINE 1: ...SUM(r.points), 0) FROM results r WHERE r.raceId = races.race... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.15, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_45", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "select count(S.id), A.alignment, count(R.race), R.race from superhero S, alignment A, race R where S.alignment_id=A.id and S.race_id=R.id group by A.alignment, R.race;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "alignment", + "race", + "superhero" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_46", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "select driverId, points, lead(driverId) over (order by points asc) as \"lead(driverId) with order\", array_agg(driverId) over (order by points asc) as \"array_agg(driverId) with order\", lead(driverId) over () as \"lead(driverId) without order\", array_agg(driverId) over () as \"array_agg(driverId) without order\" from results where raceId = 19 order by driverId asc", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_47", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n raceId,\n MAX(time::time) AS end_time,\n MIN(time::time) AS start_time,\n (MAX(time::time) - MIN(time::time)) AS total_duration\nFROM pitStops\nWHERE raceId = 842\nGROUP BY raceId;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_48", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "select label, JSON_AGG(JSON_BUILD_OBJECT(atom.molecule_id, atom.atom_id)) AS groupedMolecules FROM molecule JOIN atom ON molecule.molecule_id = atom.molecule_id GROUP BY label", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_49", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT molecule_id, COALESCE(SUM(CASE WHEN element = 'na' THEN 1 ELSE 0 END), 0) na_atoms, COALESCE(SUM(CASE WHEN element = 'c' OR element = 'cl' THEN 1 ELSE 0 END), 0) c_atoms FROM atom GROUP BY molecule_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0333, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_50", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT home_team_api_id, AVG(home_team_goal) as avg_home_goals, AVG(away_team_goal) as avg_away_goals, SUM(home_team_goal) as total_home_goals, SUM(away_team_goal) as total_away_goals, MAX(home_team_goal) as max_home_goals, MIN(home_team_goal) as min_home_goals, COUNT(home_team_api_id) as count FROM Match GROUP BY home_team_api_id, date_part('hour', date);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function date_part(unknown, text) does not exist | LINE 1: ...d) as count FROM Match GROUP BY home_team_api_id, date_part(... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_51", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transaction_date AS date, club_name, sum(amount) over (partition by club_name, sign(amount) order by transaction_date) from club_transactions", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "club_transactions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_52", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT array_to_json(array_agg(row_to_json(alias))) FROM (select * from modules ) alias", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "modules" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_53", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO customers (customerid, segment, currency) VALUES (3, 'SME', 'EUR'), (1, 'KAM', 'CZK'), (3, 'SME', 'EUR') ON CONFLICT (customerid, segment, currency) DO UPDATE SET Currency = customers.Currency RETURNING CustomerID;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT-RETURNING", + "clauses_present": [ + "INSERT", + "RETURNING", + "VALUES" + ], + "tables": [ + "customers" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_54", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT client.client_id, client.gender, disp.disp_id, address ->> 'PostCode' AS PostCode FROM client JOIN disp ON client.client_id = disp.client_id CROSS JOIN jsonb_array_elements(disp.addresses) AS address WHERE disp.client_id IN (100, 414);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "SELECT", + "WHERE" + ], + "tables": [ + "client", + "disp" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_55", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO loan (\n loan_id,\n account_id,\n date,\n amount,\n duration,\n payments,\n status\n)\nVALUES (\n DEFAULT,\n 2,\n '1996-04-29',\n 30276,\n 12,\n 2523.0,\n 'B'\n)\nON CONFLICT (loan_id, account_id, date)\nDO UPDATE\n SET amount = loan.amount + 1000;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"date\" of relation \"loan\" does not exist | LINE 4: date, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "amount" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in table 'loan' (referenced as 'loan.amount')", + "taxonomy_category": "semantic", + "context": "loan.amount" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_56", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "DELETE FROM cards WHERE (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm1 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) AND (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm2 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) LIMIT 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"LIMIT\" | LINE 1: ...AND rarity IS NOT NULL AND manaCost IS NOT NULL ) LIMIT 1000... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'setCode' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "setCode", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'rarity' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "rarity", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'manaCost' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "manaCost", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2385, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT-DELETE-SUBQUERY", + "clauses_present": [ + "DELETE", + "FROM", + "LIMIT", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "norm1", + "norm2" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_57", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION f_gap_fill_update(tbl text, id text, row_num text) RETURNS void LANGUAGE plpgsql AS $func$ DECLARE tmp text[]; col text; BEGIN select array ( select column_name from information_schema.columns c where table_name = tbl ) into tmp; foreach col in array tmp loop execute 'update '||tbl||' set '||col||' = gapfill('||col||') OVER w AS '||col||' where '||tbl||'.row_num = '||col||'.row_num window w as (PARTITION BY '||id||' ORDER BY '||row_num||') returning *;'; end loop; end ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "f_gap_fill_update" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_58", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET disp_id = 1 WHERE disp_id = 41;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card\" does not exist | LINE 1: EXPLAIN UPDATE card SET disp_id = 1 WHERE disp_id = 41; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_59", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION public.generate_series_monthly(a date, b date) RETURNS SETOF date LANGUAGE SQL IMMUTABLE PARALLEL SAFE ROWS 10 AS $function$ select generate_series(date_trunc('month', a), date_trunc('month', b), '1 month') $function$;EXPLAIN SELECT generate_series_monthly('2024-01-01', '2024-05-01');EXPLAIN SELECT * FROM generate_series_monthly('2024-01-01', '2024-05-01');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_60", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n m.id,\n m.date,\n CASE WHEN m.home_team_goal = m.away_team_goal THEN 1 ELSE 0 END AS invoiced,\n SUM(m.home_team_goal + m.away_team_goal)\n OVER (PARTITION BY (CASE WHEN m.home_team_goal = m.away_team_goal THEN 1 ELSE 0 END)\n ORDER BY m.id, m.date) AS amount\nFROM match AS m\nORDER BY m.id, m.date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_61", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH DataSource AS (\n SELECT\n *,\n MIN(CASE WHEN amount < 10 THEN gasstationid END)\n OVER (PARTITION BY customerid) AS first_issue_gasstation,\n ROW_NUMBER() OVER (PARTITION BY customerid ORDER BY gasstationid DESC) AS gasstation_id\n FROM transactions_1k\n WHERE gasstationid = (\n SELECT MAX(gasstationid)\n FROM transactions_1k\n WHERE customerid = transactions_1k.customerid\n )\n)\nSELECT\n customerid,\n transactionid,\n gasstationid,\n amount\nFROM DataSource\nWHERE\n (first_is", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 7: FROM transactions_1k | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.201, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "datasource", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_62", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT c1.user_id, COUNT(*) FROM user_actions c1 LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'LOGIN') c2 ON c1.user_id = c2.user_id AND c2.action_time > c1.action_time LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'BUY') c3 ON c1.user_id = c3.user_id AND c3.action_time > c1.action_time AND c3.action_time < c2.action_time WHERE c1.action = 'SEARCH' AND c2.user_id IS NOT NULL AND c3.user_id IS NULL GROUP BY 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2552, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "user_actions" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_63", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.id, c.name FROM cards c WHERE c.id IN (SELECT unnest(card_order) FROM decks WHERE id = 1);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1146, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_64", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ord.order_date, ord.order_id, ord.card_id, prd.price FROM order_cards ord LEFT JOIN (SELECT * FROM card_prices ORDER BY start_date ASC) AS prd ON ord.card_id = prd.card_id AND ord.order_date >= prd.start_date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1365, + "pattern_signature": "SELECT-FROM-JOIN-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "card_prices", + "order_cards" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_65", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "select player_id, stats_keys, stats_values from player_stats", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "player_stats" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_66", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE teams_config SET configurations = jsonb_set(configurations, '{settings}', (configurations->'id') - (SELECT DISTINCT position - 1 FROM teams_config, jsonb_array_elements(configurations) WITH ORDINALITY arr(elem, position) WHERE elem->>'id' = '101')::int);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "teams_config" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_67", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT begin_date, end_date, age(CASE WHEN end_date = date_trunc('month', end_date) + interval '1 month - 1 day' THEN end_date + interval '1 day' ELSE date_trunc('month', end_date) END::date, CASE WHEN begin_date = date_trunc('month', begin_date) THEN begin_date ELSE date_trunc('month', begin_date) + interval '1 month' END::date) AS calculated_months FROM race_dates;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "race_dates" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_68", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO new_attendance (link_to_event, link_to_member, date)\n VALUES ('reciRZdAqNIKuMC96', 'recL94zpn6Xh6kQii', NOW())\n ON CONFLICT\n WHERE link_to_member='recL94zpn6Xh6kQii' DO NOTHING;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHERE\" | LINE 4: WHERE link_to_member='recL94zpn6Xh6kQii' DO NOTHING; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES", + "WHERE" + ], + "tables": [ + "new_attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_69", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "pg_advisory_xact_lock(lkhndl);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"pg_advisory_xact_lock\" | LINE 1: pg_advisory_xact_lock(lkhndl); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_70", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n link_to_member,\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN CEIL(SUM(hours) / 10) * 10\n ELSE FLOOR(SUM(hours) / 10) * 10\n END AS rounded_hours,\n RANK() OVER (ORDER BY\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_71", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE INDEX ix_account ON account USING btree (district_id, frequency, date);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "relation \"ix_account\" already exists", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P07" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_72", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "create or replace view findcount(season, team_count) as\n select\n season,\n findteam(season) as team_count\n from (\n select distinct season\n from match\n where season >= '2008/2009'\n ) seasons;", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "cannot change data type of view column \"team_count\" from integer to double precision", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P16" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "findcount", + "match" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_73", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "select posttypeid\n case when tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from posts", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"when\" | LINE 2: case when tags like ('%bayesian%','%distributions%') | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 17.\n select posttypeid\n case \u001b[4mwhen\u001b[0m tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_74", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id last_update DESC;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"last_update\" | LINE 1: ...OM bond GROUP BY molecule_id ORDER BY molecule_id last_updat... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 98.\n SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id \u001b[4mlast_update\u001b[0m DESC;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_75", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT entity_id, coalesce(change->'height', lag(change->'height', 1, null) over (partition by entity_id order by updated_at)) as height, coalesce(change->'weight', lag(change->'weight', 1, null) over (partition by entity_id order by updated_at)) as weight, updated_at FROM ( SELECT entity_id, json_object_agg(column_id, value) as change, updated_at FROM player_stats_changes GROUP BY entity_id, updated_at) as changes;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1083, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "player_stats_changes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_76", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "with qr1(item, subgroup) AS (SELECT id, subgroup1 FROM superhero_group WHERE subgroup1 IS NOT NULL), qr2(item, subgroup) AS (SELECT id, subgroup2 FROM superhero_group WHERE subgroup2 IS NOT NULL) select item, subgroup1, subgroup2, dense_rank() over (order by item) as group from (select qr1.item, qr1.subgroup as subgroup1, qr2.subgroup as subgroup2 from qr1 full outer join qr2 on qr1.item = qr2.item) as combined", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "qr1", + "qr2", + "superhero_group" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_77", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH r AS (SELECT id, date_of_visit, SUM(sessions) AS sessions, SUM(pageviews) AS pageviews, SUM(bounces) AS bounce, COALESCE(utm_campaign, '') AS utm_campaign, COALESCE(utm_source, '') AS utm_source, COALESCE(utm_medium, '') AS utm_medium, COALESCE(utm_content, '') AS utm_content, COALESCE(utm_term, '') AS utm_term FROM report GROUP BY id, date_of_visit, utm_campaign, utm_source, utm_medium, utm_content, utm_term UNION SELECT id, date_of_visit, SUM(sessions), SUM(pageviews), SUM(bounces), COALE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2771, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "r", + "report", + "utm" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 36 + } + }, + { + "instance_id": "PostgreSQL_78", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n id,\n text,\n REGEXP_MATCHES(\n text,\n '\\{.*?\\}',\n 'g'\n ) AS bracketed_tokens\nFROM cards;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_79", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT race_id, top(count(*), 5) as cnt FROM superhero group by gender_id", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function top(bigint, integer) does not exist | LINE 1: EXPLAIN SELECT race_id, top(count(*), 5) as cnt FROM superhe... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_80", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT rulings.id, rulings.date, rulings.text, rulings.uuid FROM rulings WHERE rulings.uuid IN ('6d268c95-c176-5766-9a46-c14f739aba1c', '56f4935b-f6c5-59b9-88bf-9bcce20247ce', '8dfc67e9-8323-5d1f-9e25-9f9394abd5a0', '5ac794d2-4c66-5332-afb1-54b24bc11823', '60f49caf-3583-5f85-b4b3-08dca73a8628') GROUP BY rulings.id ORDER BY rulings.id LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "rulings" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_81", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select rank() over (order by total_points desc) as place, id, name, total_points, race_points, raceId from racers", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "racers" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_82", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT month_year, COUNT(DISTINCT customer_id) FROM orders GROUP BY month_year HAVING COUNT(order_id) > 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_83", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT player_name, event_date as join_date, (SELECT event_date FROM player_movements pm1 WHERE pm1.player_name = pm.player_name AND pm1.event = 'Leave' AND pm1.event_date > pm.event_date) as leave_date FROM player_movements pm WHERE event = 'Join'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.125, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "player_movements" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_84", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select account_id, date,\n sum(amount) OVER (PARTITION BY account_id, date) as total_amount,\n sum(balance) OVER (PARTITION BY account_id, date) as total_balance,\n count(trans_id) OVER (PARTITION BY account_id, date) as total_transactions\n from trans", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0292, + "pattern_signature": "SELECT-FROM-WINDOW", + "clauses_present": [ + "FROM", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_85", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE (Date, Time, Amount) < ('2012-08-24', '10:00:00', 20);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT * FROM transactions_1k WHERE (Date, Time, Amo... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_86", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT client.gender, loan.amount, loan.duration, account.date FROM loan JOIN account ON loan.account_id = account.account_id JOIN client ON disp.client_id = client.client_id JOIN disp ON account.account_id = disp.account_id WHERE loan.date BETWEEN '1996-01-01' AND '1996-12-31';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...er, loan.amount, loan.duration, account.date FROM loan JOIN ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "client", + "disp", + "loan" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_87", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "with cte as (select pv1.session_id, pv1.post_id, pv2.view_perc, pv1.ts as start_time, min(pv2.ts) as end_time from view_logs pv1 join view_logs pv2 on pv1.session_id = pv2.session_id and pv1.post_id = pv2.post_id and pv1.event_name <> pv2.event_name and pv1.ts < pv2.ts group by pv1.session_id, pv1.post_id, pv2.view_perc, pv1.ts) select session_id, post_id, start_time, end_time, case when (end_time - start_time > 3 and view_perc > 0.8 )then 'yes' else 'no' end as has_meaningful_view from cte;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WITH" + ], + "tables": [ + "cte", + "view_logs" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_88", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "delete from superhero where id = 999 returning 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-DELETE-RETURNING", + "clauses_present": [ + "DELETE", + "RETURNING", + "WHERE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_89", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION GapFillInternal(s anyelement, v anyelement) RETURNS anyelement AS $$ DECLARE temp alias for $0; BEGIN F v IS NULL AND s NOTNULL THEN temp := s; ELSIF s IS NULL AND v NOTNULL THEN temp := v; ELSIF s NOTNULL AND v NOTNULL THEN temp := v; ELSE temp := NULL; END;END; $$ LANGUAGE PLPGSQL;CREATE AGGREGATE GapFill(anyelement) (SFUNC=GapFillInternal, STYPE=anyelement);SELECT id, publisher_id, height_cm, weight_kg, GapFill(height_cm) OVER (PARTITION BY publisher_id ORDER BY id)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"F\" | LINE 1: ...anyelement AS $$ DECLARE temp alias for $0; BEGIN F v IS NUL... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_90", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 1 THEN amount ELSE NULL END) AS yesterday_revenue, ROUND((SUM(CASE WHEN timestamp::date > '2022-01-27'::date - 1 THEN amount ELSE NULL END) - SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 8 THEN amount ELSE NULL END)) / SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 8 THEN amount ELSE NULL END), 2) AS pct_change_week_ago, SUM(CASE WHEN date_trunc('month', timestamp) = date_trunc('month', '2022-01-27'::date - 1) THEN amount ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "transactions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 8 + } + }, + { + "instance_id": "PostgreSQL_91", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, convertedManaCost, avg(convertedManaCost) OVER(ORDER BY id ROWS BETWEEN 8 PRECEDING AND CURRENT ROW) AS nine_card_avg FROM cards WHERE name LIKE 'A%' ORDER BY id DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_92", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT hero_id, attribute_id, jsonb_array_length(a.ss) AS ss_cnt, jsonb_array_length(CASE WHEN a.ss -> 'approved' = 'true' THEN a.ss END) AS approved_cnt FROM hero_attribute a WHERE a.hero_id IN (1, 2);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_93", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT set_translations.language\n CASE WHEN set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'common'\n ELSE 'not common'\n END\n FROM set_translations", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHEN\" | LINE 2: CASE WHEN set_translations.language IN (SELECT... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 23.\n SELECT set_translations.language\n CASE \u001b[4mWHEN\u001b[0m set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'com", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_94", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$ DECLARE i integer; BEGIN\n FOREACH i IN ARRAY[11, 20]::integer[] LOOP\n RAISE NOTICE 'Value: %', i;\n UPDATE Player_Attributes SET overall_rating = i\n WHERE player_api_id = ANY (ARRAY[505942, 155782]::integer[])\n AND date = ANY (ARRAY['2016-02-18 00:00:00', '2015-10-16 00:00:00']::text[]);\n END LOOP;\n END $$;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 2: FOREACH i IN ARRAY[11, 20]::integer[] LOOP | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_95", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT resultId FROM results WHERE to_tsvector(results.fastestLapTime) @@ to_tsquery('1:35.405');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error in tsquery: \"1:35.405\"", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_96", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT raceId, position, COUNT(*) as cnt FROM results GROUP BY raceId, position", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_97", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM Match WHERE (match_api_id, date, id) > (492473, '2008-08-17 00:00:00', 1) ORDER BY date, id ASC LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_98", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT School FROM schools GROUP BY School HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_99", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT MAX(date), raceid, name FROM races GROUP BY name, raceid HAVING MAX(date) = date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_100", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.team_name, o.outcome FROM (VALUES('Team A'),('Team B')) AS t(team_name) JOIN (VALUES('win'),('lose'),('draw')) AS o(outcome);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \";\" | LINE 1: ..._name) JOIN (VALUES('win'),('lose'),('draw')) AS o(outcome); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.026, + "pattern_signature": "SELECT-FROM-JOIN-VALUES", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "VALUES" + ], + "tables": [], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_101", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (\"County Code\") * FROM frpm ORDER BY \"County Code\", \"Enrollment (K-12)\" DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_102", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(quantity) FROM race_materials WHERE price_per_unit * quantity <= 100;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "race_materials" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_103", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO historical_rating (player_fifa_api_id, player_api_id, grouped_rating) SELECT player_fifa_api_id, player_api_id AS grouped_rating FROM player_attributes GROUP BY player_fifa_api_id, player_api_id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "INSERT has more target columns than expressions | LINE 1: ...orical_rating (player_fifa_api_id, player_api_id, grouped_ra... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: historical_rating, player_attributes", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: historical_rating, player_attributes", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "SELECT-FROM-GROUP-INSERT", + "clauses_present": [ + "FROM", + "GROUP", + "INSERT", + "SELECT" + ], + "tables": [ + "historical_rating", + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_104", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT id, acceptedanswerid, posttypeid, score FROM posts WHERE score >= 20 OR acceptedanswerid IS NOT NULL AND score >= 20 GROUP BY id, acceptedanswerid;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"acceptedanswerid\" does not exist | LINE 1: EXPLAIN SELECT DISTINCT id, acceptedanswerid, posttypeid, sc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'acceptedanswerid' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "acceptedanswerid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "score", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0385, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_105", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH card_activity AS ( SELECT to_date(fe.start_date_key::text, 'YYYYMMDD') AS start_date, to_date(fe.end_date_key::text, 'YYYYMMDD') AS end_date, dp.set_name, dp.set_code FROM fact_collection fe INNER JOIN dim_set dp ON fe.set_key = dp.set_key ) SELECT date_trunc('month', month_series) AS month, COUNT(*) AS existing_cards, sa.set_name FROM ( SELECT generate_series( (SELECT MIN(to_date(start_date_key::text, 'YYYYMMDD')) FROM fact_collection), '2100-12-31', INTERVAL '1 month') AS month_series ) A", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.275, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WITH" + ], + "tables": [ + "card_activity", + "dim_set", + "fact_collection" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_106", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH mission_spans AS ( SELECT hero_id, mission_start, mission_end FROM superhero_missions ORDER BY hero_id, mission_start, mission_end ) SELECT hero_id, MIN(mission_start) OVER (PARTITION BY hero_id), MAX(mission_end) OVER (PARTITION BY hero_id) FROM mission_spans ORDER BY 1, 2, 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0792, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "mission_spans", + "superhero_missions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_107", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT percentile_cont(0.5) within group (ORDER by releasedate) FROM sets", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function percentile_cont(numeric, date) does not exist | LINE 1: EXPLAIN SELECT percentile_cont(0.5) within group (ORDER by r... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "sets" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_108", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE race_incidents ( incident_type VARCHAR(30) NOT NULL CHECK(incident_type = 'Engine failure' OR incident_type = 'Collision'), incident_description VARCHAR(30) NOT NULL);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "race_incidents" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_109", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "select * from trans t1 where (account_id, trans_id) in (select account_id, max(trans_id) from trans t1 group by account_id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_110", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.league_id) SELECT * FROM recuree", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"recuree\" | LINE 1: ...ue UNION SELECT id, name FROM League) , RECURSIVE recuree AS... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'recuree' does not exist in schema", + "taxonomy_category": "semantic", + "context": "recuree", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting (. Line 1, Col: 108.\n ITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE \u001b[4mrecuree\u001b[0m AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON \n\nRequired keyword: 'expressions' missing for . Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\nExpecting ). Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "league", + "recuree", + "tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_111", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "SELECT *\nFROM superhero.\"%_id\";", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"superhero.%_id\" does not exist | LINE 2: FROM superhero.\"%_id\"; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table '%_id' does not exist in schema", + "taxonomy_category": "semantic", + "context": "%_id", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "%_id" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_112", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO races (raceid, year, round, circuitid, name, date, time, url)\nVALUES (\n 999,\n 2023,\n 1,\n 2,\n 'Test Grand Prix',\n '2023-04-01',\n '12:00:00',\n 'http://example.com'\n)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_113", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n sub.raceId,\n sub.t[1] AS \"Lap_Time_Race1\",\n sub.t[2] AS \"Lap_Time_Race2\",\n sub.t[3] AS \"Lap_Time_Race3\"\nFROM (\n SELECT\n driverId,\n raceId,\n ARRAY_AGG(milliseconds ORDER BY lap) AS t\n FROM lapTimes\n WHERE driverId = 1\n GROUP BY driverId\n) AS sub\nORDER BY sub.raceId;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"laptimes.raceid\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 9: raceId, | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "laptimes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_114", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM Examination AS e LEFT JOIN LATERAL (SELECT * FROM Laboratory WHERE ID = e.ID ORDER BY Date DESC LIMIT 2) AS lab ON true", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-LATERAL-WHERE-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "examination", + "laboratory" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_115", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "select a.f as \"id\", count(a.f) as \"num\" from ( select atom_id as f from connected union all select atom_id2 as f from connected ) a group by a.f order by count(a.f) desc limit 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "connected" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_117", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceId, name, year, COUNT(*) AS same_year_races FROM races GROUP BY raceid, name, year", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_118", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "with hero_attribute_data (hero_id, attribute_id, max_score, year_1, year_2, year_3, year_4, year_5) as (values (1, 1, 80, 80, 80, 80, null, 80), (2, 2, 90, 90, 85, 90, 88, 90), (3, 3, 75, 75, 70, null, 75, 75), (4, 4, 60, null, 60, 60, 60, null)), score_check as (select *, case when (max_score <> year_1 or max_score <> year_2 or max_score <> year_3 or max_score <> year_4 or max_score <> year_5) then false else true end as is_a_match from hero_attribute_data) select * from score_check where is_a_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1156, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "VALUES", + "WHERE", + "WITH" + ], + "tables": [ + "hero_attribute_data", + "score_check" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_119", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "select item_id, item_price as retail_price, sum(coalesce(uses_item_price, 0) * quantity) + sum(coalesce(resource_price*quantity, 0)) as partial_craft_price FROM store GROUP BY item_id, retail_price;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "store" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_120", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET full_name = 'Superman' JOIN team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team_member_superhero.team_member_id = team_member.id WHERE team_id = 91;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JOIN\" | LINE 1: ...PLAIN UPDATE superhero SET full_name = 'Superman' JOIN team_... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n UPDATE superhero SET full_name = 'Superman' \u001b[4mJOIN\u001b[0m team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_121", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, CASE WHEN e.id = p.id AND e.diagnosis = 'SLE' THEN TRUE ELSE FALSE END AS SLE, CASE WHEN e.id = p.id AND e.diagnosis = 'PSS' THEN TRUE ELSE FALSE END AS PSS, CASE WHEN e.id = p.id AND e.diagnosis = 'RA susp.' THEN TRUE ELSE FALSE END AS RA_susp FROM patient p LEFT JOIN examination e ON p.id = e.id WHERE e.diagnosis IN ('SLE', 'PSS', 'RA susp.') ORDER BY p.id DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0854, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "examination", + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_122", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT hbi.id, hbi.hero_name, hbi.birthdate, hbialt.date_of_birth FROM hero_birth_info hbi LEFT JOIN hero_birth_info_alt hbialt ON hbi.id = hbialt.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "hero_birth_info", + "hero_birth_info_alt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_123", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION reindex_superhero_ids(IN BIGINT) RETURNS VOID LANGUAGE SQL AS $$ CREATE TEMPORARY SEQUENCE id_seq_temp MINVALUE 1 START WITH 1 INCREMENT BY 1; ALTER SEQUENCE id_seq_temp RESTART; UPDATE superhero SET hair_colour_id=hair_colour_id+2000 WHERE publisher_id=$1; UPDATE superhero SET hair_colour_id=nextval('id_seq_temp') WHERE publisher_id=$1; $$;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"id_seq_temp\" does not exist | LINE 1: ...d=$1; UPDATE superhero SET hair_colour_id=nextval('id_seq_te... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "reindex_superhero_ids" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_124", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card_versions SET seqnr=seqnr+1 WHERE defn_id = 100 AND attr_id = 100 AND seqnr >= 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0385, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "card_versions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_126", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE atom_ancestors AS ( SELECT atom_id, parent_id, enabled FROM connection WHERE atom_id = 4 UNION ALL SELECT c.atom_id, c.parent_id, c.enabled FROM connection c INNER JOIN atom_ancestors aa ON c.atom_id = aa.parent_id) SELECT * FROM atom_ancestors", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom_ancestors", + "connection" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_127", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select customerid,\n (select jsonb_agg(t->>'dis') from jsonb_array_elements(preference::jsonb) as x(t) where t->>'dis' is not null) as sdata\nfrom card_preference where customerid='123.abc'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1042, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "card_preference" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_128", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT hero_id, 'attribute_value' AS Difference FROM hero_attribute\nGROUP BY hero_id HAVING COUNT(DISTINCT attribute_value) > 1\nOR (COUNT(attribute_value) != COUNT(*) AND COUNT(DISTINCT attribute_value) > 0)\nUNION ALL SELECT hero_id, 'attribute_id' AS Difference FROM hero_attribute GROUP BY hero_id\nHAVING COUNT(DISTINCT attribute_id) > 1 OR (COUNT(attribute_id) != COUNT(*)\nAND COUNT(DISTINCT attribute_id) > 0)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-UNION", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "UNION" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 8 + } + }, + { + "instance_id": "PostgreSQL_129", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO member(member_id, first_name, last_name) VALUES ('new_member_id', 'John', 'Doe','rec06DF6vZ1CyPKpc') ON CONFLICT (member_id) DO UPDATE SET first_name=excluded.first_name, last_name=excluded.last_name;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "INSERT has more expressions than target columns | LINE 1: ...last_name) VALUES ('new_member_id', 'John', 'Doe','rec06DF6v... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "member" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_130", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS streak_count, 'April Meeting' AS event_name, 'MST' AS timezone, MIN(event_date) AS start_date, MAX(event_date) AS end_date FROM attendance WHERE event_name = 'April Meeting' GROUP BY DATE_TRUNC('day', event_date AT TIME ZONE 'UTC' AT TIME ZONE 'MST') ORDER BY end_date DESC LIMIT 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"event_date\" does not exist | LINE 1: ...il Meeting' AS event_name, 'MST' AS timezone, MIN(event_date... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_131", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DATE_TRUNC('day', to_timestamp(transaction_timestamp / 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC('day', transaction_timestamp)", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function date_trunc(unknown, bigint) does not exist | LINE 1: .../ 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_132", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "select a.id, a.date, a.got, a.gpt from laboratory as a inner join ( select id, max(date) as date from laboratory group by id ) as b on a.id = b.id and a.date = b.date order by id, date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "laboratory" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_133", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH constructor_roles AS ( SELECT 18 race_id, 1 constructor_id, false customer_billing, true commander, true agent UNION ALL SELECT 18, 2, true, false, false ) SELECT n.race_id, string_agg(distinct CASE WHEN n.customer_billing = TRUE THEN 'AR (Customer Billing)' WHEN n.commander = TRUE THEN 'AP (Commander)' WHEN n.agent = TRUE THEN 'AP (Agent)' ELSE NULL END, ', ') AS finance FROM constructor_roles n WHERE n.race_id = 18 AND (n.customer_billing = TRUE or n.commander = TRUE or n.agent = TRUE) GR", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "constructor_roles" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_134", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.firstName, jsonb_agg(DISTINCT jsonb_build_object('yearId', y.id, 'classes', (SELECT jsonb_agg(jsonb_build_object('classId', c.id)) FROM classes AS c WHERE y.id = cy.yearId AND c.id = cy.classId AND s.id = cys.studentId))) AS years FROM users3 AS s LEFT JOIN classYearStudents AS cys ON cys.studentId = s.id LEFT JOIN classYears AS cy ON cy.id = cys.classYearId LEFT JOIN years AS y ON y.id = cy.yearId GROUP BY s.id order by s.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2375, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "classes", + "classyears", + "classyearstudents", + "users3", + "years" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_135", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE EmpMgrCTE AS (SELECT id, bossid, salary, 0 as EmployeeLevel FROM staff WHERE bossid IS NULL UNION ALL SELECT emp.id, emp.bossid, emp.salary, mgr.EmployeeLevel + 1 as EmployeeLevel FROM staff emp INNER JOIN EmpMgrCTE mgr ON emp.bossid = mgr.id) SELECT * FROM EmpMgrCTE emp", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "empmgrcte", + "staff" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_136", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "select rarity, id from cards order by convertedmanacost desc nulls last, edhrecrank desc nulls last, multiverseid asc limit 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_137", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS card, account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, frequency TEXT NOT NULL, date DATE NOT NULL, disp_id INT NOT NULL, FOREIGN KEY (disp_id) REFERENCES disp(disp_id) ON UPDATE CASCADE ON DELETE CASCADE);CREATE TABLE disp (disp_id INT PRIMARY KEY NOT NULL, client_id INT NOT NULL, account_id INT NOT NULL, type TEXT NOT NULL, FOREIGN KEY (account_id) REFERENCES account(account_id) ON UPDATE CASCADE ON DELETE CASCADE);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot drop desired object(s) because other objects depend on them | constraint trans_account_id_fkey on table trans depends on table account | constraint order_account_id_fkey on table \"order\" depends on table account | Use DROP ... CASCADE to drop the dependent objects too.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "2BP01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 26.\n DROP TABLE IF EXISTS card\u001b[4m,\u001b[0m account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_unknown_error", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_138", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COALESCE(json_agg(CASE WHEN client.client_id IS NULL THEN NULL ELSE json_build_object('client_id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS clients FROM client;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"clients\" | LINE 1: ...birth_date', client.birth_date) END), '[]') AS AS clients FR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 207.\n _id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS \u001b[4mclients\u001b[0m FROM client;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_139", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "select * from transactions_1k e\nwhere exists\n ( select * from transactions_1k e2\n where e.date=e2.date and e.time=e2.time\n and e.cardid=e2.cardid\n and e.gasstationid=e2.gasstationid\n and e.productid='2' and e2.productid='5') order by e.date asc;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN select * from transactions_1k e | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0771, + "pattern_signature": "SELECT-FROM-WHERE-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_140", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, amount as cum_sum, 1 as bucket from transfer where id = 1 union all select transfer.id, (case when cum_sum + amount > 20 then amount else cum_sum + amount end), (case when cum_sum + amount > 20 then bucket + 1 else bucket end) from cte join transfer on transfer.id = cte.id + 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"cte\" does not exist | LINE 1: ...amount > 20 then bucket + 1 else bucket end) from cte join t... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'cte' does not exist in schema", + "taxonomy_category": "semantic", + "context": "cte", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "cte", + "transfer" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_141", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceid mode() within group(order by laps) as modal_laps FROM results;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: EXPLAIN SELECT raceid mode() within group(order by laps) as ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 19.\n SELECT raceid mode\u001b[4m(\u001b[0m) within group(order by laps) as modal_laps FROM results;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_143", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "update match set stage = stage + 1 where id = 'match1';", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type bigint: \"match1\" | LINE 1: ...LAIN update match set stage = stage + 1 where id = 'match1'; | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + } + ], + "tags": [ + "value_format_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_144", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "with hero_attribute(hero_id, attribute_id, attribute_value) as ( values (1, 1, 80), (2, 1, 75), (3, 1, 95), (4, 1, 85), (5, 1, 90), (6, 1, 70) ) select sum(attribute_value) from hero_attribute group by (hero_id-1) / 2;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0625, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "VALUES", + "WITH" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_145", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, name, d ->> 'description' as skill from player_skills, json_array_elements(skills) as d;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "player_skills" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_146", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE when (t.events::json->0->'id')::varchar::int = 2 then (t.events::json->0)::varchar when (t.events::json->1->'id')::varchar::int = 2 then (t.events::json->1)::varchar when (t.events::json->2->'id')::varchar::int = 2 then (t.events::json->2)::varchar else null::varchar end as \"result\" FROM match_events as t;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "match_events" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_147", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(\"ANA Pattern\") AS c, \"ANA Pattern\", EXTRACT(YEAR FROM \"Examination Date\") AS examination_year FROM examination WHERE EXTRACT(YEAR FROM \"Examination Date\") BETWEEN 1993 AND 1996 GROUP BY EXTRACT(YEAR FROM \"Examination Date\"), \"ANA Pattern\" ORDER BY examination_year, c DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_148", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH player_names AS (SELECT 1 AS source, ROW_NUMBER() OVER (ORDER BY player_name) AS row_number, CONCAT(player_name, '(', LEFT(birthday, 4), ')') AS dest FROM player_table), birth_year_summary AS (SELECT 2 AS source, ROW_NUMBER() OVER (ORDER BY COUNT(*), LEFT(birthday, 4)) AS row_number, CONCAT('There are a total of ', COUNT(*), ' player', CASE WHEN COUNT(*) > 1 THEN 's' ELSE '' END, ' born in ', LEFT(birthday, 4), '.') AS dest FROM player_table GROUP BY LEFT(birthday, 4)) SELECT dest FROM (SEL", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"row_num\" does not exist | LINE 1: ...OM birth_year_summary) AS combined_results ORDER BY ROW_NUM; | ^ | Perhaps you meant to reference the column \"combined_results.row_number\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1292, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "birth_year_summary", + "player_names", + "player_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_149", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT rs.raceId AS race_id, string_agg(constructorId::TEXT, ',' ORDER BY res.resultId) AS constructor_ids, string_agg(p.stop::TEXT, ', ' ORDER BY p.raceId) AS stops FROM races rs LEFT JOIN results res ON res.raceId = rs.raceId LEFT JOIN pitstops p ON rs.raceId = p.raceId GROUP BY rs.raceId", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "pitstops", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_150", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT r.id, r.start_day, r.end_day, de.point_of_delivery_plant_name, de.point_of_delivery_plant_number, de.visit_status FROM route r JOIN route_detail de ON de.route_id = r.id WHERE NOT EXISTS (SELECT 1 FROM route ro JOIN route_detail rd ON rd.route_id = ro.id JOIN route_event ev ON ev.route_detail_id = rd.id WHERE rd.route_id = r.id AND ev.event_type !=3 AND rd.visit_status = '5' AND rd.id = de.id) AND de.visit_status = '5' GROUP BY 1,2,3,4,5,6 ORDER BY r.id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1656, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "route", + "route_detail", + "route_event" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_151", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION update_team_attributes_eff_to() RETURNS TRIGGER AS $$ BEGIN UPDATE team_attributes SET eff_to = subquery.next_date FROM ( SELECT COALESCE( LEAD(TO_TIMESTAMP(date, 'YYYY-MM-DD HH24:MI:SS')::DATE, 1) OVER ( ORDER BY TO_TIMESTAMP(date, 'YYYY-MM-DD HH24:MI:SS')::DATE DESC), TO_DATE('6000-00-00', 'YYYY-MM-DD') ) - 1 AS next_date FROM team_attributes ) AS subquery; RETURN NULL; END; $$ LANGUAGE plpgsql;CREATE OR REPLACE TRIGGER after_insert_team_attributes AFTER INSERT ON te", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "update_team_attributes_eff_to" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_152", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "select position, array_agg(driverid) as driverids from results group by position having COUNT(*)>1 order by position", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_153", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "WITH RECURSIVE cte AS ( SELECT id, parent_id, color FROM superhero2 WHERE parent_id IS NULL UNION ALL SELECT s.id, s.parent_id, CASE WHEN c1.color IS NULL THEN c2.color WHEN c2.color IS NULL THEN c1.color WHEN c1.color = c2.color THEN c1.color ELSE 'gray' END AS color FROM superhero2 s LEFT JOIN cte c1 ON s.id = c1.parent_id LEFT JOIN cte c2 ON s.id = c2.parent_id ) UPDATE superhero2 SET color = cte.color FROM cte WHERE superhero2.id = cte.id", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "recursive reference to query \"cte\" must not appear within an outer join | LINE 1: ...E 'gray' END AS color FROM superhero2 s LEFT JOIN cte c1 ON ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P19" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-UPDATE", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "UPDATE", + "WHERE", + "WITH" + ], + "tables": [ + "cte", + "superhero2" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_154", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT artist, setcode, COUNT(setcode) AS counter FROM cards GROUP BY setcode, artist HAVING COUNT(setcode) > 1 ORDER BY counter DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_155", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\nFROM circuit_json;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FROM\" | LINE 3: FROM circuit_json; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 3, Col: 4.\n SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\n\u001b[4mFROM\u001b[0m circuit_json;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_156", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT y.district_id,\n CASE WHEN y.status IN ('A', 'B') THEN array_agg(loan_id) END AS type_A_B,\n CASE WHEN y.status = 'C' THEN array_agg(loan_id) END AS type_C\nFROM (\n SELECT x.district_id, l.loan_id, l.status\n FROM loan l\n JOIN account x ON l.account_id = x.account_id\n) y\nGROUP BY 1, y.status\nORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 6: FROM loan l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1385, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_157", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ts, superhero_id, activity_code, LEAD(ts) OVER (PARTITION BY superhero_id, activity_code ORDER BY ts) as next_ts FROM superhero_activities", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "superhero_activities" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_158", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT count(*) FROM card_matches INNER JOIN card_players ON card_matches.player1_id = card_players.id OR card_matches.player2_id = card_players.id WHERE card_players.type = 'Pro'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "card_matches", + "card_players" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_159", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH all_dates AS (SELECT league_id, season, ARRAY_AGG(DISTINCT id order by id) as match_ids, date AS match_date FROM match WHERE season IS NOT NULL AND league_id IS NOT NULL AND id is not null AND date IS NOT NULL GROUP BY league_id, season, date) SELECT DISTINCT league_id, season, match_ids, ARRAY_AGG(DISTINCT all_dates.match_date ORDER BY match_date) AS dates FROM all_dates GROUP BY season, league_id, match_ids order by league_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1177, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "all_dates", + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_160", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "select * from crosstab ('select id, uuid, text from ruling order by 1,2') AS final_result(id int, uuid1 text, uuid2 text, uuid3 text);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function crosstab(unknown) does not exist | LINE 1: EXPLAIN select * from crosstab ('select id, uuid, text from ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_161", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.*\nFROM cards_info c\nWHERE NOT EXISTS (\n SELECT 1\n FROM card_choice cc\n WHERE cc.card_id = c.id\n AND c.id = ANY (cc.non_valid_cards)\n);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "op ANY/ALL (array) requires array on right side | LINE 7: AND c.id = ANY (cc.non_valid_cards) | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42809" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "card_choice", + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_162", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE nodes AS (\n SELECT\n uuid,\n card_name AS name,\n ARRAY[]::uuid[] AS parents\n FROM card_type\n WHERE parent_uuid IS NULL\n\n UNION ALL\n\n SELECT\n c.uuid,\n c.card_name AS name,\n nodes.parents || c.uuid\n FROM card_type c\n JOIN nodes ON nodes.uuid = c.parent_uuid\n)\nSELECT * FROM nodes;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "card_type", + "nodes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_163", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT d.the_day AS \"Date\", COUNT(e.event_id) AS \"Number of Events\", AVG(b.remaining) AS \"Avg Remaining Budget\" FROM (SELECT ts::date AS the_day FROM generate_series (timestamp '2020-01-01', timestamp '2020-03-31', interval '1 day'::interval) ts) d LEFT JOIN \"event\" e ON e.event_date::date = d.the_day LEFT JOIN budget b ON b.link_to_event = e.event_id GROUP BY d.the_day ORDER BY d.the_day;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_164", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT LPAD(extract (month from trans.date)::text, 2, '0') as month, sum(trans.amount) as a1997 from trans WHERE trans.date >= '1997-01-01' and trans.date < '1998-01-01' group by month order by 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_165", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM circuits WHERE ST_DWithin(ST_SetSRID(ST_MakePoint(lng, lat), 4326)::geography, ST_ClosestPoint((ST_MakePoint(lng, lat), 4326)::geography, ST_Collect(Array[ST_SetSRID(ST_MakePoint(2.76083, 101.73800), 4326)::geography, ST_SetSRID(ST_MakePoint(26.03250, 50.51060), 4326)::geography])), 1000000, FALSE);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "cannot cast type record to geography | LINE 1: ...hy, ST_ClosestPoint((ST_MakePoint(lng, lat), 4326)::geograph... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42846" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "circuits" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_167", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT driverid, points, (points * 100) as earnings, CASE WHEN (points * 100) > 5000 THEN (points * 100) * 0.2 WHEN (points * 100) > 3000 THEN (points * 100) * 0.15 ELSE null END AS bonus FROM driverstandings", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "driverstandings" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_168", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with dataset as (\n SELECT\n date,\n COUNT(*) as rows_added\n FROM\n team_attributes\n WHERE\n date between '2010-01-01 00:00:00'\n AND '2015-12-31 00:00:00'\n GROUP BY\n date\n )\nSELECT\n COUNT(*) as total_days_in_result_set,\n COUNT(DISTINCT rows_added) as total_days_w_distinct_record_counts,\n COUNT(*) - COUNT(DISTINCT rows_added) as toal_days_w_duplicate_record_counts\nFROM dataset", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1052, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "dataset", + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_169", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "insert into card_counters (card_name, counters) values ('Lightning Bolt', array[2,0,2,1]) on conflict (card_name) do update set counters = array_agg(unnest(card_counters.counters) + unnest(array[2,0,2,1]))", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "set-returning functions are not allowed in UPDATE | LINE 1: ...ct (card_name) do update set counters = array_agg(unnest(car... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "card_counters" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_170", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "select id, round(prev + event * sum(prev) over(order by id range between unbounded preceding and 1 preceding)::numeric(10, 6), 6) as not_quite_my_tempo from (select *, event*sum(trx) over(order by id) as prev from sales_transactions) t order by id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "sales_transactions" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_171", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH cte_funding_count AS (SELECT fundingtype, COUNT(*) AS count FROM schools GROUP BY fundingtype) SELECT fundingtype, count, ROUND(count*100/(SELECT SUM(count) FROM cte_funding_count),0) AS percent FROM cte_funding_count", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1125, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WITH" + ], + "tables": [ + "cte_funding_count", + "schools" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_172", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT lab.date AS firstActivity, pat.id FROM patient pat JOIN laboratory lab ON lab.id = pat.id AND lab.date <= pat.description AND lab.date > pat.\"First Date\" WHERE pat.sex='F' order by pat.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.075, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "laboratory", + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_173", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "select id, array_agg(elem) from cards, unnest(string_to_array(cards.keywords, ',')::text[]) elem where elem <> all(SELECT unnest(sq.RemoveKeywords) from SelectQuery sq) and id in (61, 65) group by id order by id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "selectquery" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_174", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT date_trunc('week', \"TIMESTAMP\") AS week, count(*), AVG(\"CL\") AS cl, AVG(\"C\") AS c FROM \"Experiment\" WHERE \"TIMESTAMP\" >= '2021-01-07T00:00:00.000Z' AND \"TIMESTAMP\" <= '2022-01-06T23:59:59.999Z' GROUP BY week ORDER BY week ASC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "experiment" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_175", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE FUNCTION calculate_loan_status()\n RETURNS SETOF loan_last\n AS $$\n DECLARE temp_table TABLE (loan_id int, status text);\n BEGIN INSERT INTO temp_table\n SELECT loan_id, status FROM loan_first WHERE status = 'A';\n INSERT INTO loan_last SELECT loan_id, status FROM temp_table;\n RETURN;\n END;\n $$ LANGUAGE plpgsql;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "type \"loan_last\" does not exist", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42704" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_176", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET total_powers = (SELECT COUNT(power_id) FROM hero_power);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "SELECT-FROM-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE" + ], + "tables": [ + "hero_power", + "superhero" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_177", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ID, Date, GOT, GPT FROM Laboratory GROUP BY ID HAVING COUNT(ID) > 1 ORDER BY Date DESC", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"laboratory.date\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT ID, Date, GOT, GPT FROM Laboratory GROUP BY I... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_178", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select (coalesce(circui_name_A1, '') || ' ' || coalesce(circui_name_A2,'') || ' ' || coalesce(circui_name_A3, '')) as A, (coalesce(circui_name_B1, '') || ' ' || coalesce(circui_name_B2,'') || ' ' || coalesce(circui_name_B3, '')) as B from race_info;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "race_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_179", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH s as ( SELECT DATE(date_value) as dt, date_value, card_id cid, price FROM card_prices ) SELECT cid, dt, date_value, s.price as second_price FROM s INNER JOIN ( SELECT q.card_id, DATE(q.date_value) as dat FROM card_prices q GROUP BY q.card_id, dat ORDER BY q.card_id ASC ) as end_price ON s.cid = end_price.card_id AND s.date_value = (SELECT date_value FROM s WHERE s.cid = end_price.card_id AND s.dt = end_price.dat LIMIT 1) + interval '15 minutes' ORDER BY cid, dt;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "card_prices", + "s" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_180", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.bond_id as current_bond, b2.bond_id as next_bond, b.bond_type as bond_type FROM bond b INNER JOIN bond b2 ON b.molecule_id = b2.molecule_id WHERE b.bond_id < b2.bond_id ORDER BY b.bond_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_181", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT timestamp, avg(strength) FROM bond_strength WHERE timestamp >= ('2023-10-01 02:30:00'::timestamp - INTERVAL '1 hour') GROUP BY timestamp, strength", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond_strength" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_182", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select jsonb_set(t.data, '{purchaseurls}', (select jsonb_agg(case when v.value::text ~ 'tcgplayer' or v.value::text ~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_array_elements(t.data -> 'purchaseurls') v)) from cards_info", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 1: ...~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_ar... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_183", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH RNG AS(SELECT date_num, product_id, sales_value FROM sales_data WHERE (date_num = 123 OR date_num=567) ORDER BY date_num) SELECT date_num, product_id, sales_value, SUM(sales_value) AS trend FROM RNG group by date_num, product_id, sales_value", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "rng", + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_185", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT count(*) FROM (SELECT DISTINCT molecule_id FROM bond GROUP BY molecule_id HAVING COUNT(CASE WHEN bond_type = '-' THEN 1 END) = 0) AS molecule_without_bond_type;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1094, + "pattern_signature": "SELECT-DISTINCT-FROM-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_186", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "create or replace function setup_vector_store(table_name text) returns void language plpgsql as $$ begin execute 'drop function if exists match_strategies(int, jsonb)'; execute format('create table %I ( id bigint primary key generated always as identity, description text, metadata jsonb )', table_name); execute format('create function match_strategies ( match_count int default null, filter jsonb default \"{}\"::jsonb ) returns table ( id bigint, description text, metadata jsonb, similarity float )", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"return\" | LINE 1: ..., similarity float ) language plpgsql as $$ begin return que... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_187", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH variables_array AS (SELECT datapoint_id, ARRAY_AGG(variablevalue_id) AS varvalues FROM datapoint_variablevalue GROUP BY datapoint_id) SELECT COALESCE(SUM(dp.value),0), sd.name AS sp_name, v.varvalues AS varvalues, td.years AS years FROM variables_array v CROSS JOIN spatial_dimension sd CROSS JOIN time_dimension td LEFT JOIN datapoints dp ON dp.id = v.datapoint_id AND dp.spatial_dimension_id = sd.id AND dp.time_dimension_id = td.id GROUP BY years, sp_name, varvalues ORDER BY years DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2094, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "datapoint_variablevalue", + "datapoints", + "spatial_dimension", + "time_dimension", + "variables_array" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_188", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(*) AS exact_count FROM match;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_190", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT player_api_id, player_name FROM player WHERE player_name LIKE 'Ale%' AND player_fifa_api_id > 220000 AND id = (SELECT MAX(id) FROM player);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.124, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "player" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_191", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT match_id, match_date FROM detail WHERE match_details @@ '$.player_stats[*] ? (@.player_id == :player_id).goals > 0';", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "(sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'player_id' | [SQL: EXPLAIN SELECT match_id, match_date FROM detail WHERE match_details @@ '$.player_stats[*] ? (@.player_id == %(player_id)s).goals > 0';] | (Background on this error at: https://sqlalche.me/e/20/cd3x)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "detail" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_192", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.bond_id, jsonb_build_object('time', sum((b.bond_stat_->'time')::numeric)) FROM bond b GROUP BY bond_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_194", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE UNIQUE INDEX conditional_unique_index ON match_results (match_id, team_id) WHERE (SELECT COUNT(*) FROM match_results t2 WHERE t2.match_id = match_results.match_id AND t2.team_id = match_results.team_id) = 1;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot use subquery in index predicate | LINE 1: ..._index ON match_results (match_id, team_id) WHERE (SELECT CO... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "match_results" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_195", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CAST(time_bucket AS DATE) AS time_bucket, rate / DATE_PART('days', time_bucket + INTERVAL '1 month - 1 day') AS daily_rate FROM (SELECT DATE(generate_series(LOWER(time_span)::TIMESTAMP, COALESCE(UPPER(time_span),NOW())::TIMESTAMP, '1 day')) AS time_bucket, rate FROM budgets) AS daily_rates;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budgets" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_196", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT attribute_name, to_number(attribute_name) FROM attribute;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_number(text) does not exist | LINE 1: EXPLAIN SELECT attribute_name, to_number(attribute_name) FRO... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_197", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT molecule_id, COUNT(*) FILTER (WHERE COUNT(*) > 5) AS total_bonds FROM bond GROUP BY molecule_id;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in FILTER | LINE 1: ...XPLAIN SELECT molecule_id, COUNT(*) FILTER (WHERE COUNT(*) >... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-FILTER", + "clauses_present": [ + "FILTER", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_198", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH range_values AS ( SELECT date_trunc('week', min(date)) as minval, date_trunc('week', max(date)) as maxval FROM laboratory ), week_range AS ( SELECT generate_series('1991-01-01', now(), '1 week') as week FROM range_values ), grouped_labs AS ( SELECT date_trunc('week', date) as week, count(id) as total_tests FROM laboratory WHERE date >= '1991-01-01' GROUP BY 1 ) SELECT week_range.week, COALESCE(sum(total_tests)::integer, 0) AS total_labs FROM week_range LEFT OUTER JOIN grouped_labs on week_r", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "grouped_labs", + "laboratory", + "range_values", + "week_range" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_199", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "DROP FUNCTION IF EXISTS update_school_inventory_after_supply() CASCADE;CREATE OR REPLACE FUNCTION update_school_inventory_after_supply() RETURNS TRIGGER LANGUAGE plpgsql AS $trigger$ BEGIN UPDATE school_inventory AS i SET NEW.quantity = school_supplies.quantity + OLD.quantity FROM school_supplies WHERE i.cdscode = school_supplies.cdscode; RETURN NEW; END; $trigger$;DROP TRIGGER IF EXISTS trigger_insert_supply ON school_supplies;CREATE TRIGGER trigger_insert_supply AFTER INSERT ON school_supplies", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "update_school_inventory_after_supply" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_200", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT county, AVG(avgscrread + avgscrmath + avgscrwrite) / 3 AS avg_total_sat FROM satscores GROUP BY county ORDER BY avg_total_sat DESC LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"county\" does not exist | LINE 1: EXPLAIN SELECT county, AVG(avgscrread + avgscrmath + avgscrw... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_201", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH vars AS ((select count(*) from laboratory) AS vars_id) select * from laboratory where id=vars.vars_id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"AS\" | LINE 1: ...N WITH vars AS ((select count(*) from laboratory) AS vars_id... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_202", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM match_location WHERE ST_INTERSECTS(location, CIRCLE(POINT(-73.935242, 40.730610), 2));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"match_location\" does not exist | LINE 1: EXPLAIN SELECT * FROM match_location WHERE ST_INTERSECTS(loc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'match_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "match_location", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match_location" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_203", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "INSERT INTO learners\n (\"Age\", \"Gender\", \"Geographic_Location\", \"Socioeconomic_Background\",\n \"Education_Level\", \"Previous_Academic_Performance\", \"Language_Proficiency\",\n \"Preferred_Learning_Medium\", \"Learning_Pace\", \"Engagement_History\")\nVALUES\n (18,\n 'Male',\n 'Urban',\n 'Low',\n 'UndergraduateUndergraduateUndergraduate',\n 88.55,\n 'Intermediate',\n 'Video',\n 'Moderate',\n 6);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "value too long for type character varying(15)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "22001" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_204", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n x.curriculum_id,\n ARRAY_LENGTH(x.combined_array, 1) AS distinct_count\nFROM\n(\n\nSELECT\n c.curriculum_id,\n ARRAY[e.\"Content_Type\", e.\"Platform_Used\"] AS combined_array\n FROM curriculum_resources cr\n JOIN educational_resources e\n ON cr.resource_key = e.resource_key\n JOIN curricula c\n ON c.curriculum_id = cr.curriculum_id\n\n UNION\nSELECT\n c2.curriculum_id,\n ARRAY[cr2.recommended] AS combined_array\n FROM curriculum_resources cr2\n JOI", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "UNION could not convert type boolean[] to character varying[] | LINE 19: ARRAY[cr2.recommended] AS combined_array | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42846" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.1885, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-UNION-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "curricula", + "curriculum_resources", + "educational_resources" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_205", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE curricula\n ADD COLUMN status TEXT DEFAULT 'installed';\n\n\nWITH RECURSIVE curricula_to_upgrade AS (\n\nSELECT c.curriculum_id\n FROM curricula c\n WHERE c.status = 'installed'\n AND c.curriculum_id = 1\n\nUNION ALL\n\n\nSELECT c2.curriculum_id\n FROM curricula c2\n JOIN curricula_to_upgrade ctu\n ON c2.curriculum_id = ctu.curriculum_id\n)\nUPDATE curricula\nSET status = 'to upgrade'\nWHERE curriculum_id IN (\n SELECT curriculum_id\n FROM curricula_to_upgrade\n);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "curricula" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_206", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT learner_code, resource_key, SUM(duration) AS total_time_spent\nFROM event_usage\nWHERE start_timestamp BETWEEN '2024-10-01' AND '2024-10-09'\nGROUP BY learner_code, resource_key;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "event_usage" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_207", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n first_value(rating) OVER (\n PARTITION BY learner_code, resource_key\n ORDER BY usage_date\n ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW\n ) AS filled_rating,\n learner_code,\n resource_key\nFROM\n resource_usage_2\nORDER BY\n learner_code, usage_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "resource_usage_2" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_208", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT dd::date AS day_start, SUM(CASE WHEN T.incident_start <= dd AND T.incident_end >= dd THEN 1440 ELSE 0 END) AS incident_minutes FROM generate_series('2022-01-01'::timestamp, '2022-01-31'::timestamp, '1 day'::interval) dd LEFT JOIN race_incidents T ON dd::date BETWEEN T.incident_start AND T.incident_end GROUP BY dd::date ORDER BY dd::date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "race_incidents" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_209", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM CROSSTAB ('SELECT p.id, l.ldh, l.ldh, l.ldh FROM patient p JOIN laboratory l ON p.id = l.id ORDER BY 1,2;') AS (id INT, ldh_1 INT, ldh_2 INT, ldh_3 INT);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_210", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT tempId, pemId, time, rank, (CASE pointsno WHEN 1 THEN points ELSE points END ) AS points FROM (SELECT ROW_NUMBER() OVER(PARTITION BY points) AS pointsno, tempId, pemId, time, rank, points FROM (SELECT driverid AS tempId, driverid AS pemId, time, rank, points FROM results GROUP BY GROUPING SETS ((tempId, points), (tempId, pemId, time, rank))) AS b) AS s ORDER BY tempId, points ASC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "SELECT-DISTINCT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_211", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select * from results r inner join drivers d on r.driverid = d.driverid where r.grid = 21 order by r.points desc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "drivers", + "results" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_212", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO customer_orders(name, title) SELECT COALESCE(uo.name, co.name), COALESCE(uo.title, co.title) FROM customer_orders co LEFT OUTER JOIN updated_orders uo ON uo.id = co.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-INSERT", + "clauses_present": [ + "FROM", + "INSERT", + "JOIN", + "SELECT" + ], + "tables": [ + "customer_orders", + "updated_orders" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_213", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result FOR attribute_name IN (Strength, Speed, Intelligence))", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FOR\" | LINE 1: ...e, result FROM superhero_performance PIVOT(result FOR attrib... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Strength", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Speed' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Speed", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Intelligence' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Intelligence", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expecting an aggregation function in PIVOT. Line 1, Col: 103.\n SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(\u001b[4mresult\u001b[0m FOR attribute_name IN (Strength, Speed, Intelligence))\n\nRequired keyword: 'this' missing for . Line 1, Col: 107.\n CT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result \u001b[4mFOR\u001b[0m attribute_name IN (Strength, Speed, Intelligence))", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero_performance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_214", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) FROM laboratory WHERE date_part('year', date) = date_part('year', CURRENT_DATE) AND date_part('month', date) = date_part('month', CURRENT_DATE) AND date [I don't know what to put here];", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"don\" | LINE 1: ...e) = date_part('month', CURRENT_DATE) AND date [I don't know... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unterminated_string", + "message": "Unterminated quoted string", + "taxonomy_category": "syntax", + "context": "Error tokenizing 'NT_DATE) AND date [I don't know what to put here]'" + } + ], + "tags": [ + "syntax_error", + "syntax_unterminated_string" + ] + }, + { + "instance_id": "PostgreSQL_215", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH reporting_dates AS (SELECT generate_series('2000-01-01'::date, '2017-01-01'::date, '1 year'::interval) AS reporting_date) SELECT reporting_date, COUNT(CASE WHEN OpenDate > reporting_date AND (ClosedDate IS NULL OR ClosedDate <=reporting_date) THEN cdscode END) AS active_schools FROM reporting_dates LEFT JOIN schools ON true GROUP BY reporting_date ORDER BY reporting_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "reporting_dates", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_216", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT budget_id, category, amount, SUM(amount) OVER (PARTITION BY category ORDER BY amount) AS cum_amount FROM budget ORDER BY category DESC, amount;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_217", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT district_id FROM client WHERE district_id = 1 LIMIT 100;SELECT district_id FROM client WHERE district_id <> 1 LIMIT 900;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "WHERE" + ], + "tables": [ + "client" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_218", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET type = ( SELECT type, client_id FROM disp WHERE card.disp_id = disp.disp_id );", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card\" does not exist | LINE 1: EXPLAIN UPDATE card SET type = ( SELECT type, client_id FROM... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "card", + "disp" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_219", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE card (card_id SERIAL PRIMARY KEY,loan_id INT UNIQUE,type TEXT NOT NULL,issued DATE NOT NULL,CONSTRAINT fk_loan_id FOREIGN KEY (loan_id) REFERENCES loan(loan_id) ON DELETE SET NULL);ALTER TABLE loan ADD CONSTRAINT fk_card_loan FOREIGN KEY (loan_id) REFERENCES card(loan_id) ON DELETE CASCADE;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card", + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_220", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$ DECLARE value RECORD[]; BEGIN SELECT t FROM transactions_1k t LIMIT 1 INTO value[1]; SELECT c FROM customers c LIMIT 1 INTO value[2]; RAISE NOTICE 'Transaction: %', value[1]; RAISE NOTICE 'Customer: %', value[2]; END $$;", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "variable \"value\" has pseudo-type record[] | compilation of PL/pgSQL function \"inline_code_block\" near line 1", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_221", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE loan l SET status = 'updated_status', date = 'new_date', amount = 'new_amount' WHERE l.loan_id = 'loan_id_value' AND l.status = 'current_status';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: EXPLAIN UPDATE loan l SET status = 'updated_status', date = ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_222", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS patients, (SELECT * FROM doctors) AS doctors, (SELECT * FROM appointments) AS appointments;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \")\" | LINE 1: EXPLAIN SELECT coalesce(_agg(patients), '[]'::) as patients,... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expected type. Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nRequired keyword: 'to' missing for . Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nExpected type. Line 1, Col: 84.\n SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::\u001b[4m)\u001b[0m as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS p\n\n... and 3 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.2292, + "pattern_signature": "SELECT-FROM-JOIN-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "appointments", + "doctors", + "patients" + ], + "num_joins": 2, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_223", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE patients_info\nSET general_info = jsonb_set(general_info, '{accept_appointments}', '\"false\"');", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"patients_info\" does not exist | LINE 1: EXPLAIN UPDATE patients_info | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'patients_info' does not exist in schema", + "taxonomy_category": "semantic", + "context": "patients_info", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "patients_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_224", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.molecule_id, b.date AS buy_date, s.date AS sell_date, s.molecules, b.usd_total AS buy_usd_total, s.usd_total AS sell_usd_total FROM transaction b JOIN transaction s ON b.molecule_id = s.molecule_id WHERE b.sell = 0 AND s.sell = 1 ORDER BY b.date, s.date", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: boolean = integer | LINE 1: ...n s ON b.molecule_id = s.molecule_id WHERE b.sell = 0 AND s.... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transaction" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_225", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE weekdays AS ( SELECT generate_series(0, 60) AS offset ), dates AS ( SELECT CURRENT_DATE + (w.offset || ' days')::interval AS date, EXTRACT(ISODOW FROM CURRENT_DATE + (w.offset || ' days')::interval) AS day_of_week FROM weekdays w WHERE EXTRACT(ISODOW FROM CURRENT_DATE + (w.offset || ' days')::interval) IN (1, 2, 3, 4, 5, 6, 7) ), schedule_blocks_with_dates AS ( SELECT sb.*, d.date AS block_date FROM schedule_blocks sb JOIN dates d ON sb.day_of_week ILIKE to_char(d.date, 'Day') WHE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "dates", + "schedule_blocks", + "schedule_blocks_with_dates", + "weekdays" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_226", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, (select sum(buildupplayspeed) over (ROWS UNBOUNDED PRECEDING) as a), sum(buildupplayspeed) over (ROWS UNBOUNDED PRECEDING) as b from team_attributes limit 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-WINDOW-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_227", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "CREATE VIEW overview AS SELECT count(*) AS learners_count FROM learners, SELECT count(*) AS institutions_count FROM institutions, SELECT count(*) AS curricula_count FROM curricula", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELECT\" | LINE 1: ... SELECT count(*) AS learners_count FROM learners, SELECT cou... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1125, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "curricula", + "institutions", + "learners", + "overview" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_228", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT patients.patient_id, demographics.height, treatment_and_followup.primary_pathology_karnofsky_performance_score, MIN(primary_pathology_karnofsky_performance_score) AS min_performance_score FROM patients JOIN treatment_and_followup ON patients.patient_id = treatment_and_followup.patient_id JOIN demographics ON patients.patient_id = demographics.patient_id WHERE informed_consent_verified = TRUE GROUP BY patients.patient_id;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"demographics.height\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT patients.patient_id, demographics.height, tre... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "demographics", + "patients", + "treatment_and_followup" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_229", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE A(GroupNum, n, RollingSum, id) AS (\n SELECT 1, Performance_Prediction, Performance_Prediction, prediction_code\n FROM performance_predictions\n ORDER BY prediction_code ASC\n LIMIT 1\n UNION ALL\n SELECT\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN GroupNum + 1\n ELSE GroupNum\n END,\n P.Performance_Prediction,\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"UNION\" | LINE 6: UNION ALL | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.099, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WINDOW-UNION-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "a", + "performance_predictions" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_230", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT A.client_id AS child FROM client A, client B\nWHERE A.birth_date + INTERVAL '16 years' < B.birth_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "client" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_231", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT g.GasStationID FROM transactions_1k t JOIN gasstations g\nON t.GasStationID = g.GasStationID GROUP BY g.GasStationID\nHAVING SUM(t.Amount * t.Price) / SUM(t.Amount * t.Price) OVER (PARTITION BY t.CustomerID) >= 0.7", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT g.GasStationID FROM transactions_1k t JOIN ga... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0667, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-WINDOW", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "WINDOW" + ], + "tables": [ + "gasstations", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_232", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE WHEN c.type = 'gold' THEN 'Gold' ELSE 'Non-Gold'\nEND AS card_type_group, COUNT(l.loan_id) AS loan_count\nFROM loan l\nJOIN disp d ON l.account_id = d.account_id\nJOIN card c ON d.disp_id = c.disp_id\nGROUP BY c.type", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 3: FROM loan l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "card", + "disp", + "loan" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_233", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT link_to_member, link_to_event, count(1) AS total FROM attendance\nGROUP BY GROUPING SETS ((link_to_member), (link_to_member, link_to_event))\nORDER BY max(count(1)) over (partition by link_to_member) desc, max(count(1))\nover (partition by link_to_member,link_to_event) desc, count(1) desc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0479, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_234", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (CustomerID) * FROM transactions_1k ORDER BY Date DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT DISTINCT ON (CustomerID) * FROM transactions_... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_235", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "MERGE INTO treatment_and_followup_backup b USING treatment_and_followup_latest a ON b.patient_id = a.patient_id WHEN MATCHED THEN UPDATE SET followup_no = a.followup_no, primary_pathology_karnofsky_performance_score = a.primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cancer_oncology_group = a.primary_pathology_eastern_cancer_oncology_group WHEN NOT MATCHED THEN INSERT (patient_id, followup_no, primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cance", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"MERGE\" | LINE 1: MERGE INTO treatment_and_followup_backup b USING treatment_a... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'followup_no' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "followup_no" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'primary_pathology_karnofsky_performance_score' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "primary_pathology_karnofsky_performance_score" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'primary_pathology_eastern_cancer_oncology_group' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "primary_pathology_eastern_cancer_oncology_group" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'patient_id' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "patient_id" + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "INSERT-UPDATE-MERGE", + "clauses_present": [ + "INSERT", + "MERGE", + "UPDATE" + ], + "tables": [ + "treatment_and_followup_backup", + "treatment_and_followup_latest" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_236", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, engagement_history FROM learners_array;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "learners_array" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_237", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Engagement_Level, MAX(rating), MIN(rating) FROM resource_usage JOIN target_labels ON resource_usage.learner_code = target_labels.learner_code GROUP BY Engagement_Level;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"engagement_level\" does not exist | LINE 1: EXPLAIN SELECT Engagement_Level, MAX(rating), MIN(rating) FR... | ^ | Perhaps you meant to reference the column \"target_labels.Engagement_Level\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0594, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "resource_usage", + "target_labels" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_238", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, rating, usage_date FROM resource_usage WHERE (learner_code, usage_date) = (SELECT learner_code, MAX(usage_date) FROM resource_usage GROUP BY learner_code) ORDER BY learner_code, usage_date DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "resource_usage" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_239", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, CASE WHEN Geographic_Location = 'Urban' THEN 1 WHEN Geographic_Location = 'Rural' THEN 2 ELSE 0 END AS location_id, AVG(Pre_Test_Score) AS average_pre_test_score FROM learners WHERE Engagement_History > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"$\" | LINE 1: ...ciency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_st... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Pre_Test_Score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Pre_Test_Score", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 318.\n tory > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN $\u001b[4m{\u001b[0msocio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' \n\nRequired keyword: 'this' missing for . Line 1, Col: 395.\n diate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN $\u001b[4m{\u001b[0msocio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0552, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_240", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH src(id,geom) as (values (1, 'linestring(0 0, 0 10)'::geometry), (2, 'linestring(0 10, 0 11)'::geometry), (3, 'linestring(1 1, 0 5)'::geometry), (4, 'linestring(1 1, 2 2)'::geometry)) SELECT a.id, st_asText(st_intersection(a.geom, b.geom)) FROM src AS a WHERE NOT EXISTS (SELECT 1 FROM src as b WHERE a.id != b.id AND ST_Toches(a.geom, b.geom) AND ST_Equals(ST_EndPoint(b.geom), ST_Intersection(a.geom, b.geom)));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"b\" | LINE 1: ...)) SELECT a.id, st_asText(st_intersection(a.geom, b.geom)) F... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0917, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "VALUES", + "WHERE", + "WITH" + ], + "tables": [ + "src" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_241", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "select device_info::json ->> 'SerialNumber' as SerialNumber, cto ->> 'ChannelId'::INT AS channelid, cto ->> 'ChannelName' AS ChannelName from device_details CROSS JOIN LATERAL json_array_elements(device_info::json ->'ChannelListDto') Channels(cto);", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type integer: \"ChannelId\" | LINE 1: ...:json ->> 'SerialNumber' as SerialNumber, cto ->> 'ChannelId... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'cto' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "cto", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "value_format_mismatch", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "device_details" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_242", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH test AS ( SELECT EXTRACT(DAY FROM diff) || ' days ' || EXTRACT(HOUR FROM diff) || ' hours ' || EXTRACT(MINUTE FROM diff) || ' minutes ' || EXTRACT(SECOND FROM diff) || ' seconds ' AS time_diff FROM ( SELECT TIMESTAMP '2023-01-10 15:12:24' - TIMESTAMP '2023-01-01 10:34:36' AS diff ) AS diff_query JOIN ( SELECT generate_series( timestamp '2023-01-01', timestamp '2023-01-10', interval '1 day' ) AS the_day ) AS dates ON dates.the_day BETWEEN TIMESTAMP '2023-01-01 10:34:36' AND TIMESTAMP '2023-0", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2021, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "test" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_243", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH links AS (SELECT greatest(link.source_cluster, link.target_cluster) AS big, least(link.source_cluster, link.target_cluster) AS smol, link.type AS type FROM link AS link) SELECT l.cluster AS left_id, l.cluster_type AS left_type, l.cluster_label AS left_label, r.cluster AS right_id, r.cluster_type AS right_type, r.cluster_label AS right_label, count(distinct(l.article)) AS articles, array_agg(distinct(links.type)) AS link_types FROM tag AS r, tag AS l JOIN links ON l.cluster = links.big WHERE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "link", + "links", + "tag" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_244", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT i.country, o.name, o.city, o.established FROM public.ismember i INNER JOIN\npublic.organization o ON o.abbreviation = i.organization WHERE i.type = 'member'\nAND i.country = 'CI' ORDER BY o.established DESC LIMIT 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "ismember", + "organization" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_245", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS (select inst.\"Institution_Type\", outcm.\"Pre_Test_Score\", dense_rank()\nover (partition by \"Institution_Type\" order by \"Pre_Test_Score\" desc) as score_rank from outcomes as outcm\njoin enrollment as enrl on outcm.learner_code = enrl.learner_code join institutions as inst\non enrl.institution_key = inst.institution_key where inst.\"Institution_Type\" = 'Public' or\ninst.\"Institution_Type\" = 'Private') select (case when \"Institution_Type\" = 'Public' AND score_rank = 1\nTHEN \"Pre_Test_Score\" EN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1844, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "enrollment", + "institutions", + "outcomes" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_246", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT regexp_replace(\"Content_Type\", '^(.)|\\1', '', 'ig') FROM educational_resources", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "educational_resources" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_247", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "select regexp_replace((select regexp_replace(primary_pathology_histological_type, 'NOS$',\n'Not Otherwise Specified') from pathology_and_surgery), 'Adenocarcinoma', 'Adenoma Carcinoma')\nas transformed_histological_type from pathology_and_surgery;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "pathology_and_surgery" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_248", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "(SELECT COUNT(*) FROM sp_artists WHERE pop > 50) / (SELECT COUNT(*) FROM sp_artists);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"/\" | LINE 1: (SELECT COUNT(*) FROM sp_artists WHERE pop > 50) / (SELECT C... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_artists" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_249", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE WHEN COALESCE(primary_pathology_initial_pathologic_diagnosis_method,\nprimary_pathology_init_pathology_dx_method_other) LIKE 'Other method, specify:'\nTHEN NULL ELSE primary_pathology_neoplasm_histologic_grade END AS histologic_grade,\nCASE WHEN COALESCE(primary_pathology_initial_pathologic_diagnosis_method,\nprimary_pathology_init_pathology_dx_method_other) LIKE 'Other method, \nspecify:' THEN NULL ELSE primary_pathology_days_to_initial_pathologic_diagnosis END AS\ndays_to_initial_diagnos", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "pathology_and_surgery" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_250", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM sp_album_ctb WHERE (alb, art, feat_arts, start_date) IN (SELECT alb, art, feat_arts, end_date + INTERVAL '1 day' FROM sp_album_ctb);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"end_date\" does not exist | LINE 1: ...arts, start_date) IN (SELECT alb, art, feat_arts, end_date +... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_album_ctb" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_251", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT patients.patient_id, patients.patient_barcode, patient_addresses.address_id, patient_addresses.city_of_procurement FROM patients, patient_addresses WHERE patients.patient_id = 1 AND patient_addresses.patient_id = patients.patient_id ORDER BY patient_addresses.address_id DESC LIMIT 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "patient_addresses", + "patients" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_252", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT l.learner_code, l.gender, r.resource_key, 'Regular Feedback' as FeedbackType, r.feedback as UserFeedback FROM learners l INNER JOIN resource_usage r ON l.learner_code = r.learner_code WHERE UserFeedback = ANY(ARRAY['Negative']) UNION ALL SELECT l.learner_code, l.gender, 0 as resource_key, 'Synthetic Feedback' as FeedbackType, CASE WHEN o.learner_satisfaction_score < 3 THEN 'Negative' ELSE 'Positive' END as UserFeedback FROM learners l INNER JOIN outcomes o ON l.learner_code = o.learner_co", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column l.gender does not exist | LINE 1: EXPLAIN SELECT l.learner_code, l.gender, r.resource_key, 'Re... | ^ | Perhaps you meant to reference the column \"l.Gender\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "learners", + "outcomes", + "resource_usage" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_253", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM city ORDER BY COALESCE(SUBSTRING(name FROM '[A-Z]+'), ''), COALESCE(SUBSTRING(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\uff1b\" | LINE 1: ... COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 190.\n NG(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\u001b[4m\uff1b\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "city" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_254", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.name, c.code, array_agg(cn.othername) AS alternative_names FROM country c LEFT JOIN countryothername cn ON c.code = cn.country GROUP BY c.name, c.code ORDER BY c.name ASC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "country", + "countryothername" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_255", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ST_Touches(ol.geom, l.geom)\nFROM institution_location ol, learner_institution_location l\nWHERE ST_Touches(ol.geom, l.geom)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"institution_location\" does not exist | LINE 2: FROM institution_location ol, learner_institution_location l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'institution_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "institution_location", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'learner_institution_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "learner_institution_location", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "institution_location", + "learner_institution_location" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_256", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM\n (SELECT tissue_source_site, COUNT (*) AS total\n FROM (SELECT * FROM patients) AS _\n GROUP BY tissue_source_site) result_total\n INNER JOIN\n (SELECT tissue_source_site, COUNT (*) AS processed\n FROM (SELECT * FROM patients WHERE informed_consent_verified=true) AS _\n GROUP BY tissue_source_site) result_processed\n ON result_total.tissue_source_site = result_processed.tissue_source_site;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2813, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patients" + ], + "num_joins": 1, + "num_subqueries": 4, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_257", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH sales AS ( SELECT \"gasstationid\" AS \"GasstationId\", \"customerid\" AS \"CustomerId\", \"date\" AS \"SaleDate\", \"amount\" AS \"Amount\" FROM \"transactions_1k\" ), initial_purchase AS ( SELECT \"GasstationId\", \"CustomerId\", MIN(CAST(\"SaleDate\" AS date)) AS \"FirstPurchaseDate\" FROM sales GROUP BY \"GasstationId\", \"CustomerId\" ), customer_wages AS ( SELECT i.\"CustomerId\", s.* FROM sales s JOIN initial_purchase i ON s.\"CustomerId\" = i.\"CustomerId\" WHERE s.\"SaleDate\" >= i.\"FirstPurchaseDate\" ORDER BY i.\"Custo", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..., \"date\" AS \"SaleDate\", \"amount\" AS \"Amount\" FROM \"transacti... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "customer_wages", + "initial_purchase", + "sales", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_258", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE (SELECT quote_ident(c.table_schema) || '.' || quote_ident(c.table_name) || ' RENAME \"' || c.column_name || '\" TO ' || quote_ident(lower(c.column_name)) || ';' As ddlsql FROM information_schema.columns As c WHERE c.table_schema NOT IN('information_schema', 'pg_catalog') AND c.column_name <> lower(c.column_name) ORDER BY c.table_schema, c.table_name, c.column_name);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: ALTER TABLE (SELECT quote_ident(c.table_schema) || '.' || qu... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_259", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT product_id FROM product WHERE product_id IN (101, 103) AND is_searchable = true", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "product" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_260", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM orders WHERE customer_id = 1 OR product_id = 'P202'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_261", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT transaction_date, salesperson_name FROM sales_log WHERE salesperson_name NOT IN (SELECT salesperson_name FROM sales_log GROUP BY transaction_date, salesperson_name)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sales_log" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_262", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT p.product_id, p.product_name FROM Product p JOIN ProductPrice pp ON p.product_id = pp.product_id WHERE pp.price < ( SELECT MAX(price) FROM ProductPrice WHERE product_id = p.product_id ) ORDER BY p.product_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1469, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "product", + "productprice" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_263", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CD.customer_id, COUNT(S.customer_id) AS total_sales, SUM(S.amount) AS total_amount, COUNT(C.customer_id) AS total_communications, COUNT(F.customer_id) AS total_feedback, COUNT(F.customer_id) FILTER (WHERE F.feedback_type='positive') AS total_positive_feedback, COUNT(F.customer_id) FILTER (WHERE F.feedback_type='negative') AS total_negative_feedback FROM customer_details CD JOIN sales S ON CD.customer_id = S.customer_id JOIN communications C ON CD.customer_id = C.customer_id JOIN feedback ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-FILTER", + "clauses_present": [ + "FILTER", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "communications", + "customer_details", + "feedback", + "sales" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_265", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM orders WHERE '10015' = ANY(string_to_array(orders.delivery_zones, ','))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_266", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH t1 AS ( SELECT e.event_id FROM event e LEFT JOIN attendance a ON e.event_id = a.link_to_event ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at end of input | LINE 1: ...t e INNEr JOIN attendance a ON e.event_id = a.link_to_event) | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Failed to parse any statement following CTE. Line 1, Col: 197.\n nt ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event\u001b[4m)\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_267", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.* FROM transactions_1k LEFT JOIN customers ON transactions_1k.customerid = customers.customerid LIMIT 5", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT transactions_1k.* FROM transactions_1k LEFT J... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_268", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT bond_id FROM bond WHERE bond_id LIKE 'TR1%5' OR bond_id LIKE 'TR2%4'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_269", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(cost) AS total_cost, link_to_member FROM expense GROUP BY link_to_budget", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"expense.link_to_member\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT SUM(cost) AS total_cost, link_to_member FROM ... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "expense" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_270", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT t.trans_id, a.district_id, t.amount FROM trans AS t JOIN account AS a ON t.account_id = a.account_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "account", + "trans" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_271", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT schools.cdscode, frpm.cdscode FROM schools LEFT JOIN frpm ON schools.cdscode = frpm.cdscode", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "frpm", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_272", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELEC Player.player_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_attributes ON Player.player_api_id = Player_Attributes.player_api_id WHERE Player_Attributes.overall_rating = 68", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELEC\" | LINE 1: SELEC Player.player_api_id, Player.player_name, Player_Attri... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 13.\n SELEC Player\u001b[4m.\u001b[0mplayer_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_att", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_273", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM attribute JOIN hero_attribute ON hero_attribute.attribute_id = attribute.id WHERE (attribute_name <> 'Speed' AND attribute_value <> 35)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attribute", + "hero_attribute" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_274", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cdscode, COUNT(cdscode) FROM schools WHERE district = 'Alameda County Office of Education' LIMIT 1", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"schools.cdscode\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT cdscode, COUNT(cdscode) FROM schools WHERE di... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_275", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.driverstandingsid, s.raceid, d.driverid FROM driverstandings AS s LEFT JOIN drivers AS d ON d.driverid = s.driverid AND s.raceid = 19", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0573, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "drivers", + "driverstandings" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_276", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT status, SUM(amount) AS total_amount, SUM(payments) AS total_payments, (total_amount + total_payments) AS s FROM loan GROUP BY status", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...yments, (total_amount + total_payments) AS s FROM loan GROUP... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_277", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(diagnosis), diagnosis FROM patient WHERE diagnosis = 'PSS' GROUP BY diagnosis HAVING COUNT(*) > 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0375, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_278", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, b.name AS BadgeName, b.date AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000 AND b.name = 'Teacher' UNION ALL SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, NULL AS BadgeName, NULL AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "UNION types timestamp with time zone and text cannot be matched | LINE 1: ..., u.displayname, u.reputation, NULL AS BadgeName, NULL AS Ba... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "badges", + "users" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_279", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(expense.cost) AS total_expense, SUM(budget.amount) AS total_budget, budget.link_to_event FROM budget, expense WHERE budget.budget_id = expense.link_to_budget GROUP BY budget.link_to_event", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "budget", + "expense" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_280", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, LENGTH(superhero_name) FROM superhero WHERE LENGTH(superhero_name) = (SELECT MIN(LENGTH(superhero_name)) FROM superhero) OR LENGTH(superhero_name) = (SELECT MAX(LENGTH(superhero_name)) FROM superhero) ORDER BY LENGTH(superhero_name) ASC NULLS FIRST, superhero_name ASC NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1531, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_281", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT customerid, *, MAX(date) AS maxdate FROM transactions_1k", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...DISTINCT customerid, *, MAX(date) AS maxdate FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-DISTINCT-FROM", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_282", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and power = '2') THEN coalesce(watermark, '998') watermark WHEN (colors = 'R' and power = '0') THEN coalesce(watermark, '999') watermark END) watermark FROM cards", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"watermark\" | LINE 1: ... and power = '4') THEN coalesce(watermark, '996') watermark ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expected END after CASE. Line 1, Col: 84.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996'\u001b[4m)\u001b[0m watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (color\n\nExpecting ). Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow\n\nInvalid expression / Unexpected token. Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_283", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT posts.owneruserid, posts.tags, AVG(posts.score) AS AvgOfScore FROM posts WHERE posts.owneruserid = 183 AND posts.tags LIKE '%distribution%' AND EXISTS(SELECT creaiondate FROM posts AS pdates WHERE pdates.owneruserid = posts.owneruserid AND pdates.tags = posts.tags AND pdates.creaiondate = posts.creaiondate ORDER BY pdates.creaiondate DESC NULLS LAST LIMIT 5)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column posts.owneruserid does not exist | LINE 1: EXPLAIN SELECT posts.owneruserid, posts.tags, AVG(posts.scor... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'owneruserid' does not exist in table 'posts' (referenced as 'posts.owneruserid')", + "taxonomy_category": "semantic", + "context": "posts.owneruserid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'score' does not exist in table 'posts' (referenced as 'posts.score')", + "taxonomy_category": "semantic", + "context": "posts.score", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'creaiondate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "creaiondate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'creaiondate' does not exist in table 'posts' (referenced as 'posts.creaiondate')", + "taxonomy_category": "semantic", + "context": "posts.creaiondate", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_284", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT link_to_member, COUNT(DISTINCT DATE(event_date)) AS total_attendance_days FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] WITH cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link_to_member ORDER BY DATE(event_date)) AS rn FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AN", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WITH\" | LINE 1: ... AND '2023-12-31' GROUP BY link_to_member [split] WITH cte A... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 244.\n ent.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] \u001b[4mWITH\u001b[0m cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_285", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT member_id, first_name, last_name FROM member) AS A LEFT JOIN (SELECT link_to_member FROM attendance WHERE link_to_event = 'recEVTik3MlqbvLFi') AS B ON A.member_id = B.link_to_member", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "attendance", + "member" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_286", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT t.customerid, p.description, MAX(t.date) FROM transactions_1k AS t INNER JOIN products AS p ON t.productid = p.productid GROUP BY t.customerid", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...ECT t.customerid, p.description, MAX(t.date) FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "products", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_287", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.CustomerID AS Customer1, t2.CustomerID AS Customer2, COUNT(*) AS Count FROM (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t1, (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t2 WHERE t1.ConcatenatedValue = t2.ConcatenatedValue GROUP BY Customer1, Customer2 ORDER BY Count DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.175, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_288", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DAILY_REVENUE AS (SELECT date, SUM(amount) AS TotalAmount FROM transactions_1k GROUP BY date ORDER BY date ASC NULLS FIRST), MOVING_AVG AS (SELECT date, SUM(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS TotalAmount, CAST(AVG(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS DECIMAL(10, 2)) AS AverageAmount FROM daily_revenue) SELECT * FROM moving_avg", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... AS (SELECT date, SUM(amount) AS TotalAmount FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "daily_revenue", + "moving_avg", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_289", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.department, COUNT(e.expense_id) AS cnt, e.cost AS highest_cost FROM expense AS e INNER JOIN member AS mem ON e.link_to_member = mem.member_id INNER JOIN major AS m ON mem.link_to_major = m.major_id GROUP BY m.department ORDER BY cnt DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"e.cost\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ... SELECT m.department, COUNT(e.expense_id) AS cnt, e.cost AS ... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "expense", + "major", + "member" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_290", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT country, segment, COUNT(*) AS count_segment, DENSE_RANK() OVER (PARTITION BY country ORDER BY (SELECT COUNT(*) AS count_segment FROM gasstations) NULLS FIRST) AS \"rnk\" FROM gasstations GROUP BY country, segment) AS segment_rank WHERE rnk = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1948, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "gasstations" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_291", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND ex.\"aCL IgG\" > 3.0)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"patient\" | LINE 1: ...LECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 59.\n SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM \u001b[4mpatient\u001b[0m pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND e", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_292", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(b.bond_id) AS total, b1.bond AS bond, b2.bond_type_dash AS bond_type_dash, b3.bond_type_equal AS bond_type_equal, b4.bond_type_hash AS bond_type_hash FROM bond AS b LEFT JOIN (SELECT bond_id, COUNT(*) AS bond FROM bond WHERE bond_id = 'TR000_1_2') AS b1 ON b1.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_dash FROM bond WHERE bond_type = '-') AS b2 ON b2.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_equal FROM bond WHERE bond_type = '=') ", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"bond.bond_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...S bond_type_hash FROM bond AS b LEFT JOIN (SELECT bond_id, C... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.3542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 4, + "num_subqueries": 4, + "num_ctes": 0, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_293", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id GROUP BY l.country_id HAVING l.country_id > 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 1: ...', name) FROM country c WHERE l.country_id = c.id GROUP BY l... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 101.\n UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id \u001b[4mGROUP BY\u001b[0m l.country_id HAVING l.country_id > 1000;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "FROM-WHERE-UPDATE", + "clauses_present": [ + "FROM", + "UPDATE", + "WHERE" + ], + "tables": [ + "country", + "league" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_294", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.*, rank := rank + 1 AS ranking FROM (SELECT 0 AS rank) AS init, results AS r JOIN drivers AS d ON r.driverid = d.driverid ORDER BY r.fastestlap ASC NULLS FIRST, d.dob ASC NULLS FIRST LIMIT 10", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \":=\" | LINE 1: EXPLAIN SELECT r.*, rank := rank + 1 AS ranking FROM (SELECT... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1521, + "pattern_signature": "SELECT-FROM-JOIN-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "drivers", + "results" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_295", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE CONCAT(date, ' ', time) BETWEEN CAST('2012-08-22' AS DATE) AND CAST('2012-08-23' AS DATE) ORDER BY amount DESC NULLS LAST LIMIT 3", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT * FROM transactions_1k WHERE CONCAT(date, ' '... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_296", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT state, MAX(county) AS County, MAX(city) AS City, MAX(cdscode) AS CDSCode FROM schools WHERE NOT state IS NULL GROUP BY state", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_297", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account.account_id, loan.loan_id, SUM(loan.amount) AS total_amount FROM account JOIN loan ON account.account_id = loan.account_id JOIN trans ON loan.account_id = trans.account_id WHERE loan.status LIKE '%A%' AND trans.type LIKE '%PRIJEM%' AND trans.type LIKE '%VYDAJ%' GROUP BY loan.loan_id ORDER BY account.account_id NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...UM(loan.amount) AS total_amount FROM account JOIN loan ON ac... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1177, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "loan", + "trans" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_298", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT date, COUNT(*) FROM transactions_1k WHERE EXTRACT(DAY FROM date) IN (3, 24)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT date, COUNT(*) FROM transactions_1k WHERE EXT... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_299", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SELECT 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district WHERE A8 = 4 [split] SELECT 4 AS RATES, COUNT(A9) FROM district WHERE A9 = 4 [split] SELECT 3 AS RATES, COUNT(A8) FROM district WHERE A8 = 3 [split] SELECT 3 AS RATES, COUNT(A9) FROM district WHERE A9 = 3", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 1: ... 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SE... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 70.\n SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] \u001b[4mSELECT\u001b[0m 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "district" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_300", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.id, s.code, s.parentcode AS ancestralCode FROM sets AS s WHERE NOT s.parentcode IS NULL", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "sets" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_301", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT event.event_id AS event_id, event.event_name AS event_name, MAX(attendance.link_to_member) AS largest_member, expense.cost FROM event LEFT JOIN attendance ON event.event_id = attendance.link_to_event LEFT JOIN expense ON attendance.link_to_member = expense.link_to_member WHERE event.event_id = 'rec2N69DMcrqN9PJC' GROUP BY event.event_id, expense.cost", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event", + "expense" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_302", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH Partitioned AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY CustomerID, Date ORDER BY CustomerID NULLS FIRST, Date NULLS FIRST) AS RowNumber FROM transactions_1k) SELECT *, CASE WHEN RowNumber > 1 THEN 0 ELSE COALESCE(CAST(AGE(CAST((SELECT MAX(Date) FROM transactions_1k WHERE Date < a.Date AND CustomerID = a.CustomerID) AS TIMESTAMP), CAST(a.Date AS TIMESTAMP)) AS BIGINT), 0) END AS Days_between FROM partitioned AS a", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... NULLS FIRST, Date NULLS FIRST) AS RowNumber FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.124, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "partitioned", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_303", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT hp1.hero_id AS id1, hp2.hero_id AS id2 FROM hero_power AS hp1 INNER JOIN hero_power AS hp2 ON hp1.hero_id < hp2.hero_id WHERE hp1.power_id IN (SELECT DISTINCT hp2.power_id) GROUP BY id1, id2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "hero_power" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_304", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.transactionid, transactions_1k.date, transactions_1k.customerid, STRING_AGG(gasstations.gasstationid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS gasstation_ids, STRING_AGG(products.productid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS product_ids FROM transactions_1k LEFT JOIN gasstations ON transactions_1k.gasstationid = gasstations.gasstationid LEFT JOIN products ON transactions_1k.productid = products.productid WHERE NOT trans", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...1k.transactionid NULLS FIRST) AS product_ids FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_305", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM budget GROUP BY link_to_event WHEN event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN 'Open' WHEN event_status = 'Open' THEN 'Open' WHEN event_status = 'Planning' THEN 'Planning' ELSE 'Unknown' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHEN\" | LINE 1: ...PLAIN SELECT * FROM budget GROUP BY link_to_event WHEN event... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n SELECT * FROM budget GROUP BY link_to_event \u001b[4mWHEN\u001b[0m event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_306", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.customerid, SUM(t.amount) FROM customers AS c INNER JOIN transactions_1k AS t ON c.customerid = t.customerid GROUP BY c.customerid", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"customers\" does not exist | LINE 1: EXPLAIN SELECT c.customerid, SUM(t.amount) FROM customers AS... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_307", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Time\") FROM cards) NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"Update_Time\" does not exist | LINE 1: ...HERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Ti... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_schema' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_schema", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Update_Time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Update_Time", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "tables" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_308", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.* FROM match AS m WHERE m.league_id = '1' GROUP BY m.date ORDER BY m.date ASC NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"m.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT m.* FROM match AS m WHERE m.league_id = '1' G... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_309", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n id,\n MAX(Max_v) AS Max_v,\n NULL AS MAX_attribute\nFROM (\n SELECT id, crossing AS Max_v, 'crossing' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, finishing AS Max_v, 'finishing' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, heading_accuracy AS Max_v, 'heading_accuracy' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, short_passing AS Max_v, 'short_passing' AS AttributeName FROM Player_Attributes\n UNION ALL\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-GROUP-UNION-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_310", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"??\" | LINE 1: EXPLAIN UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Expected table name but got . Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');\n\nInvalid expression / Unexpected token. Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_311", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE content (id serial PRIMARY KEY NOT NULL, item_id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_item_id <> id)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"nested_item_id\" | LINE 1: ...er\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_ite... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Required keyword: 'expressions' missing for . Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)\n\nExpecting ). Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_312", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cd.*, fd.* FROM cards cd INNER JOIN foreign_data fd ON cd.uuid = fd.uuid WHERE cd.availability = 'mtgo,paper' ORDER BY cd.releaseDate DESC, cd.uuid, fd.id LIMIT 100;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column cd.releasedate does not exist | LINE 1: ...uid WHERE cd.availability = 'mtgo,paper' ORDER BY cd.release... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "foreign_data" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_313", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.col2, t.col3 FROM (SELECT '2023-01-01' AS col1, 'Some ruling text.' AS col2, (SELECT uuid FROM cards WHERE borderColor = 'black' AND layout = 'normal') AS col3 UNION ALL SELECT '2023-01-02' AS col1, 'Another ruling text.' AS col2, (SELECT uuid FROM cards WHERE isAlternative = 1) AS col3) t WHERE NOT EXISTS (SELECT 1 FROM rulings WHERE rulings.date = t.col1::date);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"date\" is of type date but expression is of type text | LINE 1: ...AIN INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.... | ^ | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_type_mismatch", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2521, + "pattern_signature": "SELECT-FROM-WHERE-UNION-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "cards", + "rulings" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_314", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO constructorResults (constructorResultsId, raceId, constructorId, points, status)\nSELECT constructorResults.constructorResultsId, constructorResults.raceId, constructorResults.constructorId, constructorResults.points, constructorResults.status FROM constructors INNER JOIN constructorResults ON constructorResults.constructorResultsId = constructors.constructorId;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-INSERT", + "clauses_present": [ + "FROM", + "INSERT", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "constructorresults", + "constructors" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_315", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE Match SET date = TO_CHAR(make_timestamp(extract(year from date::timestamp)::int, extract(month from date::timestamp)::int, extract(day from date::timestamp)::int, 14, extract(minute from date::timestamp)::int, extract(second from date::timestamp)::double precision), 'YYYY-MM-DD HH24:MI:SS');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_316", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT element FROM atom LEFT JOIN molecule ON atom.molecule_id = molecule.molecule_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_317", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT humidity_level, (humidity_level - LAG(humidity_level, 1) OVER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_humidity WHERE diff = 0 OR diff > 10", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"warehouse_humidity\" does not exist | LINE 1: ...ER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'warehouse_humidity' does not exist in schema", + "taxonomy_category": "semantic", + "context": "warehouse_humidity", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "warehouse_humidity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_318", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders@lpu.edu;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"members\" does not exist | LINE 1: EXPLAIN SELECT s.member_id FROM members AS s WHERE s.positio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'members' does not exist in schema", + "taxonomy_category": "semantic", + "context": "members", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 95.\n SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders\u001b[4m@\u001b[0mlpu.edu;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "members" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_319", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, SUM(count) AS COUNT, SUM(excerptpostid) AS EXCERPTPOSTID FROM backup_colour", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"backup_colour.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT id, SUM(count) AS COUNT, SUM(excerptpostid) A... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "backup_colour" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_320", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id FROM cards JOIN decks ON cards.id = decks.card1_id WHERE decks.card1_id <> 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"decks\" does not exist | LINE 1: EXPLAIN SELECT id FROM cards JOIN decks ON cards.id = decks.... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'decks' does not exist in schema", + "taxonomy_category": "semantic", + "context": "decks", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_321", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, COUNT(*) FROM races", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"races.name\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT name, COUNT(*) FROM races | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_322", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT team_list.t_id FROM team_list LEFT JOIN detail ON team_list.t_id = detail.t_id WHERE detail.type IN ('a', 'b') GROUP BY team_list.t_id HAVING COUNT(DISTINCT detail.type) = 2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0677, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "detail", + "team_list" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_323", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH MissingValues AS (SELECT a.id + 1 AS missing_value FROM worker1 AS a LEFT JOIN worker1 AS b ON a.id + 1 = b.id WHERE b.id IS NULL) SELECT MIN(missing_value) AS lowest_missing_value FROM missingvalues WHERE NOT missing_value IN (SELECT id FROM worker2)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "missingvalues", + "worker1", + "worker2" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_324", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT userid, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as view_rank, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as favorite_rank, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as upvote_rank FROM user_record ORDER BY userid", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0292, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "user_record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_326", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(t1.quantity) AS total FROM products AS t1 LEFT JOIN records AS t2 ON t1.order_id = t2.order_id WHERE t2.order_status = 'A'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "products", + "records" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_327", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT type, COUNT(*) AS type_count FROM card_type WHERE cardid IN (SELECT DISTINCT cardid FROM info) GROUP BY type ORDER BY type_count DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card_type\" does not exist | LINE 1: EXPLAIN SELECT type, COUNT(*) AS type_count FROM card_type W... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card_type' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card_type", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "card_type", + "info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_328", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT results.score, scores.value, scores.segment FROM customer_scores AS scores JOIN customer_results AS results ON scores.segment = results.segment WHERE results.score >= scores.score GROUP BY scores.segment ORDER BY scores.customerid DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"results.score\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT results.score, scores.value, scores.segment F... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'customer_scores' does not exist in schema", + "taxonomy_category": "semantic", + "context": "customer_scores", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'customer_results' does not exist in schema", + "taxonomy_category": "semantic", + "context": "customer_results", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "logical_grouping_error", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "customer_results", + "customer_scores" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_329", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CHECK(id <> spouseid)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"CHECK\" | LINE 1: CHECK(id <> spouseid) | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_330", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE log_content (\"log_id\" INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, \"content\" VARCHAR(32) NOT NULL, \"no_of_chars\" INT NULL DEFAULT CHAR_LENGTH(\"content\"), PRIMARY KEY (\"log_id\"))", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot use column reference in DEFAULT expression | LINE 1: ... NULL, \"no_of_chars\" INT NULL DEFAULT CHAR_LENGTH(\"content\")... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "log_content" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_331", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE products SET description = 'Other' WHERE productid = 2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_332", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CASE WHEN amount_sold < 1000 THEN 'Under 1000' WHEN amount_sold BETWEEN 1000 AND 9999 THEN '1000 to 9999' WHEN amount_sold BETWEEN 10000 AND 49999 THEN '10000 to 49999' WHEN amount_sold >= 50000 THEN '50000 and above' END AS range, AVG(Count) AS avg FROM sales_data GROUP BY range", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"sales_data\" does not exist | LINE 1: ...0 and above' END AS range, AVG(Count) AS avg FROM sales_data... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'sales_data' does not exist in schema", + "taxonomy_category": "semantic", + "context": "sales_data", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_333", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "DELETE FROM pitstops WHERE raceid = (SELECT MIN(raceid) FROM pitstops GROUP BY milliseconds HAVING COUNT(*) > 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING-DELETE-SUBQUERY", + "clauses_present": [ + "DELETE", + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_335", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT c.* FROM cards c WHERE c.setcode IN (SELECT setcode FROM cards WHERE isreprint = 1) OR c.id = (SELECT MAX(id) FROM cards WHERE setcode = c.setcode AND isreprint = 0)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_336", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < 40000);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'list' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "list" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_337", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "SELECT * FROM rules AS t1 WHERE t1.valid_from <= '2024-12-31' AND (t1.valid_to >= '2022-07-01' OR t1.valid_to IS NULL) AND NOT EXISTS(SELECT 1 FROM rules AS t2 WHERE t2.valid_from > t1.valid_from AND t2.valid_from <= '2024-12-31' AND (t2.valid_to IS NULL OR t2.valid_to > '2022-07-01') AND t2.valid_from <= COALESCE(t1.valid_to, '2024-12-31'))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "rules" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_338", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.product_code, t1.product_id, t1.assign_key, STRING_AGG(t2.value_name, ',') FROM products_sample AS t1 LEFT JOIN value_list AS t2 ON t2.value_id::text = ANY(string_to_array(t1.assign_key, ',')) GROUP BY t1.assign_key", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"t1.product_code\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT t1.product_code, t1.product_id, t1.assign_key... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "products_sample", + "value_list" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_339", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, p.name, c.item, c.size FROM packages p LEFT JOIN contents c ON (c.packageid=p.id) WHERE (( p.id IN ( SELECT packageid FROM contents WHERE item='square' AND size='A' ) AND ( p.id IN ( SELECT packageid FROM contents WHERE item='circle' AND size='B' )) GROUP BY p.id HAVING ( SELECT COUNT(*) FROM contents WHERE packageid=p.id ) = 2;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 1: ...FROM contents WHERE item='circle' AND size='B' )) GROUP BY p... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "2 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.2667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "contents", + "packages" + ], + "num_joins": 1, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_340", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ProductID, SPLIT_PART(Description, 'x', 1) AS count, SPLIT_PART(Description, 'x', 2) AS type FROM product", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "product" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_341", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH duplicates AS (SELECT product FROM promotions GROUP BY product HAVING COUNT(product) > 1) SELECT * FROM promotions INNER JOIN duplicates ON promotions.product = duplicates.product", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "duplicates", + "promotions" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_342", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team, MIN(source) AS source, MAX(destination) AS destination FROM source_destination_flight GROUP BY team", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "source_destination_flight" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_343", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)), u.displayname, COUNT(c.id) AS nbrOfComments FROM comments AS c INNER JOIN users AS u ON c.userid = u.id WHERE EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)) = '2010' GROUP BY u.id", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"c.creationdate\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT EXTRACT(YEAR FROM CAST(c.creationdate AS DATE... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "comments", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_344", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.transactionid, g.gasstationid, p.productid, COALESCE(t1.date, g.country, p.description) AS date, COALESCE(t1.amount, 0) AS amount, COALESCE(g.chainid, 0) AS chainid, COALESCE(p.description, '') AS description FROM transactions_1k AS t1 FULL OUTER JOIN gasstations AS g ON t1.gasstationid = g.gasstationid FULL OUTER JOIN products AS p ON COALESCE(t1.date, g.country) = p.productid WHERE t1.date IS NULL AND g.country IS NULL", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..., COALESCE(p.description, '') AS description FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_345", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (\"account_id\", \"district_id\", \"frequency\", \"account_type\", \"date\") VALUES (12345, 18, 'POPLATEK MESICNE', 'Regular', '1970-12-13')", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type bigint: \"1970-12-13\" | LINE 1: ...VALUES (12345, 18, 'POPLATEK MESICNE', 'Regular', '1970-12-1... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + } + ], + "tags": [ + "value_format_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_346", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE HierarchyCTE(entityid, parentid, emission, total_emission, percentage, level) AS (\n SELECT entityid, parentid, emission, emission AS total_emission, pctcontribution, 0\n FROM tree_table\n WHERE NOT entityid IN (SELECT DISTINCT parentid FROM tree_table WHERE NOT parentid IS NULL)\n UNION ALL\n SELECT h.entityid, h.parentid, h.emission, h.emission + cte.total_emission * (CAST(cte.pctcontribution AS DOUBLE PRECISION) / NULLIF(100, 0)) AS total_emission, h.pctcontribution, ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 11: FROM ( | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.2323, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "hierarchycte", + "tree_table" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_348", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT j.* FROM event e, json_array_elements(e.event_schedule->'$.*[*]') AS j(element)\nCROSS JOIN LATERAL (\n SELECT\n (j.element->>'start')::TIME AS date_start,\n (j.element->>'end')::TIME AS date_end,\n (j.element->>'*')::VARCHAR(10) AS day\n) AS j\nWHERE e.event_id='rec0Si5cQ4rJRVzd6';", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "table name \"j\" specified more than once", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42712" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_349", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT\n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 5: ...part('day', lastaccessdate - creationdate) + 1) - [subtract ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Expected ]. Line 5, Col: 79.\n \n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract \u001b[4mholidays\u001b[0m] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;\n\nInvalid expression / Unexpected token. Line 5, Col: 80.\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays\u001b[4m]\u001b[0m AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_350", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS count FROM duration AS d WHERE (TIMESTAMP '2011-12-19 12:00:00' >= d.start AND TIMESTAMP '2011-12-19 12:00:00' < d.\"end\") OR (TIMESTAMP '2011-12-19 15:00:00' > d.start AND TIMESTAMP '2011-12-19 15:00:00' <= d.\"end\") OR (d.start BETWEEN TIMESTAMP '2011-12-19 12:00:00' AND TIMESTAMP '2011-12-19 15:00:00' AND d.\"end\" BETWEEN TIMESTAMP '2011-12-19 12:00:00' AND TIMESTAMP '2011-12-19 15:00:00');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.076, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "duration" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_351", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ct.c_id, bt.start_time::date AS date, trip_counts.trip_count, SUM(CASE WHEN tc.duration = 'Single' AND trip_counts.trip_count = 1 THEN tc.cost WHEN tc.duration = 'Single' AND trip_counts.trip_count = 2 THEN tc.cost * 2 ELSE 0 END) + SUM(CASE WHEN tc.duration = 'Day' AND trip_counts.trip_count >= 3 THEN tc.cost ELSE 0 END) AS total_cost FROM customertrip ct JOIN bustrip bt ON ct.b_id = bt.b_id JOIN ticketcosts tc ON tc.duration IN ('Single', 'Day') JOIN (SELECT b_id, start_time::date AS tr", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"trip_counts.trip_count\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...LAIN SELECT ct.c_id, bt.start_time::date AS date, trip_count... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'b_id' is ambiguous \u2014 exists in tables: customertrip, bustrip", + "taxonomy_category": "semantic", + "context": "b_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "logical_grouping_error", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.249, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bustrip", + "customertrip", + "ticketcosts" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_352", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CONCAT(EXTRACT(HOUR FROM description), ' hours, ', EXTRACT(MINUTE FROM description), ' minutes, ', EXTRACT(SECOND FROM description), ' seconds') FROM backup_colour", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "backup_colour" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_353", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE `lessonschedule` (`record_id` SMALLINT NOT NULL, `student_id` SMALLINT, `lesson_date_time` TIMESTAMP NOT NULL, PRIMARY KEY (`record_id`, `student_id`, `lesson_date_time`), CONSTRAINT `fk_record` FOREIGN KEY (`record_id`) REFERENCES `record`(`id`), CONSTRAINT `fk_student` FOREIGN KEY (`student_id`) REFERENCES `student`(`id`));", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"`\" | LINE 1: CREATE TABLE `lessonschedule` (`record_id` SMALLINT NOT NULL... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_354", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE \"member_privileges\" ADD CONSTRAINT \"member_fk\" FOREIGN KEY REFERENCES \"member\"(\"member_id\");", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"REFERENCES\" | LINE 1: ...rivileges\" ADD CONSTRAINT \"member_fk\" FOREIGN KEY REFERENCES... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "member", + "member_privileges" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_355", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE hero_event (event_id SERIAL PRIMARY KEY, superhero TEXT NOT NULL, event_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIME);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"event_date\" is of type timestamp without time zone but default expression is of type time with time zone | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "hero_event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_356", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE superhero ALTER COLUMN description TYPE JSON SET NOT NULL SET DEFAULT '{}';", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SET\" | LINE 1: ...ABLE superhero ALTER COLUMN description TYPE JSON SET NOT NU... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_357", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT REGEXP_REPLACE(first_name, '(\\w)\\w', '\\1*') AS masked_first_name, REGEXP_REPLACE(last_name, '(\\w)\\w', '\\1*') AS masked_last_name FROM member", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "member" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_358", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.\"event_id\", b.\"amount\", b.\"link_to_member\", \"link_to_event\" FROM event AS b JOIN budget AS b ON b.\"event_id\" = b.\"link_to_event\" LEFT JOIN attendance AS b ON b.\"event_id\" = b.\"link_to_event\" ORDER BY b.\"event_id\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "table name \"b\" specified more than once", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42712" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'link_to_event' is ambiguous \u2014 exists in tables: attendance, budget", + "taxonomy_category": "semantic", + "context": "link_to_event", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_unknown_error", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0833, + "pattern_signature": "SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_359", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE FUNCTION check_alignment(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "unterminated dollar-quoted string at or near \"$$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END\" | LINE 1: ...ent(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN R... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_error", + "message": "Error tokenizing 'alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' EN'", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_error" + ] + }, + { + "instance_id": "PostgreSQL_360", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE \"atom_hierarchy\" AS (SELECT \"atom_id\", \"atom_id2\", \"bond_id\", 1 AS \"level\" FROM connected WHERE \"atom_id\" = 'TR007_8' UNION ALL SELECT c.\"atom_id\", c.\"atom_id2\", c.\"bond_id\", ah.\"level\" + 1 FROM connected AS c JOIN atom_hierarchy AS ah ON c.\"atom_id\" = ah.\"atom_id2\") SELECT \"atom_id\", \"atom_id2\", \"bond_id\", \"level\" FROM atom_hierarchy ORDER BY \"level\" NULLS FIRST, \"atom_id\" NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom_hierarchy", + "connected" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_361", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MaxHeightCTE\" AS (SELECT \"alignment_id\", \"publisher_id\", MAX(\"height_cm\") AS \"max_height\" FROM superhero GROUP BY \"alignment_id\", \"publisher_id\"), \"JoinedCTE\" AS (SELECT s.\"id\", s.\"superhero_name\", s.\"alignment_id\", s.\"publisher_id\", s.\"height_cm\", s.\"hair_colour_id\" FROM superhero AS s JOIN maxheightcte AS m ON s.\"alignment_id\" = m.\"alignment_id\" AND s.\"publisher_id\" = m.\"publisher_id\" AND s.\"height_cm\" = m.\"max_height\") SELECT \"alignment_id\", \"publisher_id\", SUM(\"hair_colour_id\") AS \"tot", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"maxheightcte\" does not exist | LINE 1: ..._cm\", s.\"hair_colour_id\" FROM superhero AS s JOIN maxheightc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "joinedcte", + "maxheightcte", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_362", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_bonds AS (\n SELECT a.\"atom_id\", a.\"molecule_id\", a.\"element\",\n STRING_AGG(c.\"bond_id\", ',' ORDER BY c.\"bond_id\" NULLS FIRST) AS connected_bonds\n FROM atom AS a\n LEFT JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n GROUP BY a.\"atom_id\", a.\"molecule_id\", a.\"element\"\n),\nmolecule_stats AS (\n SELECT m.\"molecule_id\", m.\"label\",\n COUNT(a.\"atom_id\") OVER (PARTITION BY m.\"molecule_id\") AS atom_count,\n ROW_NUMBER() OVER (PARTITION BY m.\"molecule_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_bonds", + "bond", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_363", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_year NUMERIC;\nv_week NUMERIC;\nv_home_team_wins NUMERIC;\nv_away_team_wins NUMERIC;\nv_draws NUMERIC;\nv_total_matches NUMERIC;\nBEGIN\nSELECT EXTRACT(YEAR\n FROM TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')),\n TO_CHAR(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'IW'),\n SUM(CASE\n WHEN \"home_team_goal\" > \"away_team_goal\" THEN 1\n ELSE 0\n END),\n SUM(CASE\n WHEN \"home_team_goal\" < \"away_team_goal\" THEN 1\n", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 9 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_364", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT molecule_id, COUNT(*) AS atom_count, string_agg(element, ',' ORDER BY atom_id NULLS FIRST) AS elements\n FROM atom\n GROUP BY molecule_id\n),\nbond_hierarchy AS (\n WITH RECURSIVE hierarchy AS (\n SELECT bond_id, molecule_id, bond_type, 1 AS bond_depth, '/' || bond_id AS bond_path\n FROM bond\n WHERE bond_id LIKE '%\\_2\\_%' ESCAPE '\\'\n UNION ALL\n SELECT b.bond_id, b.molecule_id, b.bond_type, h.bond_depth + 1, \n h.bo", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.5135, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "hierarchy", + "molecule", + "molecule_json" + ], + "num_joins": 7, + "num_subqueries": 2, + "num_ctes": 4, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_365", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", 1 AS level, CAST(m.\"molecule_id\" AS VARCHAR(4000)) AS path\n FROM molecule AS m\n JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n WHERE a.\"element\" = 'cl'\n\n UNION ALL\n\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", mh.level + 1, mh.path || '->' || m.\"molecule_id\"\n FROM molecule_hierarchy AS mh\n JOIN connected AS c ON mh.\"atom_id\" = c.\"atom_id\"\n JOIN ", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"molecule_hierarchy\" column 6 has type character varying(4000) in non-recursive term but type character varying overall | LINE 3: ... m.\"label\", a.\"atom_id\", a.\"element\", 1 AS level, CAST(m.\"mo... | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.3458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy" + ], + "num_joins": 8, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_366", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_atoms AS (\n SELECT m.molecule_id, m.label, a.atom_id, a.element,\n ROW_NUMBER() OVER (PARTITION BY m.molecule_id ORDER BY a.atom_id NULLS FIRST) AS atom_seq\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.molecule_id = a.molecule_id\n),\nmolecule_bonds AS (\n SELECT b.molecule_id, b.bond_id, b.bond_type,\n c.atom_id AS source_atom, c.atom_id2 AS target_atom,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_ran", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2427, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_connections", + "bond", + "connected", + "molecule", + "molecule_atoms", + "molecule_bonds" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_367", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_stats AS (SELECT \"m\".\"date\" AS \"match_date\", \"l\".\"name\" AS \"league_name\", \"c\".\"name\" AS \"country_name\", \"ht\".\"team_long_name\" AS \"home_team\", \"at\".\"team_long_name\" AS \"away_team\", \"m\".\"home_team_goal\" AS \"home_team_goals\", \"m\".\"away_team_goal\" AS \"away_team_goals\", RANK() OVER (PARTITION BY \"m\".\"league_id\", \"m\".\"season\" ORDER BY \"m\".\"home_team_goal\" + \"m\".\"away_team_goal\" DESC NULLS LAST) AS \"high_scoring_rank\" FROM match AS \"m\" INNER JOIN league AS \"l\" ON \"m\".\"league_id\" = \"l\".\"id\" I", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: ...ay_team_goals\" END) AS \"avg_goals_per_match\" FROM (SELECT \"m... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.376, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "country", + "league", + "match", + "match_stats", + "team", + "team_performance" + ], + "num_joins": 6, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_368", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_elements AS (SELECT a.atom_id, a.molecule_id, a.element, RANK() OVER (PARTITION BY a.molecule_id ORDER BY a.atom_id NULLS FIRST) AS element_rank FROM atom AS a), bond_details AS (SELECT b.bond_id, b.molecule_id, b.bond_type, DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_rank FROM bond AS b) SELECT ae.atom_id, ae.molecule_id, ae.element, c.bond_id, CASE WHEN bd.bond_type IS NULL THEN 'Unknown' ELSE bd.bond_type END AS bond_type FROM atom_elements ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_elements", + "bond", + "bond_details", + "connected", + "molecule" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_369", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"m\".\"id\", \"m\".\"home_team_api_id\", \"m\".\"away_team_api_id\", \"m\".\"home_team_goal\", \"m\".\"away_team_goal\", SUM(CASE WHEN \"m\".\"home_team_api_id\" = \"t\".\"team_api_id\" THEN \"m\".\"home_team_goal\" - \"m\".\"away_team_goal\" ELSE \"m\".\"away_team_goal\" - \"m\".\"home_team_goal\" END) OVER (PARTITION BY \"t\".\"team_api_id\" ORDER BY \"m\".\"id\" NULLS FIRST) AS \"goal_difference\" FROM match AS \"m\" INNER JOIN team AS \"t\" ON \"m\".\"home_team_api_id\" = \"t\".\"team_api_id\" OR \"m\".\"away_team_api_id\" = \"t\".\"team_api_id\" WHERE \"m\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "match", + "team" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_370", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT a.molecule_id, COUNT(a.atom_id) AS atom_count,\n STRING_AGG(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements\n FROM atom AS a\n GROUP BY a.molecule_id\n),\nbond_hierarchy AS (\n SELECT bond_id, molecule_id, bond_type,\n SUBSTRING(bond_id FROM '^[^_]+') AS molecule_prefix,\n CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOUBLE PRECISION) AS first_atom_num,\n CAST(SUBSTRING(bond_id FROM '[^_]+$') AS DOUBLE PRECISION)", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type integer: \"[^_]+\" | LINE 10: CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOU... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'molecule_id' is ambiguous \u2014 exists in tables: bond, molecule, atom", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "value_format_mismatch", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.4229, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "molecule", + "molecule_connectivity" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_371", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_molecule_id VARCHAR(512);\n v_label TEXT;\n v_atom_id VARCHAR(512);\n v_element TEXT;\n v_atom_id2 VARCHAR(512);\n v_bond_id VARCHAR(512);\n v_bond_type TEXT;\nBEGIN\n SELECT \"m\".\"molecule_id\",\n \"m\".\"label\",\n \"a\".\"atom_id\",\n \"a\".\"element\",\n \"c\".\"atom_id2\",\n \"b\".\"bond_id\",\n \"b\".\"bond_type\"\n FROM \"molecule\" \"m\"\n INNER JOIN \"atom\" \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\"\n INNER JOIN \"connected\"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 11 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_372", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_elements AS (\n SELECT a.atom_id, a.molecule_id, a.element,\n RANK() OVER (PARTITION BY a.molecule_id ORDER BY a.atom_id NULLS FIRST) AS element_rank\n FROM atom AS a\n),\nbond_details AS (\n SELECT b.bond_id, b.molecule_id, b.bond_type,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_rank\n FROM bond AS b\n),\nmolecule_connections AS (\n SELECT c.atom_id, c.atom_id2, c.bond_id,\n STRING_AGG(c.atom_id2, ',' ORDER ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "aggregate ORDER BY is not implemented for window functions | LINE 13: STRING_AGG(c.atom_id2, ',' ORDER BY c.atom_id2 NU... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_elements", + "bond", + "bond_details", + "connected", + "molecule", + "molecule_connections" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_373", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result\nFROM \"molecule\" m\nINNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\nINNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" INTO :result_variable", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "(sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'result_variable' | [SQL: EXPLAIN SELECT m.\"molecule_id\", | COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result | FROM \"molecule\" m | INNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\" | INNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\" | INNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\" | GROUP BY m.\"molecule_id\" INTO %(result_variable)s] | (Background on this error at: https://sqlalche.me/e/20/cd3x)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 7, Col: 29.\n a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" \u001b[4mINTO\u001b[0m :result_variable", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_unknown_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_374", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_data AS (SELECT a.atom_id, a.molecule_id, CASE WHEN a.element = 'cl' THEN UPPER(a.element) ELSE a.element END AS element FROM atom AS a), bond_data AS (SELECT b.bond_id, b.molecule_id, CASE WHEN b.bond_type = '-' THEN 'single' WHEN b.bond_type = '=' THEN 'double' WHEN b.bond_type = '#' THEN 'triple' ELSE b.bond_type END AS bond_type FROM bond AS b), molecule_elements AS (SELECT m.molecule_id, string_agg(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements FROM molecule AS m LEFT ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2417, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_data", + "bond", + "bond_data", + "molecule", + "molecule_elements" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_375", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS ( SELECT m.molecule_id, m.label, a.atom_id, a.element, CAST(NULL AS VARCHAR(512)) AS atom_id2, CAST(NULL AS VARCHAR(512)) AS bond_id, CAST(NULL AS TEXT) AS bond_type, 1 AS level, CAST(a.atom_id AS VARCHAR(4000)) AS path FROM molecule AS m JOIN atom AS a ON m.molecule_id = a.molecule_id UNION ALL SELECT h.molecule_id, h.label, h.atom_id, h.element, c.atom_id2, c.bond_id, b.bond_type, h.level + 1, h.path || '->' || c.atom_id2 FROM molecule_hierarchy AS h JOIN", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: ...SE WHEN rn = 3 THEN element END) AS element3 FROM (SELECT mo... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.5208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "pivoted_elements" + ], + "num_joins": 8, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_376", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\", m.\"label\", COUNT(DISTINCT a.\"atom_id\") AS atom_count, COUNT(DISTINCT b.\"bond_id\") AS bond_count\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n LEFT JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n LEFT JOIN bond AS b ON c.\"bond_id\" = b.\"bond_id\" AND b.\"molecule_id\" = m.\"molecule_id\"\n GROUP BY m.\"molecule_id\", m.\"label\"\n),\natom_details AS (\n SELECT a.\"molecule_id\", a.\"atom_id\", a.\"element\",\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3542, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_details", + "bond", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 7, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_377", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_pairs AS (\n SELECT\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM 1 FOR POSITION(',' IN pair_str) - 1))\n ELSE pair_str END AS mol_id1,\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM POSITION(',' IN pair_str) + 1))\n ELSE NULL END AS mol_id2\n FROM (\n SELECT 'TR427, TR430' AS pair_str\n UNION ALL\n SELECT 'TR427, TR431'\n UNION ALL\n ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "DISTINCT is not implemented for window functions | LINE 22: COUNT(DISTINCT b.\"bond_id\") OVER (PARTITION BY m.\"mo... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.3823, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pairs", + "molecule_stats" + ], + "num_joins": 5, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_378", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"m\".\"molecule_id\", \"m\".\"label\", \"a\".\"element\" FROM molecule AS \"m\" INNER JOIN atom AS \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\" ORDER BY \"m\".\"molecule_id\" NULLS FIRST, \"a\".\"atom_id2\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column a.atom_id2 does not exist | LINE 1: ...ecule_id\" ORDER BY \"m\".\"molecule_id\" NULLS FIRST, \"a\".\"atom_... | ^ | Perhaps you meant to reference the column \"a.atom_id\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_379", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\",\n COUNT(DISTINCT a.\"atom_id\") AS atom_count,\n COUNT(DISTINCT b.\"bond_id\") AS bond_count,\n string_agg(DISTINCT CASE WHEN a.\"element\" IS NULL THEN NULL WHEN ',' IS NULL THEN NULL ELSE a.\"element\" END, ',') AS elements\n FROM molecule AS m\n LEFT OUTER JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n LEFT OUTER JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n LEFT OUTER JOIN bond AS b ON c.\"bond_id\" = b", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column mp.chlorine does not exist | LINE 32: mp.chlorine, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.4594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pivot", + "molecule_stats" + ], + "num_joins": 9, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_380", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\", COUNT(a.\"atom_id\") AS atom_count,\n STRING_AGG(a.\"element\", ',' ORDER BY a.\"atom_id\" NULLS FIRST) AS elements\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n GROUP BY m.\"molecule_id\"\n),\nbond_stats AS (\n SELECT b.\"molecule_id\", COUNT(b.\"bond_id\") AS bond_count\n FROM bond AS b\n GROUP BY b.\"molecule_id\"\n)\nSELECT ms.\"molecule_id\", ms.atom_count AS \"total_atoms\", bs.bond_count,\n CASE W", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function round(double precision, integer) does not exist | LINE 14: CASE WHEN ms.atom_count > 0 THEN ROUND(CAST(bs.bond_c... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1896, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "bond_stats", + "molecule", + "molecule_stats" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_381", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"event_id\", e.\"event_name\", e.\"event_date\", e.\"type\",\n(SELECT MAX(CAST(column_value AS timestamp)) AS latest_event_date FROM (VALUES (e.\"event_date\")) AS value_table(column_value)\nWHERE column_value IS NOT NULL) AS latest_event_date FROM \"event\" e", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-VALUES-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "VALUES", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_382", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n TO_CHAR(type) AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 END) -\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = oldest_year THEN 1 END) AS year_difference\nFROM event,\n (\n SELECT\n MAX(EXTRACT(YEAR FROM event_date::timestamp)) AS recent_year,\n MIN(EXTRACT(YEAR FROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type), recent_year, oldest_year;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_char(text) does not exist | LINE 2: TO_CHAR(type) AS event_type, | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'format' missing for . Line 2, Col: 17.\n SELECT\n TO_CHAR(type\u001b[4m)\u001b[0m AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 EN\n\nRequired keyword: 'format' missing for . Line 12, Col: 22.\n ROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type\u001b[4m)\u001b[0m, recent_year, oldest_year;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_undefined_function", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "event" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_383", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*)\nFROM match m1\nWHERE EXISTS (\n SELECT 1\n FROM match m2\n WHERE m2.home_team_api_id = m1.away_team_api_id\n AND m2.away_team_api_id = m1.home_team_api_id\n)\nAND m1.home_team_api_id < m1.away_team_api_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0521, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_384", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_match_id BIGINT;\nv_match_date TEXT;\nv_home_team_goals BIGINT;\nv_away_team_goals BIGINT;\nv_home_team_name TEXT;\nv_away_team_name TEXT;\nv_league_name TEXT;\n\nBEGIN\nSELECT \"match\".\"id\",\n \"match\".\"date\",\n \"match\".\"home_team_goal\",\n \"match\".\"away_team_goal\",\n \"HomeTeam\".\"team_long_name\",\n \"AwayTeam\".\"team_long_name\",\n \"league\".\"name\"\nFROM \"match\"\nINNER JOIN \"team\" \"HomeTeam\" ON \"match\".\"home_team_api_id\" = \"HomeTeam\".\"team_api_id\"\nINNER JOIN \"team\" \"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 11 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_385", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_years AS (\n SELECT\n M.league_id,\n EXTRACT(YEAR FROM TO_DATE(M.date, 'YYYY-MM-DD HH24:MI:SS')) AS match_year,\n COUNT(*) AS year_count\n FROM match M\n WHERE M.date IS NOT NULL\n GROUP BY M.league_id, EXTRACT(YEAR FROM TO_DATE(M.date, 'YYYY-MM-DD HH24:MI:SS'))\n),\nleague_stats AS (\n SELECT\n L.id AS league_id,\n L.name AS league_name,\n C.name AS country_name,\n COUNT(DISTINCT M.id) AS total_matches\n FROM league L\n JOIN count", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "country", + "league", + "league_stats", + "match", + "match_years" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_386", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH temp AS\n (SELECT a.\"atom_id\",\n a.\"molecule_id\",\n ROW_NUMBER() OVER (PARTITION BY a.\"molecule_id\"\n ORDER BY a.\"atom_id\") - TO_DATE(REGEXP_SUBSTR(a.\"atom_id\", '\\d+$'), 'DD') AS grp\n FROM \"atom\" a), temp2 AS\n (SELECT t.\"atom_id\",\n t.\"molecule_id\",\n COUNT(*) OVER (PARTITION BY t.\"molecule_id\", t.grp) AS cnt\n FROM temp t)\nSELECT t2.\"atom_id\",\n t2.\"molecule_id\"\nFROM temp2 t2\nWHERE t2.cnt >= 3\nORDER BY t2.\"molecule_id\",\n ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(text, unknown) does not exist | LINE 5: ... ORDER BY a.\"atom_id\") - TO_DATE(REGEXP_SUB... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "temp", + "temp2" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_387", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n\n set_a (molecule_id, element_count) AS (\n SELECT molecule_id, COUNT(DISTINCT element)\n FROM atom\n GROUP BY molecule_id\n HAVING COUNT(DISTINCT element) > 1\n ),\n set_b (molecule_id, element_count) AS (\n SELECT m.molecule_id, COUNT(DISTINCT a.element)\n FROM molecule m\n JOIN atom a ON m.molecule_id = a.molecule_id\n WHERE m.label IS NOT NULL\n GROUP BY m.molecule_id\n ),\n\n unique_a (molecule_id, element_count, rn, densi", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"molecule_hierarchy\" does not exist | LINE 49: JOIN molecule_hierarchy h ON m.molecule_id = h.molec... | ^ | There is a WITH item named \"molecule_hierarchy\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'bond_id' is ambiguous \u2014 exists in tables: bond, connected", + "taxonomy_category": "semantic", + "context": "bond_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'element_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "element_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.5177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "set_a", + "set_b", + "unique_a", + "unique_b" + ], + "num_joins": 6, + "num_subqueries": 2, + "num_ctes": 5, + "num_aggregations": 12 + } + }, + { + "instance_id": "PostgreSQL_388", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule_id\",\n\n (SELECT \"element\"\n FROM \"atom\"\n WHERE \"molecule_id\" = \"atom\".\"molecule_id\") AS \"elements\"\nFROM \"atom\"\nGROUP BY \"molecule_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_389", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT \"molecule_id\",\n STRING_AGG(DISTINCT \"atom_id\", ',') OVER (PARTITION BY \"molecule_id\" ORDER BY \"atom_id\") AS \"atom_ids\"\nFROM \"atom\"\nWHERE \"molecule_id\" = 'TR011'\nGROUP BY \"molecule_id\",\n \"atom_id\"", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "DISTINCT is not implemented for window functions | LINE 2: STRING_AGG(DISTINCT \"atom_id\", ',') OVER (PA... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_390", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS\n (SELECT \"id\",\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_date,\n TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'fmDay', 'English') AS day_of_week,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_start_time,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '2 HOUR' AS match_end_time\n FROM \"match\")\nSELECT m.*,\n ROUND(GREATEST(LEAST(m.match_end_time, m.match_date + INTERVAL '17:00:00' HOUR TO SECOND) - GREATEST(m.ma", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_char(date, unknown, unknown) does not exist | LINE 4: TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'DBA_VIEWS' does not exist in schema", + "taxonomy_category": "semantic", + "context": "DBA_VIEWS", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_undefined_function", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "dba_views", + "match", + "match_dates" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_391", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH tiers AS (SELECT 1 as tier_start, 4 as tier_end, 20 as rate UNION SELECT 5, 8, 50 UNION SELECT 10, 12, 100), input_qty AS (SELECT height_cm as quantity FROM superhero WHERE id = 1) SELECT SUM(CASE WHEN quantity >= tier_start THEN (LEAST(quantity, tier_end) - tier_start + 1) * rate ELSE 0 END) as total FROM tiers CROSS JOIN input_qty", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "input_qty", + "superhero", + "tiers" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_392", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"home_team_api_id\" AS \"team_api_id\",\n \"start_date\",\n \"end_date\",\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (consecutive_wins+) DEFINE consecutive_wins AS \"league_id\" = 'EUROPEAN_FOOTBALL_2')", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"BY\" | LINE 5: FROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\" | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'match_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "match_count", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 6, Col: 38.\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n \u001b[4mORDER BY\u001b[0m \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\n\nInvalid expression / Unexpected token. Line 6, Col: 54.\n OM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" \u001b[4mMEASURES\u001b[0m FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (conse", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_393", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT\n molecule_id,\n COUNT(*) AS atom_count,\n (array_agg(element ORDER BY atom_id))[1] AS first_element,\n (array_agg(element ORDER BY atom_id DESC))[1] AS last_element\n FROM \"atom\"\n GROUP BY molecule_id\n),\nranked_atoms AS (\n SELECT\n a.\"atom_id\",\n a.\"molecule_id\",\n a.\"element\",\n DENSE_RANK() OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"atom_id\") AS atom_rank,\n stats.atom_count,\n stats.first_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1583, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "filtered_atoms", + "ranked_atoms" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_394", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE split_date AS (\n SELECT id,\n date,\n 1 AS level,\n SPLIT_PART(date, ' ', 1) AS date_part\n FROM team_attributes\n\n UNION ALL\n\n SELECT s.id,\n s.date,\n s.level + 1,\n SPLIT_PART(s.date, ' ', s.level + 1) AS date_part\n FROM split_date s\n WHERE s.level < regexp_count(s.date, ' ') + 1\n AND s.date_part != ''\n)\nSELECT id, date_part\nFROM split_date", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_count(text, unknown) does not exist | LINE 15: WHERE s.level < regexp_count(s.date, ' ') + 1 | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0844, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "split_date", + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_395", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT REGEXP_REPLACE(cdscode, '\\.[^.]*$', '') AS output\nFROM schools\nWHERE cdscode = '1110.400000.8001382'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_396", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n m.\"molecule_id\" AS root_molecule_id,\n 1 AS hierarchy_level,\n '/' || m.\"molecule_id\" AS molecule_path\n FROM \"molecule\" m\n JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\n JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\n JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\n WHERE b.\"bond_type\" = '-'\n\n UNION ALL\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n ", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"month_generator\" column 1 has type date in non-recursive term but type timestamp without time zone overall | LINE 33: TO_DATE('01/01/2018', 'MM/DD/YYYY') AS month_start_d... | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.4427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "molecule_months", + "month_generator" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_397", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH tbl AS\n (SELECT TO_DATE('12.01.2023', 'dd.mm.yyyy') AS act_date\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('12.02.2023', 'dd.mm.yyyy')\n FROM (S", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"g.rn_1\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 64: WHEN g.rn_1 = g.rn_2 THEN | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.4104, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "grid", + "molecule", + "molecule_activity", + "t2", + "tbl" + ], + "num_joins": 2, + "num_subqueries": 19, + "num_ctes": 4, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_398", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"credits\" AS (\n SELECT\n 5001 AS \"ID\",\n 12 AS \"ARTCRED\",\n 7.5 AS \"BIZCRED\",\n 12 AS \"HUMCRED\",\n 14 AS \"NATCRED\",\n 11 AS \"TEKCRED\",\n 9 AS \"GENCRED\",\n TO_DATE('01.01.2010', 'dd.mm.yyyy') AS \"EFFECTIVE_DATE\"\n UNION ALL\n SELECT\n 5001 AS \"ID\",\n 15 AS \"ARTCRED\",\n 9 AS \"BIZCRED\",\n 14 AS \"HUMCRED\",\n 16 AS \"NATCRED\",\n 13 AS \"TEKCRED\",\n 11 AS \"GENCRED\",\n TO_DATE('01.01.2020', 'dd.mm.", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "credits", + "grp_choices", + "latest_credits" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_399", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\"\nFROM\n (SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\",\n ROW_NUMBER() OVER (PARTITION BY \"team_api_id\"\n ORDER BY TO_NUMBER(\"date\") DESC) AS seq\n FROM \"team_attributes\")\nWHERE seq = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 5: (SELECT \"team_api_id\", | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_400", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH player_data AS (\n SELECT\n p.player_api_id AS player_id,\n 'name' AS attribute_type,\n p.player_name AS attribute_value\n FROM player p\n WHERE p.player_api_id IS NOT NULL\n UNION ALL\n SELECT\n pa.player_api_id AS player_id,\n 'rating' AS attribute_type,\n CAST(pa.overall_rating AS TEXT) AS attribute_value\n FROM player_attributes pa\n WHERE pa.date = (\n SELECT MAX(date)\n FROM player_attributes\n WHERE player_api_id = p", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2698, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "player", + "player_attributes", + "player_data", + "player_stats" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_401", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MY_TABLE\" AS\n (SELECT '1111' AS \"TECHNICAL_ID\",\n 'NOTIONALCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '1111' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n 'FWDNOTLCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_I", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"CTE\" does not exist | LINE 53: FROM \"CTE\" C | ^ | There is a WITH item named \"CTE\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.125, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "map_recrf_asset_type", + "my_table" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_402", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS (\n SELECT m.country_id,\n m.date,\n m.league_id,\n m.season,\n DENSE_RANK() OVER (PARTITION BY m.country_id ORDER BY m.date DESC) AS match_rank\n FROM \"match\" m\n WHERE m.date IS NOT NULL\n),\ncountry_stats AS (\n SELECT c.id AS country_id,\n c.name AS country_name,\n COUNT(DISTINCT m.league_id) AS league_count,\n COUNT(DISTINCT m.season) AS season_count\n FROM \"country\" c\n LEFT JOIN \"match\" m ON c.id ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2708, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "country", + "country_stats", + "league", + "match", + "match_dates", + "match_summary" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 10 + } + }, + { + "instance_id": "PostgreSQL_403", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT T.\"team_long_name\",\n T.\"team_short_name\",\n TA.\"buildUpPlaySpeed\",\n TA.\"buildUpPlaySpeedClass\",\n TA.\"chanceCreationShooting\",\n TA.\"chanceCreationShootingClass\",\n TA.\"defencePressure\",\n TA.\"defencePressureClass\"\nFROM \"team\" T\nINNER JOIN \"team_attributes\" TA ON T.\"team_api_id\" = TA.\"team_api_id\"\nWHERE TA.\"date\" = '2013-09-20 00:00:00'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column ta.buildUpPlaySpeed does not exist | LINE 3: TA.\"buildUpPlaySpeed\", | ^ | Perhaps you meant to reference the column \"ta.buildupplayspeed\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_404", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"valid_from\",\n \"valid_until\",\n \"count\"\nFROM\n (SELECT \"dt\" AS \"valid_from\",\n LEAD(\"dt\") OVER (\n ORDER BY \"dt\") - INTERVAL '1' SECOND AS \"valid_until\",\n SUM(\"count\" * \"type\") OVER (\n ORDER BY \"dt\") AS \"count\"\n FROM\n (SELECT \"valid_from\",\n \"valid_until\" + INTERVAL '1 DAY' AS \"valid_until\",\n 1 AS \"count\"\n FROM\n (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 15: (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"vali... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2885, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_405", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH school_data AS (\n SELECT\n s.cdscode AS \"pk\",\n CASE\n WHEN s.charter = 1 THEN 'Charter'\n WHEN s.magnet = 1 THEN 'Magnet'\n ELSE 'Regular'\n END AS \"col2\",\n SUBSTRING(s.county FROM 1 FOR POSITION(' ' IN s.county) - 1) AS \"col3\",\n TO_TIMESTAMP(TO_CHAR(s.lastupdate, 'YYYY/MM/DD') || ' ' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode), 24) AS TEXT), 2, '0') || ':' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode) * 7, 60) AS TEXT), ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: timestamp with time zone < text | LINE 26: AND sd.\"col4\" < TO_CHAR(TO_TIMESTAMP('2024/09/04 00:05',... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "aggregated_data", + "filtered_data", + "school_data", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_406", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"data\" AS\n (SELECT 101 AS \"id\",\n 'A' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 20 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'C' AS \"type\",\n 30 AS \"part\"\n UNION A", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1302, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "data", + "w_cnt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_407", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"columns\" (\"column_name\") AS\n (SELECT 'cdscode'\n UNION ALL SELECT 'statustype'\n UNION ALL SELECT 'school'),\n \"column_exists\" (\"column_name\",\n \"column_exists\") AS\n (SELECT c.\"column_name\",\n COALESCE(a.attname, 'NO')\n FROM \"columns\" c\n LEFT OUTER JOIN pg_attribute a ON (a.attrelid = 'schools'::regclass\n AND c.\"column_name\" = a.attname))\nSELECT *\nFROM \"column_exists\"\nPIVOT (MAX(\"column_exists\")\n FOR \"column_", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 14: PIVOT (MAX(\"column_exists\") | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1604, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "column_exists", + "columns", + "pg_attribute" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_408", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH string1_tab AS (\n SELECT REGEXP_SUBSTR('24,36,78,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('24,36,78,98') - LENGTH(REPLACE('24,36,78,98', ',', '')) + 1)\n),\nstring2_tab AS (\n SELECT REGEXP_SUBSTR('25,36,88,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('25,36,88,98') - LENGTH(REPLACE('25,36,88,98', ',', '')) + 1)\n),\nstring1_parsed AS (\n S", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(unknown, unknown, integer, integer) does not exist | LINE 2: SELECT REGEXP_SUBSTR('24,36,78,98', '[^,]+', 1, generate... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "common_values", + "string1_parsed", + "string1_tab", + "string2_parsed", + "string2_tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 5, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_409", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH t AS\n (SELECT \"date\",\n \"match_api_id\" AS code,\n CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')) AS duration,\n COUNT(*) OVER (PARTITION BY DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')), \"match_api_id\", CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'))) AS cnt,\n MIN(CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'))) OVER (PARTITION BY DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')), \"match_api_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "t" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_410", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n GREATEST(DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 day') + INTERVAL '1 day' + (m.months * INTERVAL '1 month'), CURRENT_DATE) AS bond_formation_date\nFROM \"bond\" b\nJOIN\n (SELECT generate_series(0, 5) AS months) m\nGROUP BY b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n m.months\nHAVING b.\"molecule_id\" = 'TR011'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 8: GROUP BY b.\"bond_id\", | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bond" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_411", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH team_speed_stats AS (\n SELECT\n team_api_id,\n date,\n buildupplayspeed,\n ROW_NUMBER() OVER (PARTITION BY team_api_id ORDER BY date DESC) as rn,\n AVG(buildupplayspeed) OVER (PARTITION BY buildupplayspeedclass) as class_avg_speed\n FROM team_attributes\n),\nmatch_details AS (\n SELECT\n m.id,\n m.date,\n m.home_team_api_id,\n m.away_team_api_id,\n m.home_team_goal,\n m.away_team_goal,\n t.team_long_name as home_te", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text >= date | LINE 34: WHERE m.date BETWEEN TO_DATE('2015-01-01', 'YYYY-MM-DD')... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_undefined_function", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.499, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "match_details", + "team", + "team_attributes", + "team_speed_stats" + ], + "num_joins": 5, + "num_subqueries": 4, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_412", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with lose_agg as\n (select team_api_id,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2011 then defencepressure\n end) as lose_5,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2012 then defencepressure\n end) as lose_10\n from team_attributes\n group by team_api_id),\n profit_agg as\n (select team_api_id,\n sum(case\n when extract(ye", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"select\" | LINE 29: select extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:S... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 29, Col: 6.\n join profit_agg p on l.team_api_id = p.team_api_id\norder by coalesce(p.team_api_id, l.team_api_id)\n\u001b[4mselect\u001b[0m extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) as year\nfrom team_attributes\nwhere date =", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "lose_agg", + "profit_agg", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_413", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT \"id\", \"date\", \"home_team_goal\", LAG(\"home_team_goal\") OVER (ORDER BY \"date\" DESC) AS prev_home_goal FROM \"match\" WHERE \"date\" <= '2024-02-26'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_414", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT \"atom_id\",\n \"bond_id_1\",\n \"bond_id_2\",\n \"bond_id_3\"\nFROM (\n SELECT \"atom_id\", \"bond_id\",\n CASE WHEN \"bond_id\" = 1 THEN \"bond_id\" END AS \"bond_id_1\",\n CASE WHEN \"bond_id\" = 2 THEN \"bond_id\" END AS \"bond_id_2\",\n CASE WHEN \"bond_id\" = 3 THEN \"bond_id\" END AS \"bond_id_3\"\n FROM \"connected\"\n) AS pivoted_data\nORDER BY \"atom_id\"", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text = integer | LINE 7: CASE WHEN \"bond_id\" = 1 THEN \"bond_id\" END AS \"bo... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "connected" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_415", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH OrderedCategories AS (\n SELECT\n SUM(spent) AS category_total,\n category\n FROM budget\n GROUP BY category\n ORDER BY category DESC\n),\nCumulative AS (\n SELECT category_total, category,\n SUM(category_total) OVER (ORDER BY category DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_sum\n FROM OrderedCategories\n)\nSELECT category_total, category\nFROM Cumulative\nWHERE cumulative_sum <= 800\nAND (cumulative_sum - category_total) < 800", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "budget", + "cumulative", + "orderedcategories" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_416", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT player_id,\n MAX(overall_rating) AS overall_rating,\n potential,\n preferred_foot,\n attacking_work_rate\nFROM (SELECT player_api_id AS player_id, overall_rating, potential, preferred_foot, attacking_work_rate, row_number() OVER (PARTITION BY player_api_id ORDER BY date DESC) as rn FROM player_attributes WHERE date <= '2015-12-31') subquery\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"subquery.player_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT player_id, | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_417", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_name\"))\n ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZE = 2) AS result\nFROM \"team\"\nWHERE \"id\" IN\n (SELECT \"id\"\n FROM \"team_attributes\"\n WHERE \"date\" IS NULL)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"INDENT\" | LINE 2: ... ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 1, Col: 39.\n SELECT XMLSERIALIZE(DOCUMENT \u001b[4mXMLELEMENT\u001b[0m(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long\n\nInvalid expression / Unexpected token. Line 1, Col: 40.\n SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT\u001b[4m(\u001b[0mNAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_418", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_times AS (\n SELECT\n \"date\",\n \"match_api_id\",\n EXTRACT(HOUR FROM CAST(\"date\" AS TIMESTAMP)) +\n EXTRACT(MINUTE FROM CAST(\"date\" AS TIMESTAMP))/60 AS hour_of_day,\n TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'YYYY-MM-DD') AS match_date_str\n FROM \"match\"\n),\ntarget_times AS (\n SELECT 8 AS target_hour\n UNION ALL\n SELECT 20 AS target_hour\n),\ndistance_calc AS (\n SELECT\n mt.\"date\",\n mt.\"match_api_id\",\n mt.match_date_str,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1438, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distance_calc", + "match", + "match_times", + "target_times" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_419", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT REPLACE(SUBSTR(date, 1, INSTR(date, '.', -1) - 1), '.') || SUBSTR(date, INSTR(date, '.', -1)) AS \"updated_value\"\nFROM team_attributes\nWHERE date LIKE '%.%'", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function instr(text, unknown, integer) does not exist | LINE 1: EXPLAIN SELECT REPLACE(SUBSTR(date, 1, INSTR(date, '.', -1) ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_420", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") AS atom_count,\n MIN(a.\"element\") AS first_element\n FROM \"molecule\" m\n LEFT JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\n GROUP BY m.\"molecule_id\"\n),\natom_details AS (\n SELECT a.\"molecule_id\",\n a.\"atom_id\",\n ROW_NUMBER() OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"atom_id\") AS atom_seq,\n LEAD(a.\"atom_id\") OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"ato", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_details", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 5, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_421", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"my_table\" AS\n (SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A1' AS \"file_\",\n 5 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A2' AS \"file_\",\n 3 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A3' AS \"file_\",\n 2 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A4' AS \"file_\",\n ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"BY\" | LINE 37: FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\" | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 38, Col: 46.\n ize\"\n FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n \u001b[4mORDER BY\u001b[0m \"rn\" MEASURES MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((\n\nInvalid expression / Unexpected token. Line 38, Col: 60.\n my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n ORDER BY \"rn\" \u001b[4mMEASURES\u001b[0m MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((same_nif* nif)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "my_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_422", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE \"a\" (\"test\") AS\n (SELECT 'Jack|Sparrow|17-09-16|DY7009|Address at some where|details '\n UNION ALL SELECT 'Jack|Sparrow|17-09-16|DY7009|'\n UNION ALL SELECT 'Jack|Sparrow|17-09-16'\n UNION ALL SELECT \"test\" || '|MoreData'\n FROM \"a\")\nSELECT \"test\",\n REGEXP_SUBSTR(\"test\", '([^|]+\\|?){1,5}') AS \"res\"\nFROM \"a\"", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(text, unknown) does not exist | LINE 8: REGEXP_SUBSTR(\"test\", '([^|]+\\|?){1,5}') AS \"res\" | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "a" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_423", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM \"event\"\n WHERE \"status\"::text <> 'Closed'\n ORDER BY \"event_date\"\n OFFSET 10 ROWS FETCH FIRST 5 ROWS ONLY\n FOR UPDATE SKIP LOCKED;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-OFFSET-LOCKING", + "clauses_present": [ + "FROM", + "LOCKING", + "OFFSET", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_424", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n \"molecule\".\"molecule_id\",\n MIN(\"atom\".\"atom_id\") AS \"first_atom_id\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\";", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"molecule.molecule_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 2: \"molecule\".\"molecule_id\", | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_425", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule\".\"molecule_id\",\n \"molecule\".\"label\",\n \"atom\".\"atom_id\",\n \"atom\".\"element\",\n \"bond\".\"bond_id\",\n \"bond\".\"bond_type\",\n \"connected\".\"atom_id2\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\"\nINNER JOIN \"connected\" ON \"atom\".\"atom_id\" = \"connected\".\"atom_id\"\nINNER JOIN \"bond\" ON \"connected\".\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \"connected\".\"atom_id2\";", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\"connected\"\" | LINE 14: \"connected\".\"atom_id2\"; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 14, Col: 20.\n .\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \u001b[4m\"connected\"\u001b[0m.\"atom_id2\";", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_426", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE \"frpm\" AS target\n \"Charter School (Y/N)\" = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Eligible Free (K-12)\" >= 0.5\n ) AS source\n WHERE target.\"cdscode\" = source.\"cdscode\";", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\"Charter School (Y/N)\"\" | LINE 2: \"Charter School (Y/N)\" = 1000 | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 26.\n UPDATE \"frpm\" AS target\n \u001b[4m\"Charter School (Y/N)\"\u001b[0m = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Elig", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_427", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n player_fifa_api_id as id,\n MIN(date::date) AS first_date,\n MAX(date::date) AS last_date\n FROM player_attributes\n GROUP BY player_fifa_api_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_428", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.molecule_id AS ID, COUNT(a.atom_id) AS QTY, COUNT(b.bond_id) AS VALUE FROM molecule m LEFT JOIN atom a ON m.molecule_id = a.molecule_id LEFT JOIN bond b ON m.molecule_id = b.molecule_id GROUP BY m.molecule_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "molecule" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_429", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_atoms_recursive AS (\n SELECT \"molecule_id\", 1 AS atom_number, atom_count\n FROM (\n SELECT \"molecule_id\", COUNT(\"atom_id\") AS atom_count\n FROM \"atom\"\n GROUP BY \"molecule_id\"\n ) base\n UNION ALL\n SELECT mar.\"molecule_id\", mar.atom_number + 1, mar.atom_count\n FROM molecule_atoms_recursive mar\n\n)\nSELECT \"molecule_id\", atom_number\nFROM molecule_atoms_recursive;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1521, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "UNION", + "WITH" + ], + "tables": [ + "atom", + "molecule_atoms_recursive" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_430", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE replacements (molecule_id, current_label, current_spos) AS (\n SELECT molecule_id,\n label::text,\n strpos(label::text, '+')\n FROM molecule\n UNION ALL\n SELECT r.molecule_id,\n overlay(r.current_label placing '-' from r.current_spos for 1),\n strpos(overlay(r.current_label placing '-' from r.current_spos for 1), '+')\n FROM replacements r\n WHERE r.current_spos > 0\nSELECT molecule_id,\n current_label AS label\nFROM replacements\n\nWHERE current_spos", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELECT\" | LINE 12: SELECT molecule_id, | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "molecule", + "replacements" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_431", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.\"cds\",\n s.\"sname\"::text,\n (SELECT json_agg(json_build_object(\n 'enroll12', t.\"enroll12\"::text,\n 'NumTstTakr', t.\"numtsttakr\"::text,\n 'AvgScrRead', t.\"avgscrread\"::text,\n 'AvgScrMath', t.\"avgscrmath\"::text,\n 'AvgScrWrite', t.\"avgscrwrite\"::text\n ) ORDER BY t.\"enroll12\" DESC)\n\n WHERE t.\"rtype\"::text = 'S'\n AND t.\"cds\" = s.\"cds\"\n )\nFROM \"satscores\" s\nWHERE s.\"rtype\"::text = 'S';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"t\" | LINE 4: 'enroll12', t.\"enroll12\"::text, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_432", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE Match_Recursive AS (\n SELECT id, country_id, date, home_team_goal, away_team_goal, 1 as lvl\n FROM match\n UNION ALL\n SELECT m.id, m.country_id, m.date, m.home_team_goal, m.away_team_goal, mr.lvl + 1\n FROM match m\n JOIN Match_Recursive mr ON m.country_id = mr.country_id\n WHERE mr.lvl < 2\n)\nSELECT\n json_build_object(\n 'country_id' || mr.country_id,\n json_agg(\n json_build_object(\n 'date', mr.date,\n 'home_team_goal', mr.home_team_goal,\n 'away_tea", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "match", + "match_recursive" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_433", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT M.\"id\", MAX(M.\"date\"), M.\"overall_rating\" FROM player_rate AS M GROUP BY M.\"id\", MAX(M.\"date\"), M.\"overall_rating\"", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in GROUP BY | LINE 1: ...ll_rating\" FROM player_rate AS M GROUP BY M.\"id\", MAX(M.\"dat... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "player_rate" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_434", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "SELECT guid FROM login WHERE (login, name) IN (SELECT login, name FROM login GROUP BY login, name HAVING COUNT(*) > 1) AND NOT guid IN (SELECT room_guid FROM groups)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "groups", + "login" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_435", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "select \"element\", \"record\"\n from \"frpm_record\"\n union all\n\n select\n substring(\"element\", 1, position('_' in \"element\") - 1) ||'_rate' as element,\n max(case when substring(\"element\", -1) = '2' then \"record\" end) /\n max(case when substring(\"element\", -1) = '1' then \"record\" end) as \"record\"\n from \"frpm_record\"\n group by substring(\"element\", 1, position('_' in \"element\") - 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP-UNION", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "UNION" + ], + "tables": [ + "frpm_record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_436", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH member_data AS (\n SELECT\n member_id,\n member_name,\n ROW_NUMBER() OVER (PARTITION BY member_id ORDER BY member_name) AS rn\n FROM \"member_trunc\"\n),\ntokenized_members AS (\n SELECT\n a.\"link_to_event\",\n generate_series(1, length(a.\"link_to_member\") - length(replace(a.\"link_to_member\", '|', '')) + 1) AS position,\n split_part(a.\"link_to_member\", '|', generate_series(1, length(a.\"link_to_member\") - length(replace(a.\"link_to_member\", '|', '')) + 1))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1615, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance_trunc", + "member_data", + "member_names", + "member_trunc", + "tokenized_members" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_437", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT a.atom_id, COUNT(c.atom_id2) as connection_count FROM atom a LEFT JOIN connected c ON a.atom_id = c.atom_id WHERE a.atom_id IN (SELECT atom_id FROM test WHERE atom_id LIKE 'TR%') GROUP BY a.atom_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "atom", + "connected", + "test" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_438", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM bl.transact_dt_tm) as year, bl.bond_type, COUNT(*) as bond_count FROM bond_list bl RIGHT JOIN bond_ref br ON bl.bond_type = br.bond_type GROUP BY EXTRACT(YEAR FROM bl.transact_dt_tm), bl.bond_type ORDER BY year, br.bond_seq", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"br.bond_seq\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...M bl.transact_dt_tm), bl.bond_type ORDER BY year, br.bond_se... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "bond_list", + "bond_ref" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_439", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT header || ': ' || name AS grouped_countries\nFROM (\n SELECT\n MAX(CASE WHEN name LIKE 'Country Group%' THEN name END)\n OVER (ORDER BY id) AS header,\n id,\n name\n FROM country\n)\nWHERE name NOT LIKE 'Country Group%'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 2: FROM ( | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "country" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_440", + "db_id": "toxicology", + "category": "Management", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";UPDATE record SET r1 = uuid_generate_v4(), r2 = uuid_generate_v4();", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_441", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS pgcrypto;\nSELECT digest(product_id::bytea, 'sha1') AS hash_value, length(digest(product_id::bytea, 'sha1')) AS hash_length\nFROM products;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_442", + "db_id": "toxicology", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION FIND_TEST_TABLE_COLUMN(\n IN_COLUMN1 VARCHAR,\n IN_COLUMN2 VARCHAR,\n IN_COLUMN3 VARCHAR,\n IN_COLUMN4 VARCHAR,\n IN_REQUESTED_COLUMN VARCHAR\n) RETURNS VARCHAR AS $$\nDECLARE\n C_TEST_TABLE REFCURSOR;\n C_TEST_TABLE_REC RECORD;\n RESULT VARCHAR(255);\n query TEXT;\nBEGIN\n query := 'SELECT * FROM test_table WHERE column1 = $1 AND column2 = $2 AND column3 = $3';\n IF IN_COLUMN4 IS NULL THEN\n query := query || ';';\n OPEN C_TEST_TABLE F", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "find_test_table_column" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_443", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS pgcrypto;\nSELECT digest(product_id::bytea, 'sha1') AS hash_value, length(digest(product_id::bytea, 'sha1')) AS hash_length\nFROM products;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_444", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT event_id, notes, CASE WHEN notes IS NULL THEN LEAD(notes) OVER (ORDER BY event_id ASC NULLS FIRST) ELSE notes END AS imputed_notes FROM event ORDER BY event_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_445", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH MemberEventDates AS (SELECT a.link_to_member, TO_TIMESTAMP(e.event_date, 'YYYY-MM-DD HH24:MI:SS') AS event_date, DENSE_RANK() OVER (PARTITION BY a.link_to_member ORDER BY TO_TIMESTAMP(e.event_date, 'YYYY-MM-DD HH24:MI:SS') DESC NULLS LAST) AS date_rank FROM attendance AS a LEFT JOIN event AS e ON a.link_to_event = e.event_id WHERE e.status = 'Open' OR e.status IS NULL), LatestEvents AS (SELECT link_to_member, MAX(CASE WHEN date_rank = 1 THEN event_date END) AS Latest_Event_Date FROM membere", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance", + "event", + "latestevents", + "member", + "membereventdates" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_446", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT trans_id, account_id, date, CASE WHEN CAST(EXTRACT(epoch FROM CAST(CAST(date AS TIMESTAMP) AS TIMESTAMP) - CAST(CAST(MIN(date) OVER (PARTITION BY account_id) AS TIMESTAMP) AS TIMESTAMP)) / 86400 AS BIGINT) <= 30 THEN 'Followup' ELSE 'New' END AS Category FROM trans ORDER BY trans_id NULLS FIRST LIMIT 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_447", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH cte AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY m1.member_id, m2.member_id ORDER BY e.event_date DESC NULLS LAST) AS rn FROM attendance AS a1 JOIN attendance AS a2 ON a1.link_to_event = a2.link_to_event AND a1.link_to_member < a2.link_to_member JOIN member AS m1 ON a1.link_to_member = m1.member_id JOIN member AS m2 ON a2.link_to_member = m2.member_id JOIN event AS e ON a1.link_to_event = e.event_id) SELECT * FROM cte WHERE rn = 1 ORDER BY event_date NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2094, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance", + "cte", + "event", + "member" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_448", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CardLegalities AS (\n SELECT C.uuid, COUNT(L.id) AS LegalityCount, STRING_AGG(L.format, ', ' ORDER BY L.format NULLS FIRST) AS Formats\n FROM cards AS C\n LEFT JOIN legalities AS L ON L.uuid = C.uuid\n GROUP BY C.uuid\n),\nCardDetails AS (\n SELECT C.name, C.manacost, CL.LegalityCount, CL.Formats\n FROM cards AS C\n INNER JOIN cardlegalities AS CL ON CL.uuid = C.uuid\n)\nSELECT name, manacost\nFROM carddetails\nWHERE LegalityCount > 0 AND NOT Formats LIKE '%commander%'\nEXCEPT\nSELECT", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1771, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-EXCEPT-ORDER", + "clauses_present": [ + "CTE", + "EXCEPT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "carddetails", + "cardlegalities", + "cards", + "legalities" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_449", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER (ORDER BY T.transactionid NULLS FIRST) AS Row, CAST(EXTRACT(epoch FROM CAST(CAST(LEAD(T.date, 1, 0) OVER (ORDER BY T.date NULLS FIRST) AS TIMESTAMP) AS TIMESTAMP) - CAST(CAST(T.date AS TIMESTAMP) AS TIMESTAMP)) AS BIGINT) AS TimeDifference FROM transactions_1k AS T LIMIT 100", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... AS TIMESTAMP)) AS BIGINT) AS TimeDifference FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_450", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH CardIssuanceDays AS ( SELECT c.card_id, c.issued, TO_CHAR(CAST(CAST(TO_CHAR(c.issued, 'MM/DD/YYYY') AS VARCHAR(10)) AS TIMESTAMP), 'TMDay') AS day_of_week , ROW_NUMBER() OVER (PARTITION BY TO_CHAR(CAST(c.issued AS TIMESTAMP), '%W') ORDER BY c.issued NULLS FIRST) AS rank_in_day FROM card AS c INNER JOIN disp AS d ON c.disp_id = d.disp_id AND d.type = 'OWNER' WHERE c.issued BETWEEN CURRENT_TIMESTAMP + INTERVAL '-5 YEAR' AND 0 + INTERVAL MONTH + INTERVAL '-1 DAY'), WeekdayReference AS ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"MONTH\" | LINE 1: ...T_TIMESTAMP + INTERVAL '-5 YEAR' AND 0 + INTERVAL MONTH + IN... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.2156, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "card", + "cardissuancedays", + "disp", + "weekdayreference" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_451", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT full_name, STRPOS(SUBSTR(full_name, 2), ' ') + 2 - 1 FROM superhero", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_452", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT date, account_id, CASE WHEN EXISTS(type = 'PRIJEM' AND 'VYDAJ' AND 'SLUZBY') THEN 1 ELSE 0 END FROM trans GROUP BY \"date\", account_id", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"type\" | LINE 1: EXPLAIN SELECT date, account_id, CASE WHEN EXISTS(type = 'PR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0313, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_453", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH ClientAccountSummary AS (\n SELECT\n cl.client_id,\n cl.gender,\n cl.birth_date,\n d.account_id,\n d.type,\n ROW_NUMBER() OVER (PARTITION BY cl.client_id ORDER BY d.account_id DESC NULLS LAST) AS account_rank\n FROM\n client AS cl\n LEFT JOIN\n disp AS d ON d.client_id = cl.client_id\n WHERE\n d.type = 'OWNER' OR d.type IS NULL\n),\nBabyBoomerFlag AS (\n SELECT\n client_id,\n gender,\n CASE\n WHEN TO_C", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1885, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "babyboomerflag", + "client", + "clientaccountsummary", + "disp" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_454", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT event.event_id, event.event_name, STRING_AGG(attendance.link_to_member, ';') AS attendances, STRING_AGG(budget.category, ';') AS budget_category FROM event LEFT JOIN attendance ON event.event_id = attendance.link_to_event LEFT JOIN budget ON event.event_id = budget.link_to_event WHERE event.event_id = 'reczhS8wix6Kzbp9P' GROUP BY event.event_id, event.event_name", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_455", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"PIVOT\" | LINE 2: WHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR pro... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 36.\n T \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) \u001b[4mPIVOT\u001b[0m(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_456", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH BudgetCategories AS (SELECT budget_id, category, spent, remaining, amount, event_status, link_to_event, DENSE_RANK() OVER (PARTITION BY link_to_event ORDER BY category NULLS FIRST) AS category_rank FROM budget WHERE link_to_event = 'recggMW2eyCYceNcy'), CategoryRanges AS (SELECT 'Food' AS min_category, 'Speaker Gifts' AS max_category, (SELECT category_rank FROM budgetcategories WHERE category = 'Food' AND link_to_event = 'recggMW2eyCYceNcy') AS min_rank, (SELECT category_rank FROM budgetcat", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "budget", + "budgetcategories", + "categoryranges" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_457", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ???, s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE s.id IN (1, 2, 3)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 1: EXPLAIN SELECT ???, s.superhero_name, p.publisher_name FROM ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 11.\n SELECT ???\u001b[4m,\u001b[0m s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "publisher", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_458", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CircuitFilters AS (SELECT c.circuitid, CASE WHEN c.country LIKE 'M%' THEN 1 ELSE 0 END AS IsCountryStartingWithM, CASE WHEN c.name LIKE '%International%' THEN 1 ELSE 0 END AS HasInternationalInName FROM circuits AS c) SELECT r.raceid FROM races AS r INNER JOIN circuitfilters AS cf ON cf.circuitid = r.circuitid WHERE cf.IsCountryStartingWithM = 1 EXCEPT SELECT r.raceid FROM races AS r INNER JOIN circuits AS c ON c.circuitid = r.circuitid WHERE c.name LIKE '%International%' HAVING COUNT(DISTI", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"r.raceid\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...WHERE cf.IsCountryStartingWithM = 1 EXCEPT SELECT r.raceid F... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-HAVING-EXCEPT", + "clauses_present": [ + "CTE", + "EXCEPT", + "FROM", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "circuitfilters", + "circuits", + "races" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_459", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT name, COUNT(printings) AS Prints FROM cards GROUP BY name ORDER BY Prints DESC NULLS LAST LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_460", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT atom_id FROM ( SELECT CASE WHEN element = 'cl' AND lead(element) OVER\n(ORDER BY atom_id) = 'c' THEN REPLACE(CONCAT(atom_id, lead(atom_id) OVER (ORDER BY atom_id)), ' ', '')\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 4: ...ment) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMB... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expected END after CASE. Line 4, Col: 82.\n _id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN \u001b[4matom_id\u001b[0m, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_461", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (SELECT r.raceId, r.name AS raceName, c.name AS circuitName, d.forename || ' ' || d.surname AS driverName, DENSE_RANK() OVER (PARTITION BY r.year ORDER BY res.points DESC NULLS LAST) AS seasonRanking, res.driverId, res.constructorId, res.position AS finishPosition, res.points, ROW_NUMBER() OVER (PARTITION BY r.raceId, res.constructorId ORDER BY res.points DESC NULLS LAST) AS constructorDriverRank FROM races AS r INNER JOIN circuits AS c ON r.circuitId = c.circuitId INNER JOIN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3219, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "circuits", + "constructorperformance", + "constructors", + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 6, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_462", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT a1.atom_id AS atom_id1, a2.atom_id AS atom_id2, b.bond_id, b.bond_type FROM atom AS a1 CROSS JOIN atom AS a2 LEFT JOIN connected AS c ON a1.atom_id = c.atom_id LEFT JOIN bond AS b ON c.bond_id = b.bond_id WHERE a1.molecule_id = a2.molecule_id ORDER BY a1.atom_id NULLS FIRST, a2.atom_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "atom", + "bond", + "connected" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_463", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ID, DATE, GOT, LAST_VALUE(GOT) OVER (PARTITION BY ID ORDER BY DATE NULLS FIRST) AS NEW_GOT FROM laboratory", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_464", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientExamData AS (SELECT P.ID AS PATIENTID, P.SEX, P.BIRTHDAY, E.\"Examination Date\", E.DIAGNOSIS, E.THROMBOSIS, ROW_NUMBER() OVER (PARTITION BY P.ID ORDER BY E.\"Examination Date\" NULLS FIRST) AS ExamRank FROM patient AS P LEFT JOIN examination AS E ON P.ID = E.ID), LatestLabResults AS (SELECT L.ID, L.PLT, L.WBC, ROW_NUMBER() OVER (PARTITION BY L.ID ORDER BY L.\"date\" DESC NULLS LAST) AS LabRank FROM laboratory AS L WHERE L.\"date\" <= CURRENT_TIMESTAMP), PatientRiskProfile AS (SELECT PED.PAT", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.251, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "latestlabresults", + "patient", + "patientexamdata", + "patientriskprofile" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_465", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH data AS (SELECT county, cdscode, ROW_NUMBER() OVER (PARTITION BY county ORDER BY cdscode ASC NULLS FIRST) AS rnk, DENSE_RANK() OVER (PARTITION BY county ORDER BY cdscode ASC NULLS FIRST) AS dense_rnk FROM schools), county_pairs AS (SELECT a.cdscode AS cdscode1, a.county AS county1, b.cdscode AS cdscode2, b.county AS county2, a.rnk AS rnk1, b.rnk AS rnk2, a.dense_rnk AS dense_rnk1, b.dense_rnk AS dense_rnk2 FROM data AS a LEFT JOIN data AS b ON a.county = b.county AND b.dense_rnk = a.dense_r", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1625, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "county_pairs", + "data", + "filtered_pairs", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_466", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH MoleculeAtomCounts AS (SELECT molecule_id, COUNT(*) AS atom_count FROM atom GROUP BY molecule_id), BondDetails AS (SELECT b.bond_id, b.molecule_id, b.bond_type, SUBSTRING(b.bond_id FROM 1 FOR POSITION('_' IN b.bond_id) - 1) AS derived_molecule_id, SUBSTRING(b.bond_id FROM POSITION('_' IN b.bond_id) + 1 FOR POSITION('_' IN SUBSTRING(b.bond_id FROM POSITION('_' IN b.bond_id) + 1)) - 1) AS first_atom_suffix, SUBSTRING(b.bond_id FROM POSITION('_' IN SUBSTRING(b.bond_id FROM POSITION('_' IN b.bo", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2781, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "bonddetails", + "connected", + "moleculeatomcounts" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_467", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH AtomBondMapping AS (\n SELECT\n a.atom_id,\n SUBSTRING(a.atom_id FROM 1 FOR POSITION('_' IN a.atom_id) - 1) || '_' ||\n SUBSTRING(a.atom_id FROM POSITION('_' IN a.atom_id) + 1 FOR LENGTH(a.atom_id)) || '_' ||\n CAST(CAST(SUBSTRING(c.atom_id2 FROM POSITION('_' IN c.atom_id2) + 1 FOR LENGTH(c.atom_id2)) AS INTEGER) AS VARCHAR) AS derived_bond_id\n FROM atom AS a\n INNER JOIN connected AS c ON a.atom_id = c.atom_id\n WHERE a.element = 'c'\n),\nMoleculeStats AS (\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column ms.atom_id does not exist | LINE 30: ...ON a.molecule_id = ms.molecule_id AND a.atom_id = ms.atom_id | ^ | Perhaps you meant to reference the column \"a.atom_id\" or the column \"c.atom_id\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2958, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atombondmapping", + "bond", + "connected", + "molecule", + "moleculestats" + ], + "num_joins": 6, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_468", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM molecule WHERE NOT molecule_id IN ('TR000', 'TR001', 'TR002', NULL)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "molecule" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_469", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH MonthlyRulings AS ( SELECT EXTRACT(YEAR FROM \"date\") AS ruling_year, EXTRACT(MONTH FROM \"date\") AS ruling_month, \"date\", \"text\", \"uuid\" FROM rulings), DailyRulingsWithRank AS ( SELECT ruling_year, ruling_month, TO_CHAR(DATE_TRUNC('month', \"date\"), 'YYYY-MM') AS month_format, \"date\", DENSE_RANK() OVER (PARTITION BY ruling_year, ruling_month ORDER BY \"date\" NULLS FIRST) AS date_rank, COUNT(*) OVER (PARTITION BY \"date\") AS rulings_per_day FROM monthlyrulings), DistinctDaysPerMonth AS ( SELECT ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2125, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "dailyrulingswithrank", + "distinctdayspermonth", + "monthlyrulings", + "rulings" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_470", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH SuperheroGenderCTE AS (SELECT s.id AS superhero_id, s.superhero_name, g.gender, ROW_NUMBER() OVER (PARTITION BY s.superhero_name ORDER BY g.id NULLS FIRST) AS rn FROM superhero AS s LEFT JOIN gender AS g ON CASE WHEN s.gender_id = g.id THEN 1 WHEN s.gender_id IS NULL AND g.id = 3 THEN 1 ELSE 0 END = 1) SELECT superhero_name, gender FROM superherogendercte WHERE rn = 1 ORDER BY superhero_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "gender", + "superhero", + "superherogendercte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_471", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientExamHistory AS (SELECT p.id, p.sex, p.birthday, p.description, p.\"First Date\", p.admission, p.diagnosis AS PatientDiagnosis, e.\"Examination Date\", e.\"aCL IgG\", e.\"aCL IgM\", e.ana, e.\"ANA Pattern\", e.\"aCL IgA\", e.diagnosis AS ExamDiagnosis, e.kct, e.rvvt, e.lac, e.symptoms, e.thrombosis, ROW_NUMBER() OVER (PARTITION BY p.id ORDER BY e.\"Examination Date\" DESC NULLS LAST) AS ExamRank, COUNT(*) OVER (PARTITION BY p.id) AS ExamCount FROM patient AS p LEFT JOIN examination AS e ON e.id = p", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2385, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "latestlabresults", + "patient", + "patientexamhistory" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_472", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH LabResults AS (\n SELECT l.id, l.date, l.got, l.gpt, l.ldh, l.alp, l.tp, l.alb, l.ua, l.un, l.cre, l.\"T-BIL\", l.\"T-CHO\", l.tg, l.cpk, l.glu, l.wbc, l.rbc, l.hgb, l.hct, l.plt, l.pt, l.aptt, l.fg, l.\"U-PRO\", l.igg, l.iga, l.igm, l.crp, l.ra, l.rf, l.c3, l.c4, l.rnp, l.sm, l.sc170, l.ssa, l.ssb, l.centromea, l.dna, l.\"DNA-II\",\n ROW_NUMBER() OVER (PARTITION BY l.id ORDER BY l.date DESC NULLS LAST) AS LatestRank,\n CASE\n WHEN l.crp IS NULL THEN 0\n WHEN l.crp IN ('Positive',", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2365, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "latestlabwithrank", + "patient", + "patientdiagnosis" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_473", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH LabResults AS (\n SELECT l.id, l.date, l.got, l.gpt, l.ldh, l.alp, l.tp, l.alb, l.ua, l.un, l.cre, l.\"T-BIL\", l.\"T-CHO\", l.tg, l.cpk, l.glu, l.wbc, l.rbc, l.hgb, l.hct, l.plt, l.pt, l.aptt, l.fg, l.\"U-PRO\", l.igg, l.iga, l.igm, l.crp, l.ra, l.rf, l.c3, l.c4, l.rnp, l.sm, l.sc170, l.ssa, l.ssb, l.centromea, l.dna, l.\"DNA-II\",\n ROW_NUMBER() OVER (PARTITION BY l.id ORDER BY l.date DESC NULLS LAST) AS LatestRank,\n CASE\n WHEN l.crp IS NULL THEN 0\n WHEN l.crp IN ('Positive',", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2365, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "latestlabwithrank", + "patient", + "patientdiagnosis" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_474", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (SELECT r.raceId, r.year, r.name AS raceName, res.positionText, d.forename || ' ' || d.surname AS driverName, res.driverId, ROW_NUMBER() OVER (PARTITION BY r.raceId, res.positionText ORDER BY res.resultId NULLS FIRST) AS position_rank FROM results AS res INNER JOIN races AS r ON res.raceId = r.raceId INNER JOIN drivers AS d ON res.driverId = d.driverId WHERE CAST(res.positionText AS INT) <= 3) SELECT rr.raceId, MAX(rr.year) AS year, MAX(rr.raceName) AS raceName, MAX(CASE WHEN", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"rr.positiontext\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ... rr.raceId ORDER BY MAX(rr.year) DESC NULLS LAST, rr.positio... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_475", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH x AS (SELECT driverid, statusid, ROW_NUMBER() OVER (PARTITION BY driverid ORDER BY COUNT(*) DESC NULLS LAST) AS rn FROM results GROUP BY driverid, statusid) INSERT INTO results (resultid, raceid, driverid, constructorid, number, grid, position, positiontext, positionorder, points, laps, time, milliseconds, fastestlap, rank, fastestlaptime, fastestlapspeed, statusid) SELECT driverid, 1, driverid, 1, 1, 1, position, positiontext, positionorder, points, 1, '00:00:00', 0, 1, 1, '00:00:00', '000", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"position\" does not exist | LINE 1: ... statusid) SELECT driverid, 1, driverid, 1, 1, 1, position, ... | ^ | There is a column named \"position\" in table \"results\", but it cannot be referenced from this part of the query.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-WINDOW-ORDER-INSERT", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "INSERT", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "results", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_476", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DriverGroups AS (SELECT CASE WHEN nationality IS NULL THEN 'Unknown' ELSE nationality END AS driver_group, code FROM drivers WHERE NOT code IS NULL), GroupedCodes AS (SELECT driver_group, MIN(code) AS min_code, MAX(code) AS max_code, COUNT(DISTINCT code) AS distinct_code_count FROM drivergroups GROUP BY driver_group) SELECT driver_group, CASE WHEN distinct_code_count > 1 THEN MIN(min_code) || '-' || MAX(max_code) ELSE MAX(max_code) END AS concat_codes FROM groupedcodes GROUP BY driver", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "drivergroups", + "drivers", + "groupedcodes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_477", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DriverGroups AS (SELECT CASE WHEN nationality IS NULL THEN 'Unknown' ELSE nationality END AS driver_group, code FROM drivers WHERE NOT code IS NULL), GroupedCodes AS (SELECT driver_group, MIN(code) AS min_code, MAX(code) AS max_code, COUNT(DISTINCT code) AS distinct_code_count FROM drivergroups GROUP BY driver_group) SELECT driver_group, CASE WHEN distinct_code_count > 1 THEN MIN(min_code) || '-' || MAX(max_code) ELSE MAX(max_code) END AS concat_codes FROM groupedcodes GROUP BY driver", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "drivergroups", + "drivers", + "groupedcodes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_478", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH TeamAverages AS (\n SELECT\n AVG(CAST(buildupplayspeed AS DECIMAL(10, 2))) AS AvgBuildupplaySpeed,\n AVG(CAST(defenceteamwidth AS DECIMAL(10, 2))) AS AvgDefenceTeamWidth\n FROM team_attributes\n WHERE buildupplayspeed IS NOT NULL AND defenceteamwidth IS NOT NULL\n),\nFilteredTeams AS (\n SELECT\n TA.id,\n TA.buildupplayspeed,\n TA.buildupplaypassing,\n TA.chancecreationpassing,\n TA.chancecreationcrossing,\n TA.chancecreationshooting,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "filteredteams", + "team_attributes", + "teamaverages" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_479", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH TeamAverages AS (\n SELECT\n AVG(CAST(buildupplayspeed AS DECIMAL(10, 2))) AS AvgBuildupplaySpeed,\n AVG(CAST(defenceteamwidth AS DECIMAL(10, 2))) AS AvgDefenceTeamWidth\n FROM team_attributes\n WHERE buildupplayspeed IS NOT NULL AND defenceteamwidth IS NOT NULL\n),\nFilteredTeams AS (\n SELECT\n TA.id,\n TA.buildupplayspeed,\n TA.buildupplaypassing,\n TA.chancecreationpassing,\n TA.chancecreationcrossing,\n TA.chancecreationshooting,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "filteredteams", + "team_attributes", + "teamaverages" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_480", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientTestDates AS (SELECT p.ID, p.SEX, p.Diagnosis, l.Date, ROW_NUMBER() OVER (PARTITION BY p.ID ORDER BY l.Date NULLS FIRST) AS RowNum FROM patient AS p LEFT JOIN laboratory AS l ON p.ID = l.ID WHERE l.Date >= p.\"First Date\" OR p.\"First Date\" IS NULL), ExaminationDates AS (SELECT p.ID, MIN(e.\"Examination Date\") AS earliest_exam_date FROM patient AS p LEFT JOIN examination AS e ON p.ID = e.ID GROUP BY p.ID) SELECT ptd.ID, ptd.SEX, ptd.Diagnosis, CASE WHEN ptd.Date < ed.earliest_exam_date ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "examinationdates", + "laboratory", + "patient", + "patienttestdates" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_481", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH x AS (SELECT FLOOR(COALESCE(LENGTH(CAST(label AS TEXT)), 0) / 100) AS labellength FROM molecule) SELECT labellength * 100 AS labellengthstart, (labellength + 1) * 100 - 1 AS labellengthend, COUNT(*) AS moleculecount FROM x ORDER BY labellength NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"x.labellength\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...), 0) / 100) AS labellength FROM molecule) SELECT labellengt... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "WITH-CTE-SELECT-FROM-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "molecule", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_482", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT id, name, ROW_NUMBER() OVER (PARTITION BY id ORDER BY label NULLS FIRST) AS item, CONCAT(label, ' (', tag1, ')') AS value FROM (SELECT id, name, 'Colors' AS label, colors AS tag1 FROM cards UNION ALL SELECT id, name, 'ManaCost' AS label, manacost AS tag1 FROM cards) AS src) AS src WHERE id = '1'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_483", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientThrombosisHistory AS (SELECT e.ID, e.Thrombosis, ROW_NUMBER() OVER (PARTITION BY e.ID ORDER BY e.\"Examination Date\" DESC NULLS LAST) AS RecencyRank, COUNT(*) OVER (PARTITION BY e.ID) AS ExamCount FROM examination AS e WHERE NOT e.Thrombosis IS NULL), LabResults AS (SELECT l.ID, AVG(l.PLT) AS AvgPlateletCount, MAX(CASE WHEN l.PLT < 150 THEN 1 ELSE 0 END) AS HasLowPlatelets FROM laboratory AS l WHERE l.Date >= CURRENT_TIMESTAMP + INTERVAL '-1 YEAR' GROUP BY l.ID) SELECT p.ID AS Patient", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2448, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "patient", + "patientthrombosishistory" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_484", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TEAMATTRS AS (SELECT BUILDUPPLAYSPEED AS VALUE, 'Team_Attributes' AS IDENTIFIER, ROW_NUMBER() OVER (ORDER BY BUILDUPPLAYSPEED NULLS FIRST) AS RN FROM team_attributes) SELECT PLAYERATTRS.VALUE, PLAYERATTRS.IDENTIFIER, TEAMATTRS.VALUE, TEAMATTRS.IDENTIFIER FROM (SELECT OVERALL_RATING AS VALUE, 'Player_Attributes' AS IDENTIFIER, ROW_NUMBER() OVER (ORDER BY OVERALL_RATING NULLS FIRST) AS RN FROM player_attributes) AS PLAYERATTRS FULL OUTER JOIN teamattrs ON PLAYERATTRS.RN = TEAMATTRS.RN WHERE P", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1438, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "player_attributes", + "team_attributes", + "teamattrs" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_485", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"date\", home_team_api_id AS group_1, away_team_api_id AS group_2, home_team_goal AS daily_profits, SUM(home_team_goal) OVER (PARTITION BY CAST(\"date\" AS INT), home_team_api_id, away_team_api_id ORDER BY \"date\" NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS mtd, SUM(home_team_goal) OVER (PARTITION BY TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'YYYY'), TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'quarter'), home_team_api_id, away_team_api_id ORDER BY \"date\" NULLS FIRST ROWS BETWEEN UNBOUND", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0354, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_486", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH CardLegalities AS (\n SELECT c.name AS card_name, l.format, l.status, l.id,\n DENSE_RANK() OVER (PARTITION BY c.uuid, l.format ORDER BY CASE WHEN l.status = 'Legal' THEN 0 ELSE 1 END NULLS FIRST) AS status_priority\n FROM cards AS c\n LEFT JOIN legalities AS l ON c.uuid = l.uuid\n WHERE l.format IN ('commander', 'duel', 'legacy')\n),\nLegalityStats AS (\n SELECT card_name, format,\n MAX(CASE WHEN status = 'Legal' THEN id END) AS legal_id,\n MAX(CASE WHEN status = 'Banned' THEN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1938, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cardlegalities", + "cards", + "legalities", + "legalitystats" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_487", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH a AS (SELECT id, date AS applicationid, ROW_NUMBER() OVER (PARTITION BY id ORDER BY date NULLS FIRST) AS rn, LAG(date) OVER (PARTITION BY id ORDER BY date NULLS FIRST) AS prev FROM laboratory) SELECT id AS usercode, prev AS data_1, rn AS id_2, applicationid AS data_2, rn - 1 AS id_1 FROM a WHERE NOT prev IS NULL AND id = 27654", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "a", + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_488", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT RACEID, NAME, \"date\", LAG(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS PREVRACEID, LEAD(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS NEXTRACEID FROM races ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_existent_column\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"non_existent_column\" does not exist | LINE 1: ...es ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_exist... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'non_existent_column' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "non_existent_column", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_489", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH pages AS (SELECT 1 AS page_id, 1 AS power_id UNION ALL SELECT 1, 7 UNION ALL SELECT 2, 1 UNION ALL SELECT 3, 1 UNION ALL SELECT 3, 7 UNION ALL SELECT 3, 89 UNION ALL SELECT 4, 20 UNION ALL SELECT 5, 55 UNION ALL SELECT 5, 1 UNION ALL SELECT 6, 1 UNION ALL SELECT 6, 13), items AS (SELECT 10 AS hero_id, 1 AS power_id UNION ALL SELECT 10, 7 UNION ALL SELECT 10, 20 UNION ALL SELECT 12, 1 UNION ALL SELECT 12, 55) SELECT p.page_id, i.hero_id FROM (SELECT p.page_id, p.power_id, COUNT(*) OVER (PART", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING-WINDOW-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "items", + "pages" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_490", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH data AS (SELECT p.id, p.\"First Date\" AS as_of_date, p.diagnosis AS current_diagnosis, LAG(p.diagnosis) OVER (PARTITION BY p.id ORDER BY p.\"First Date\" NULLS FIRST) AS prev_diagnosis, CASE WHEN p.diagnosis IN ('RA susp.', 'PSS', 'SLE') THEN 1 ELSE 0 END AS output_flag FROM patient AS p) SELECT as_of_date, id, current_diagnosis, prev_diagnosis, CASE WHEN output_flag = 1 THEN MIN(as_of_date) OVER (PARTITION BY id, output_flag ORDER BY as_of_date NULLS FIRST) END AS desired_output FROM data WHE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "data", + "patient" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_491", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH ATOMRNS AS (SELECT MOLECULE_ID, ELEMENT, ROW_NUMBER() OVER (PARTITION BY MOLECULE_ID ORDER BY ATOM_ID NULLS FIRST) AS RN FROM atom) SELECT MOLECULE_ID, MAX(CASE WHEN RN = 1 THEN ELEMENT END) AS ELEMENT1, MAX(CASE WHEN RN = 2 THEN ELEMENT END) AS ELEMENT2, MAX(CASE WHEN RN = 3 THEN ELEMENT END) AS ELEMENT3 FROM atomrns JOIN atom ON ATOMRNS.MOLECULE_ID = ATOM.MOLECULE_ID GROUP BY MOLECULE_ID", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "column reference \"molecule_id\" is ambiguous | LINE 1: ...R BY ATOM_ID NULLS FIRST) AS RN FROM atom) SELECT MOLECULE_I... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42702" + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1115, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atomrns" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_492", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH SUPERHEROLIST AS (SELECT ID, SUPERHERO_NAME, FULL_NAME, ROW_NUMBER() OVER (PARTITION BY PUBLISHER_ID ORDER BY ID NULLS FIRST) AS PUBLISHER_RANK, DENSE_RANK() OVER (ORDER BY ALIGNMENT_ID NULLS FIRST, ID NULLS FIRST) AS GLOBAL_RANK FROM superhero WHERE NOT HEIGHT_CM IS NULL), SUPERHERO_POWERS AS (SELECT S.ID, S.SUPERHERO_NAME, COUNT(HP.POWER_ID) AS POWER_COUNT, STRING_AGG(SP.POWER_NAME, ', ' ORDER BY SP.POWER_NAME NULLS FIRST) AS POWERS FROM superhero AS S LEFT JOIN hero_power AS HP ON S.ID =", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column s2.publisher_id does not exist | LINE 1: ... AS S2 ON S2.GLOBAL_RANK = S1.GLOBAL_RANK + 4 AND S2.PUBLISH... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "hero_power", + "superhero", + "superhero_powers", + "superherolist", + "superpower" + ], + "num_joins": 5, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_493", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT num FROM (SELECT number AS num, ROW_NUMBER() OVER (ORDER BY id NULLS FIRST) - ROW_NUMBER() OVER (PARTITION BY CAST(number AS INT) ORDER BY id NULLS FIRST) AS grp FROM cards) AS a GROUP BY grp, num HAVING COUNT(*) >= 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_494", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH BondTypeRanking AS (SELECT bond_id, molecule_id, bond_type, CASE WHEN bond_type = '-' THEN 1 WHEN bond_type = '=' THEN 2 WHEN bond_type = '#' THEN 3 ELSE CAST(bond_type AS INT) END AS bond_type_rank FROM bond), MoleculeWithMultipleBondTypes AS (SELECT molecule_id FROM bond GROUP BY molecule_id HAVING COUNT(DISTINCT CASE WHEN bond_type = '-' THEN 'single' WHEN bond_type = '=' THEN 'double' WHEN bond_type = '#' THEN 'triple' ELSE bond_type END) > 1) SELECT b.molecule_id, b.bond_type FROM (S", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "bond", + "bondtyperanking", + "moleculewithmultiplebondtypes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_495", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH SchoolScores AS (\n SELECT\n s.school,\n sa.avgscrread,\n sa.avgscrmath,\n sa.avgscrwrite,\n DENSE_RANK() OVER (PARTITION BY sa.rtype ORDER BY sa.avgscrread DESC) AS ReadingRank\n FROM\n schools AS s\n INNER JOIN\n satscores AS sa ON s.cdscode = sa.cds\n WHERE\n s.county = 'Alameda'\n AND sa.rtype = 'S'\n),\nMaxReadingScore AS (\n SELECT MAX(avgscrread) AS MaxRead\n FROM satscores\n WHERE rtype = 'S'\n)\nSELECT\n ss.school,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1948, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-JOIN_CROSS-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "maxreadingscore", + "satscores", + "schools", + "schoolscores" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_497", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n xml_result xml;\nBEGIN\n -- First attempt to build the XML structure with nested XML queries\n WITH SchemaInfo AS (\n SELECT\n COLUMN_NAME,\n DATA_TYPE,\n ORDINAL_POSITION\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'schools' AND TABLE_SCHEMA = current_schema()\n ),\n SATData AS (\n SELECT\n cds,\n rtype,\n ROW_NUMBER() OVER(PARTITION BY cds ORDER BY NumTstTakr DESC) AS RowRank", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"schemainfo.ordinal_position\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 31: ORDER BY ORDINAL_POSITION) | ^ | QUERY: WITH SchemaInfo AS ( | SELECT | COLUMN_NAME, | DATA_TYPE, | ORDINAL_POSITION | FROM INFORMATION_SCHEMA.COLUMNS | WHERE TABLE_NAME = 'schools' AND TABLE_SCHEMA = current_schema() | ), | SATData AS ( | SELECT | cds, | rtype, | ROW_NUMBER() OVER(PARTITION BY cds ORDER BY NumTstTakr DESC) AS RowRank | FROM satscores | WHERE NumTstTakr > 0 | ) | SELECT xmlelement( | name \"Results\", | (SELECT xmlagg( | xmlelement( | name \"Columns\", | (SELECT xmlagg( | xmlelement( | name \"Column\", | xmlattributes(COLUMN_NAME as \"Name\"), | xmlelement(name \"DataType\", DATA_TYPE) | ) | ) | FROM SchemaInfo | ORDER BY ORDINAL_POSITION) | ) | )), | (SELECT xmlagg( | xmlelement( | name \"Rows\", | (SELECT xmlagg( | xmlelement( | name \"Row\", | xmlelement(name \"cds\", CASE WHEN cds IS NULL THEN 'xsi:nil=\"true\"' ELSE cds END), | xmlelement(name \"rtype\", CASE WHEN rtype IS NULL THEN 'xsi:nil=\"true\"' ELSE rtype END) | ) | ) | FROM SATData | WHERE RowRank = 1) | ) | )) | ) | PL/pgSQL function inline_code_block line 6 at SQL statement", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_498", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CustomerID, Consumption, MIN(Date) AS MinDate, MAX(Date) AS MaxDate\nFROM yearmonth WHERE Consumption = 0 GROUP BY CustomerID, Consumption;\n\nUPDATE yearmonth TGT SET DenseRankTest = SRC.NewRank\nFROM (SELECT Row_ID, DENSE_RANK() OVER (PARTITION BY CustomerID ORDER BY Consumption ASC) AS NewRank\n FROM yearmonth) AS SRC\nWHERE SRC.Row_ID = TGT.Row_ID;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"row_id\" does not exist | LINE 5: FROM (SELECT Row_ID, DENSE_RANK() OVER (PARTITION BY Custome... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "yearmonth" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_499", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n c.customerid,\n (\n SELECT\n CAST(t.transactionid AS TEXT) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n FOR JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.customerid\nWHERE segment = 'SME'\nFOR JSON PATH, WITHOUT_ARRAY_WRAPPER;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JSON\" | LINE 8: FOR JSON PATH | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c\n\nInvalid expression / Unexpected token. Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_500", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.name,\nCOALESCE(STRING_AGG(tmp.name, ', '), '')\nFROM races r\nLEFT JOIN\n(\n SELECT c.name, cr.raceid FROM constructors c\n JOIN constructorresults cr ON c.constructorid = cr.constructorid\n) tmp ON tmp.raceid = r.raceid\nGROUP BY r.name", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "constructorresults", + "constructors", + "races" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_501", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER () AS rownum, id_column, decimal_column, nvarchar_column\nFROM json_table(\n '[\n {\"id_column\": 1234, \"decimal_column\": 12.34, \"nvarchar_column\": \"asdf\"},\n {\"id_column\": 5678, \"decimal_column\": 56.78, \"nvarchar_column\": \"fdsa\"}\n ]',\n '$[*]' COLUMNS (\n id_column BIGINT PATH '$.id_column',\n decimal_column DECIMAL(28,8) PATH '$.decimal_column',\n nvarchar_column VARCHAR(30) PATH '$.nvarchar_column'\n )\n) AS data", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"COLUMNS\" | LINE 7: '$[*]' COLUMNS ( | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM-WINDOW", + "clauses_present": [ + "FROM", + "SELECT", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_502", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, value FROM races CROSS JOIN LATERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GROUPING(name) as name FOR value in ('name1','name2','name3','name4')) piv;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"PIVOT\" | LINE 1: ...TERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GRO... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_503", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_id bigint;\n v_date date;\n db_update_cursor CURSOR FOR\n SELECT id, date\n FROM laboratory\n ORDER BY id, date\n LIMIT 2;\nBEGIN\n OPEN db_update_cursor;\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n WHILE FOUND LOOP\n INSERT INTO destinationTable(testRow)\n VALUES ((SELECT v_id, v_date FOR JSON AUTO));\n\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n END LOOP;\n\n CLOSE db_update_cursor;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JSON\" | LINE 15: VALUES ((SELECT v_id, v_date FOR JSON AUTO)); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_504", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH hero_activity AS\n (SELECT id,\n activity_date,\n activity_value,\n hero_id\n FROM (\n VALUES (1,\n '2023-01-01',\n 10,\n 1), (2,\n '2023-01-02',\n 20,\n 1), (3,\n '2023-02-01',\n 15,\n 1), (4,\n '2023-02-02',\n 25,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function pg_catalog.extract(unknown, text) does not exist | LINE 32: ... SUM(activity_value) OVER (PARTITION BY EXTRACT(YE... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1052, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "VALUES", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "activity_totals", + "hero_activity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_505", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (\n\n SELECT\n r.raceId,\n r.year,\n r.date,\n res.driverId,\n res.points,\n\n DENSE_RANK() OVER (PARTITION BY res.driverId, r.year ORDER BY r.date) AS SeasonRaceNumber,\n\n ROW_NUMBER() OVER (PARTITION BY res.driverId ORDER BY r.year, r.date) AS CareerRaceNumber\n FROM results res\n JOIN races r ON res.raceId = r.raceId\n WHERE res.position IS NOT NULL\n),\nDriverFirstFiveRaces AS (\n\n SELECT\n driverId,\n year,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2021, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "driverfirstfiveraces", + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_506", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH cte AS\n (SELECT id,\n \"Examination Date\",\n thrombosis,\n risklag = LAG(thrombosis, 1, thrombosis) OVER (PARTITION BY id\n ORDER BY \"Examination Date\"),\n rn = ROW_NUMBER() OVER (PARTITION BY id,\n EXTRACT(YEAR FROM \"Examination Date\"),\n EXTRACT(MONTH FROM \"Examination Date\")\n ORDER", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"risklag\" does not exist | LINE 5: risklag = LAG(thrombosis, 1, thrombosis) OVER (PAR... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_507", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH MoleculeList AS (\n SELECT unnest(string_to_array('TR000,TR001,TR002', ',')) AS molecule_id\n),\nMoleculeStats AS (\n SELECT\n m.molecule_id,\n m.label,\n COUNT(a.atom_id) AS atom_count,\n COUNT(DISTINCT b.bond_type) AS unique_bond_types,\n DENSE_RANK() OVER (ORDER BY COUNT(a.atom_id) DESC) AS size_rank\n FROM molecule m\n LEFT JOIN atom a ON m.molecule_id = a.molecule_id\n LEFT JOIN bond b ON m.molecule_id = b.molecule_id\n GROUP BY m.molecule_id, m.", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2917, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "molecule", + "moleculelist", + "moleculestats" + ], + "num_joins": 3, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_508", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH KEYWORDMATCHES AS\n (SELECT P.ID,\n CASE\n WHEN POSITION(LOWER('Aaron') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Aaron'\n END AS COLAKEYWORD,\n CASE\n WHEN POSITION(LOWER('Cresswell') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Cresswell'\n END AS COLBKEYWORD,\n CASE\n WHEN POSITION(LOWER('Doran') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Doran'\n END AS COLCKEYWORD\n FROM PLAYER AS P),\n KEYWORDSCORES AS\n (SELECT ID,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "for SELECT DISTINCT, ORDER BY expressions must appear in select list | LINE 37: ORDER BY KS.COLASCORE; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P10" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1625, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-FILTER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FILTER", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "keywordmatches", + "keywordscores", + "player" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_509", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH ChangeHistory AS (\n\n SELECT\n s.cdscode,\n s.school,\n s.fundingtype,\n s.lastupdate,\n\n DENSE_RANK() OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) AS ChangeSequence,\n\n CASE WHEN LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) IS NULL\n OR LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) <> s.school\n THEN 1 ELSE 0 END AS SchoolChanged,\n CASE WHEN LAG(s.fundingtype) OVER (PARTITION ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "invalid UNION/INTERSECT/EXCEPT ORDER BY clause | LINE 70: CASE WHEN ColumnName = 'School' THEN 1 ELSE 2 END; | ^ | Only result column names can be used, not expressions or functions. | Add the expression/function to every SELECT, or move the UNION into a FROM clause.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.3083, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "changehistory", + "changesonly", + "schools" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_510", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' || pa.player_api_id::text || ','\n LIKE '%,' || p.player_api_id::text || ',%'\n)\nSELECT\n id,\n name,\n player_api_id = xpath('text()', col)::VARCHAR(100)\nFROM CTE\nCROSS JOIN LATERAL XMLTABLE('/t' PASSING xml_val COLUMNS col XML PATH '.') AS CA\nLI", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"xml_val\" does not exist | LINE 5: xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\nExpecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\ndpipe does not support CTE. Line 5, Col: 101.\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''\u001b[4m)\u001b[0m,\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' |\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "schema_hallucination_col", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "WITH-CTE-SELECT", + "clauses_present": [ + "CTE", + "SELECT", + "WITH" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_511", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH t AS\n (SELECT e.*,\n ROW_NUMBER() OVER (PARTITION BY e.id\n ORDER BY e.\"Examination Date\") AS seqnum\n FROM examination AS e),\n cte AS\n (SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n 'N' AS isrehire,\n t.\"Examination Date\" AS anchordate\n FROM t\n WHERE t.seqnum = 1\n UNION ALL SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n CAS", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"cte\" does not exist | LINE 25: FROM cte | ^ | There is a WITH item named \"cte\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination", + "t" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_512", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE T_period_futur AS\n (SELECT 1 AS Tpf_period_id,\n CAST('2021-10-25' AS DATE) AS Tpf_start_period\n UNION ALL SELECT Tpf_period_id + 1 AS Tpf_period_id,\n Tpf_start_period + INTERVAL '1 week'\n FROM T_period_futur\n WHERE Tpf_period_id < 12 )\nSELECT Tpf_period_id,\n Tpf_start_period,\n EXTRACT(YEAR FROM Tpf_start_period) AS Tpf_year,\n CAST(EXTRACT(YEAR FROM Tpf_start_period) AS VARCHAR) || '.' || RIGHT('00' || CAST(EXTRACT(WEEK FROM Tpf_", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"t_period_futur\" column 2 has type date in non-recursive term but type timestamp without time zone overall | LINE 3: CAST('2021-10-25' AS DATE) AS Tpf_start_period | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0635, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "t_period_futur" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_515", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 1) as value1, SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 2) as value2, SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 3) as value3 FROM trans WHERE trans_id = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_516", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ID, value FROM PATIENT CROSS JOIN LATERAL string_to_table(DIAGNOSIS, ',') AS s(value) WHERE DIAGNOSIS = 'SLE' || '; DROP TABLE PATIENT; --';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_517", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH data1 AS ( SELECT originalreleasedate, (date_trunc('week', to_date(originalreleasedate, 'YYYY-MM-DD') + interval '1 day') - interval '1 day')::date AS start_of_week_mon, floor((to_date(originalreleasedate, 'YYYY-MM-DD') - DATE '2007-01-01') / 7)::int + 1 AS week_number FROM cards WHERE originalreleasedate IS NOT NULL AND to_date(originalreleasedate, 'YYYY-MM-DD') >= DATE '2007-01-01' ), weekly_data AS ( SELECT start_of_week_mon, week_number FROM data1 ) SELECT start_of_week_mon AS actual_st", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "cards", + "data1", + "weekly_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_518", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"first_name\" || ' ' || e.\"last_name\" AS email_full_name, e.email, p.position FROM member_email AS e INNER JOIN member_position AS p ON email_full_name = p.full_name", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"email_full_name\" does not exist | LINE 1: ...ber_email AS e INNER JOIN member_position AS p ON email_full... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "member_email", + "member_position" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_519", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(motherGroups.Mothers) AS UniqueMotherGroups FROM\n(SELECT STRING_AGG(CAST(c.id AS VARCHAR), '') WITHIN GROUP (ORDER BY c.id) AS Mothers FROM laboratory c GROUP BY c.id) AS motherGroups", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function string_agg(character varying, unknown, bigint) does not exist | LINE 2: (SELECT STRING_AGG(CAST(c.id AS VARCHAR), '') WITHIN GROUP (... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_520", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n StartDate timestamp;\n EndDate timestamp;\nBEGIN\n StartDate := '2010-02-22 00:00:00';\n EndDate := '2010-02-22 23:59:59';\n\n SELECT *\n FROM team_attributes\n WHERE date BETWEEN StartDate AND EndDate;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text >= timestamp without time zone | LINE 3: WHERE date BETWEEN StartDate AND EndDate | ^ | No operator matches the given name and argument types. You might need to add explicit type casts. | QUERY: SELECT * | FROM team_attributes | WHERE date BETWEEN StartDate AND EndDate | PL/pgSQL function inline_code_block line 9 at SQL statement", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_521", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH PaymentRanks AS (SELECT payments, ROW_NUMBER() OVER (ORDER BY payments DESC NULLS LAST) AS row_num, DENSE_RANK() OVER (ORDER BY payments DESC NULLS LAST) AS dense_rank_num, COUNT(*) OVER () AS total_count FROM loan), DistinctPayments AS (SELECT COUNT( payments) AS distinct_payment_count FROM loan) SELECT CASE WHEN (SELECT COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM payme", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHERE\" | LINE 1: ...inct_payment_count FROM distinctpayments) = 1 AND WHERE paym... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'expression' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nRequired keyword: 'true' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nExpected END after CASE. Line 1, Col: 430.\n T COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 \u001b[4mAND\u001b[0m WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END\n\n... and 1 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distinctpayments", + "loan" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_523", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 'budget_seq' FROM budget LIMIT 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_524", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n spell_starts AS (\n SELECT start_date, end_date\n FROM blackout_periods s1\n WHERE NOT EXISTS (\n SELECT 1\n FROM blackout_periods s2\n WHERE s2.start_date < s1.start_date\n AND s1.start_date <= s2.end_date\n )\n ),\n spell_ends AS (\n SELECT start_date, end_date\n FROM blackout_periods t1\n WHERE NOT EXISTS (\n SELECT 1\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"merge_table_2\" does not exist | LINE 33: FROM merge_table_2 | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "blackout_periods", + "spell_ends", + "spell_starts" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_525", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n batch INT := 10000;\nBEGIN\n WHILE batch > 0 LOOP\n BEGIN\n START TRANSACTION;\n INSERT INTO player_stats\n SELECT * FROM player_stats_temp\n LIMIT batch;\n GET DIAGNOSTICS batch = ROW_COUNT;\n COMMIT;\n END;\n END LOOP;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "unsupported transaction command in PL/pgSQL | PL/pgSQL function inline_code_block line 7 at SQL statement", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_526", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DriverId, MIN(StartDate) AS StartDate, MAX(EndDate) AS EndDate\nFROM (SELECT *,\nSUM(CASE WHEN a.EndDate = a.StartDate THEN 0 ELSE 1 END) OVER (ORDER BY DriverId, StartDate) sm\nFROM (SELECT DriverId, StartDate, EndDate,\nLAG(EndDate, 1, NULL) OVER (PARTITION BY DriverId ORDER BY DriverId, EndDate) prev_EndDate\nFROM driverContracts) a\n) b\nGROUP BY DriverId, sm;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1938, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "drivercontracts" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_527", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE ExpCTE AS (\nSELECT\nDENSE_RANK() OVER (ORDER BY exp_id) AS ExpRN\n, exp_id\n, mid\n, qty\nFROM\nExperiment WHERE mid = 2\n)\n, CTE AS\n(\nSELECT\ne.exp_id\n, e.mid\n, e.qty\n, i.qty - e.qty AS QtyAvailable\n, e.ExpRN\nFROM\nExpCTE e\nINNER JOIN\nInventory i ON i.mid = e.mid\nWHERE\ne.exp_id IN (SELECT e_sub.exp_id\nFROM Experiment e_sub\nWHERE NOT EXISTS (SELECT 1 FROM Inventory i_sub\nWHERE i_sub.mid = e_sub.mid AND i_sub.qty < e_sub.qty)\nORDER BY e_sub.exp_id\nLIMIT 1)\nAND e.mid = 2\nUNION ALL\nSELECT\ne.e", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2927, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "expcte", + "experiment", + "inventory" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_528", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE vt as (\nselect t.*, row_number() over (partition by CustomerID order by StartDate) as seqnum\nfrom transactions_1k t\n),\ncte as (\nselect vt.TransactionID, vt.CustomerID, vt.StartDate, vt.EndDate, vt.StartDate as first_begin_date, seqnum\nfrom vt\nwhere seqnum = 1\nunion all\nselect vt.TransactionID, vt.CustomerID, vt.StartDate, vt.EndDate,\n(case when vt.StartDate > (cte.EndDate + interval '90 days') then vt.StartDate else cte.EndDate end),\nvt.seqnum\nfrom cte join\nvt\non vt.seqnum = cte.s", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "transactions_1k", + "vt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_529", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE cte AS (\nSELECT ID, ParentID\nFROM LaboratoryLink\nWHERE ID IN (657266, 115562)\nUNION ALL\nSELECT t.ID, t.ParentID\nFROM LaboratoryLink t\nJOIN cte c ON t.ID = c.ParentID\nWHERE t.ParentID IS NOT NULL\n)\nSELECT *\nFROM cte;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "cte", + "laboratorylink" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + } + ] +} \ No newline at end of file diff --git a/tests/output/validate_with_db_benchmark_results_errors_only.json b/tests/output/validate_with_db_benchmark_results_errors_only.json new file mode 100644 index 0000000..ee47241 --- /dev/null +++ b/tests/output/validate_with_db_benchmark_results_errors_only.json @@ -0,0 +1,10822 @@ +[ + { + "instance_id": "PostgreSQL_4", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE transactions_1k\n SET Amount = 100\n FROM ( SELECT TransactionID FROM transactions_1k WHERE Amount = 50 ORDER BY Date LIMIT 100 FOR UPDATE ) sub\n WHERE transactions_1k.TransactionID = sub.TransactionID RETURNING *;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN UPDATE transactions_1k | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1042, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-LOCKING-UPDATE-RETURNING-SUBQUERY", + "clauses_present": [ + "FROM", + "LIMIT", + "LOCKING", + "ORDER", + "RETURNING", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_5", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT users.Id, COUNT(posts.Id) as answered FROM users LEFT JOIN posts ON users.Id = posts.OwnerUserId GROUP BY users.Id ORDER BY answered DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column posts.owneruserid does not exist | LINE 1: ...answered FROM users LEFT JOIN posts ON users.Id = posts.Owne... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'OwnerUserId' does not exist in table 'posts' (referenced as 'posts.OwnerUserId')", + "taxonomy_category": "semantic", + "context": "posts.OwnerUserId", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "posts", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_6", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS users;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot drop table users because other objects depend on it | constraint posthistory_userid_fkey on table posthistory depends on table users | constraint badges_userid_fkey on table badges depends on table users | constraint comments_userid_fkey on table comments depends on table users | constraint posts_lasteditoruserid_fkey on table posts_backup depends on table users | constraint posts_owneruserid_fkey on table posts_backup depends on table users | constraint votes_userid_fkey on table votes depends on table users | Use DROP ... CASCADE to drop the dependent objects too.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "2BP01" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "users" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_8", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH CTE AS ( SELECT link_to_event, COUNT(link_to_member) AS count FROM attendance GROUP BY link_to_event ) SELECT CTE.link_to_event, CTE.count AS newCount, budget.count AS oldCount FROM budget JOIN CTE ON budget.link_to_event = CTE.link_to_event WHERE budget.count != CTE.count;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in WHERE | LINE 1: ...ON budget.link_to_event = CTE.link_to_event WHERE budget.cou... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "attendance", + "budget", + "cte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_10", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE account\n SET date__timestamp = date__bigint::timestamp;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"date__bigint\" does not exist | LINE 2: SET date__timestamp = date__bigint::timestamp; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__timestamp" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__bigint' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__bigint" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_11", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM cards GROUP BY artist;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"cards.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT * FROM cards GROUP BY artist; | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_12", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "IF SELECT * FROM transactions_1k WHERE CustomerID = 3 AND Date = '2012-08-24' RETURNS NO ROWS\nTHEN SELECT * FROM transactions_1k WHERE CustomerID = 7626 AND Date = '2012-08-24'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"IF\" | LINE 1: IF SELECT * FROM transactions_1k WHERE CustomerID = 3 AND Da... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_14", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 0 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_id = l.account_id\n WHERE account.district_id = '18'\n AND l.date >= (NOW() - INTERVAL '48 hours')\n ORDER BY l.date DESC NULLS LAST\n LIMIT 6\n)\nUNION\n(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 1 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_i", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column l.date does not exist | LINE 6: l.date AS loan_date, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_15", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Array_agg(rw) FROM (SELECT link_to_event, (SELECT To_(Array_agg(Row_to_(t))) FROM (SELECT link_to_member FROM public.attendance WHERE link_to_event = b.link_to_event) t) rw FROM attendance b GROUP BY link_to_event);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: EXPLAIN SELECT Array_agg(rw) FROM (SELECT link_to_event, (SE... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_16", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT to_char(generate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FROM\" | LINE 1: ...)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 123.\n rate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') \u001b[4mFROM\u001b[0m loan;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0125, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_17", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account_id, amount FROM (SELECT account_id, amount, ROW_NUMBER() OVER(PARTITION BY account_id ORDER BY amount DESC) AS rn FROM loan) AS a WHERE rn = 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"amount\" does not exist | LINE 1: ...ELECT account_id, amount FROM (SELECT account_id, amount, RO... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "amount", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_18", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE client_information ( client_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) GENERATED ALWAYS AS (concat(first_name, ' ', last_name)) STORED, PRIMARY KEY (client_id) );", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "generation expression is not immutable", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P17" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "client_information" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_20", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (account_id, district_id, frequency, date) VALUES (1, 18, 'POPLATEK MESICNE', CURRENT_DATE) ON CONFLICT (account_id) DO UPDATE SET date = CURRENT_DATE", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"date\" is of type bigint but expression is of type date | LINE 1: ...equency, date) VALUES (1, 18, 'POPLATEK MESICNE', CURRENT_DA... | ^ | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_24", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\\n a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) as referencing_table,\\n UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as referencing_col,\\n pg_get_constraintdef(c.oid) contraint_sql FROM pg_constraint c join pg_attribute a on c.confrelid=a.attrelid and a.attnum = ANY(confkey)\\n WHERE c.", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\\\" | LINE 1: ..._class r where r.oid = c.confrelid) as base_table,\\n a... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 83.\n SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\u001b[4m\\\u001b[0mn a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) a", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pg_class" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_25", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT first_value(bank ignore nulls) over (partition by account_id order by date rows unbounded following) as next_bank FROM trans;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"ignore\" | LINE 1: EXPLAIN SELECT first_value(bank ignore nulls) over (partitio... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_26", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team_api_id, team_short_name FROM Team as data FULL OUTER JOIN (SELECT buildUpPlaySpeed, team_api_id FROM Team_Attributes ta WHERE team_api_id = data.team_api_id) AS subquery_alias ON data.team_api_id = subquery_alias.team_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "invalid reference to FROM-clause entry for table \"data\" | LINE 1: ...pi_id FROM Team_Attributes ta WHERE team_api_id = data.team_... | ^ | There is an entry for table \"data\", but it cannot be referenced from this part of the query.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team_attributes, team", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_27", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH one AS ( SELECT date_trunc('year', date) as timeOne, COUNT(*) as trans_count FROM trans ORDER BY timeOne ), two AS ( SELECT date_trunc('year', date) as timeTwo, COUNT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count) as count FROM one, two ORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"trans.date\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN WITH one AS ( SELECT date_trunc('year', date) as tim... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "syntax_keyword_misuse", + "message": "The number of provided arguments (2) is greater than the maximum number of supported arguments (1). Line 1, Col: 270.\n NT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count\u001b[4m)\u001b[0m as count FROM one, two ORDER BY 1;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "logical_grouping_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "loan", + "one", + "trans", + "two" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_28", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH gen_transactions AS ( SELECT CustomerID, Amount FROM transactions_1k CROSS JOIN LATERAL generate_series(1, CAST(Amount AS INTEGER)) ) SELECT CustomerID, Amount, ROW_NUMBER() OVER (ORDER BY random()) AS rn FROM gen_transactions LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..._transactions AS ( SELECT CustomerID, Amount FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0927, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "gen_transactions", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_30", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.k_symbol, t.operation, t.amount, t.balance, a.frequency FROM trans t INNER JOIN account a ON t.account_id = a.account_id WHERE t.account_id = 1 AND t.type = 'PRIJEM' GROUP BY t.k_symbol", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"t.operation\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT t.k_symbol, t.operation, t.amount, t.balance,... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "trans" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_31", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT user_id, COUNT(*) AS num_consecutive_months FROM (SELECT user_id, purchase_date, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) AS month_date, ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD'))) - ROW_NUMBER() OVER(PARTITION BY user_id, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) - INTERVAL '1 month' * ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purcha", + "valid": false, + "errors": [ + { + "tag": "logical_windowing_error", + "message": "window functions are not allowed in window definitions | LINE 1: ...e || '-01', 'YYYY-MM-DD')) - INTERVAL '1 month' * ROW_NUMBER... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P20" + } + ], + "tags": [ + "logical_windowing_error" + ], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "purchase" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_32", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH tab_with_cardid AS (\n select split(cardid, '-', 3)ivm_arr,\n\n type,\n last_refresh_date\n FROM db.scema.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"as\" | LINE 8: ...UMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp OR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'table' does not exist in schema", + "taxonomy_category": "semantic", + "context": "table", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 71.\n ma.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) \u001b[4mas\u001b[0m temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\n\n\nRequired keyword: 'this' missing for . Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\nalias does not support CTE. Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "table" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_33", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT player_api_id, MAX(date), FIRST(overall_rating) FROM Player_Attributes GROUP BY player_api_id ORDER BY date desc;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function first(bigint) does not exist | LINE 1: EXPLAIN SELECT player_api_id, MAX(date), FIRST(overall_ratin... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_35", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "begin insert into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.WebsiteUrl, '.', '-'), charindex('@', replace(new.WebsiteUrl, '.', '-')) - 1);return new;end;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"insert\" | LINE 1: begin insert into profiles (Id, CreationDate, WebsiteUrl) se... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 12.\n begin \u001b[4minsert\u001b[0m into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.Webs", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_37", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "insert into event (event_id, event_name, event_date, type, notes, location, status) values ('recAlAwtBZ0Fqbr5K', 'Annual Gala', '2023-12-15T19:00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"insert\" | LINE 1: ...rand Ballroom', 'Open') on conflict (event_id) do insert int... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Unknown option DO. Line 1, Col: 251.\n :00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do \u001b[4minsert\u001b[0m into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');\n\nInvalid expression / Unexpected token. Line 1, Col: 244.\n :00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) \u001b[4mdo\u001b[0m insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_38", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION log_player_name_changes() RETURNS trigger AS $BODY$ BEGIN IF NEW.player_name <> OLD.player_name THEN INSERT INTO player_audits(player_id, old_player_name, changed_on) VALUES(OLD.id, OLD.player_name, now()); END IF; RETURN NEW; END; $BODY$ CREATE TRIGGER tr_change_playername AFTER UPDATE OF player_name ON player FOR EACH ROW EXECUTE PROCEDURE log_player_name_changes();", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"CREATE\" | LINE 1: ...yer_name, now()); END IF; RETURN NEW; END; $BODY$ CREATE TRI... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_39", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT userid, tag\nFROM preference_tag\nWHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text[] @> character varying[] | LINE 3: WHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]); | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "preference_tag" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_44", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.driverId, ((SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId) - (SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId)) AS total_points FROM results r GROUP BY r.driverId", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"races\" | LINE 1: ...SUM(r.points), 0) FROM results r WHERE r.raceId = races.race... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.15, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_50", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT home_team_api_id, AVG(home_team_goal) as avg_home_goals, AVG(away_team_goal) as avg_away_goals, SUM(home_team_goal) as total_home_goals, SUM(away_team_goal) as total_away_goals, MAX(home_team_goal) as max_home_goals, MIN(home_team_goal) as min_home_goals, COUNT(home_team_api_id) as count FROM Match GROUP BY home_team_api_id, date_part('hour', date);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function date_part(unknown, text) does not exist | LINE 1: ...d) as count FROM Match GROUP BY home_team_api_id, date_part(... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_55", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO loan (\n loan_id,\n account_id,\n date,\n amount,\n duration,\n payments,\n status\n)\nVALUES (\n DEFAULT,\n 2,\n '1996-04-29',\n 30276,\n 12,\n 2523.0,\n 'B'\n)\nON CONFLICT (loan_id, account_id, date)\nDO UPDATE\n SET amount = loan.amount + 1000;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"date\" of relation \"loan\" does not exist | LINE 4: date, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "amount" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'amount' does not exist in table 'loan' (referenced as 'loan.amount')", + "taxonomy_category": "semantic", + "context": "loan.amount" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_56", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "DELETE FROM cards WHERE (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm1 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) AND (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm2 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) LIMIT 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"LIMIT\" | LINE 1: ...AND rarity IS NOT NULL AND manaCost IS NOT NULL ) LIMIT 1000... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'setCode' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "setCode", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'rarity' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "rarity", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'manaCost' is ambiguous \u2014 exists in tables: norm2, norm1, cards", + "taxonomy_category": "semantic", + "context": "manaCost", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2385, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT-DELETE-SUBQUERY", + "clauses_present": [ + "DELETE", + "FROM", + "LIMIT", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "norm1", + "norm2" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_58", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET disp_id = 1 WHERE disp_id = 41;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card\" does not exist | LINE 1: EXPLAIN UPDATE card SET disp_id = 1 WHERE disp_id = 41; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_61", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH DataSource AS (\n SELECT\n *,\n MIN(CASE WHEN amount < 10 THEN gasstationid END)\n OVER (PARTITION BY customerid) AS first_issue_gasstation,\n ROW_NUMBER() OVER (PARTITION BY customerid ORDER BY gasstationid DESC) AS gasstation_id\n FROM transactions_1k\n WHERE gasstationid = (\n SELECT MAX(gasstationid)\n FROM transactions_1k\n WHERE customerid = transactions_1k.customerid\n )\n)\nSELECT\n customerid,\n transactionid,\n gasstationid,\n amount\nFROM DataSource\nWHERE\n (first_is", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 7: FROM transactions_1k | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.201, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "datasource", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_68", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO new_attendance (link_to_event, link_to_member, date)\n VALUES ('reciRZdAqNIKuMC96', 'recL94zpn6Xh6kQii', NOW())\n ON CONFLICT\n WHERE link_to_member='recL94zpn6Xh6kQii' DO NOTHING;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHERE\" | LINE 4: WHERE link_to_member='recL94zpn6Xh6kQii' DO NOTHING; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES", + "WHERE" + ], + "tables": [ + "new_attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_69", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "pg_advisory_xact_lock(lkhndl);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"pg_advisory_xact_lock\" | LINE 1: pg_advisory_xact_lock(lkhndl); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_71", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE INDEX ix_account ON account USING btree (district_id, frequency, date);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "relation \"ix_account\" already exists", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P07" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_72", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "create or replace view findcount(season, team_count) as\n select\n season,\n findteam(season) as team_count\n from (\n select distinct season\n from match\n where season >= '2008/2009'\n ) seasons;", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "cannot change data type of view column \"team_count\" from integer to double precision", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P16" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "findcount", + "match" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_73", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "select posttypeid\n case when tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from posts", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"when\" | LINE 2: case when tags like ('%bayesian%','%distributions%') | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 17.\n select posttypeid\n case \u001b[4mwhen\u001b[0m tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_74", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id last_update DESC;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"last_update\" | LINE 1: ...OM bond GROUP BY molecule_id ORDER BY molecule_id last_updat... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 98.\n SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id \u001b[4mlast_update\u001b[0m DESC;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_79", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT race_id, top(count(*), 5) as cnt FROM superhero group by gender_id", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function top(bigint, integer) does not exist | LINE 1: EXPLAIN SELECT race_id, top(count(*), 5) as cnt FROM superhe... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_85", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE (Date, Time, Amount) < ('2012-08-24', '10:00:00', 20);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT * FROM transactions_1k WHERE (Date, Time, Amo... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_86", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT client.gender, loan.amount, loan.duration, account.date FROM loan JOIN account ON loan.account_id = account.account_id JOIN client ON disp.client_id = client.client_id JOIN disp ON account.account_id = disp.account_id WHERE loan.date BETWEEN '1996-01-01' AND '1996-12-31';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...er, loan.amount, loan.duration, account.date FROM loan JOIN ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "client", + "disp", + "loan" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_89", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION GapFillInternal(s anyelement, v anyelement) RETURNS anyelement AS $$ DECLARE temp alias for $0; BEGIN F v IS NULL AND s NOTNULL THEN temp := s; ELSIF s IS NULL AND v NOTNULL THEN temp := v; ELSIF s NOTNULL AND v NOTNULL THEN temp := v; ELSE temp := NULL; END;END; $$ LANGUAGE PLPGSQL;CREATE AGGREGATE GapFill(anyelement) (SFUNC=GapFillInternal, STYPE=anyelement);SELECT id, publisher_id, height_cm, weight_kg, GapFill(height_cm) OVER (PARTITION BY publisher_id ORDER BY id)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"F\" | LINE 1: ...anyelement AS $$ DECLARE temp alias for $0; BEGIN F v IS NUL... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_93", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT set_translations.language\n CASE WHEN set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'common'\n ELSE 'not common'\n END\n FROM set_translations", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHEN\" | LINE 2: CASE WHEN set_translations.language IN (SELECT... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 23.\n SELECT set_translations.language\n CASE \u001b[4mWHEN\u001b[0m set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'com", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_94", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$ DECLARE i integer; BEGIN\n FOREACH i IN ARRAY[11, 20]::integer[] LOOP\n RAISE NOTICE 'Value: %', i;\n UPDATE Player_Attributes SET overall_rating = i\n WHERE player_api_id = ANY (ARRAY[505942, 155782]::integer[])\n AND date = ANY (ARRAY['2016-02-18 00:00:00', '2015-10-16 00:00:00']::text[]);\n END LOOP;\n END $$;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 2: FOREACH i IN ARRAY[11, 20]::integer[] LOOP | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_95", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT resultId FROM results WHERE to_tsvector(results.fastestLapTime) @@ to_tsquery('1:35.405');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error in tsquery: \"1:35.405\"", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_100", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.team_name, o.outcome FROM (VALUES('Team A'),('Team B')) AS t(team_name) JOIN (VALUES('win'),('lose'),('draw')) AS o(outcome);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \";\" | LINE 1: ..._name) JOIN (VALUES('win'),('lose'),('draw')) AS o(outcome); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.026, + "pattern_signature": "SELECT-FROM-JOIN-VALUES", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "VALUES" + ], + "tables": [], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_103", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO historical_rating (player_fifa_api_id, player_api_id, grouped_rating) SELECT player_fifa_api_id, player_api_id AS grouped_rating FROM player_attributes GROUP BY player_fifa_api_id, player_api_id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "INSERT has more target columns than expressions | LINE 1: ...orical_rating (player_fifa_api_id, player_api_id, grouped_ra... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: historical_rating, player_attributes", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: historical_rating, player_attributes", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "SELECT-FROM-GROUP-INSERT", + "clauses_present": [ + "FROM", + "GROUP", + "INSERT", + "SELECT" + ], + "tables": [ + "historical_rating", + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_104", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT id, acceptedanswerid, posttypeid, score FROM posts WHERE score >= 20 OR acceptedanswerid IS NOT NULL AND score >= 20 GROUP BY id, acceptedanswerid;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"acceptedanswerid\" does not exist | LINE 1: EXPLAIN SELECT DISTINCT id, acceptedanswerid, posttypeid, sc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'acceptedanswerid' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "acceptedanswerid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "score", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0385, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_107", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT percentile_cont(0.5) within group (ORDER by releasedate) FROM sets", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function percentile_cont(numeric, date) does not exist | LINE 1: EXPLAIN SELECT percentile_cont(0.5) within group (ORDER by r... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "sets" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_110", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.league_id) SELECT * FROM recuree", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"recuree\" | LINE 1: ...ue UNION SELECT id, name FROM League) , RECURSIVE recuree AS... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'recuree' does not exist in schema", + "taxonomy_category": "semantic", + "context": "recuree", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting (. Line 1, Col: 108.\n ITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE \u001b[4mrecuree\u001b[0m AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON \n\nRequired keyword: 'expressions' missing for . Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\nExpecting ). Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "league", + "recuree", + "tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_111", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "SELECT *\nFROM superhero.\"%_id\";", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"superhero.%_id\" does not exist | LINE 2: FROM superhero.\"%_id\"; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table '%_id' does not exist in schema", + "taxonomy_category": "semantic", + "context": "%_id", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "%_id" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_113", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n sub.raceId,\n sub.t[1] AS \"Lap_Time_Race1\",\n sub.t[2] AS \"Lap_Time_Race2\",\n sub.t[3] AS \"Lap_Time_Race3\"\nFROM (\n SELECT\n driverId,\n raceId,\n ARRAY_AGG(milliseconds ORDER BY lap) AS t\n FROM lapTimes\n WHERE driverId = 1\n GROUP BY driverId\n) AS sub\nORDER BY sub.raceId;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"laptimes.raceid\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 9: raceId, | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "laptimes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_120", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET full_name = 'Superman' JOIN team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team_member_superhero.team_member_id = team_member.id WHERE team_id = 91;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JOIN\" | LINE 1: ...PLAIN UPDATE superhero SET full_name = 'Superman' JOIN team_... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n UPDATE superhero SET full_name = 'Superman' \u001b[4mJOIN\u001b[0m team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_123", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION reindex_superhero_ids(IN BIGINT) RETURNS VOID LANGUAGE SQL AS $$ CREATE TEMPORARY SEQUENCE id_seq_temp MINVALUE 1 START WITH 1 INCREMENT BY 1; ALTER SEQUENCE id_seq_temp RESTART; UPDATE superhero SET hair_colour_id=hair_colour_id+2000 WHERE publisher_id=$1; UPDATE superhero SET hair_colour_id=nextval('id_seq_temp') WHERE publisher_id=$1; $$;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"id_seq_temp\" does not exist | LINE 1: ...d=$1; UPDATE superhero SET hair_colour_id=nextval('id_seq_te... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "reindex_superhero_ids" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_129", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO member(member_id, first_name, last_name) VALUES ('new_member_id', 'John', 'Doe','rec06DF6vZ1CyPKpc') ON CONFLICT (member_id) DO UPDATE SET first_name=excluded.first_name, last_name=excluded.last_name;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "INSERT has more expressions than target columns | LINE 1: ...last_name) VALUES ('new_member_id', 'John', 'Doe','rec06DF6v... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "member" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_130", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS streak_count, 'April Meeting' AS event_name, 'MST' AS timezone, MIN(event_date) AS start_date, MAX(event_date) AS end_date FROM attendance WHERE event_name = 'April Meeting' GROUP BY DATE_TRUNC('day', event_date AT TIME ZONE 'UTC' AT TIME ZONE 'MST') ORDER BY end_date DESC LIMIT 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"event_date\" does not exist | LINE 1: ...il Meeting' AS event_name, 'MST' AS timezone, MIN(event_date... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_131", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DATE_TRUNC('day', to_timestamp(transaction_timestamp / 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC('day', transaction_timestamp)", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function date_trunc(unknown, bigint) does not exist | LINE 1: .../ 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_137", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS card, account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, frequency TEXT NOT NULL, date DATE NOT NULL, disp_id INT NOT NULL, FOREIGN KEY (disp_id) REFERENCES disp(disp_id) ON UPDATE CASCADE ON DELETE CASCADE);CREATE TABLE disp (disp_id INT PRIMARY KEY NOT NULL, client_id INT NOT NULL, account_id INT NOT NULL, type TEXT NOT NULL, FOREIGN KEY (account_id) REFERENCES account(account_id) ON UPDATE CASCADE ON DELETE CASCADE);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot drop desired object(s) because other objects depend on them | constraint trans_account_id_fkey on table trans depends on table account | constraint order_account_id_fkey on table \"order\" depends on table account | Use DROP ... CASCADE to drop the dependent objects too.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "2BP01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 26.\n DROP TABLE IF EXISTS card\u001b[4m,\u001b[0m account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_unknown_error", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_138", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COALESCE(json_agg(CASE WHEN client.client_id IS NULL THEN NULL ELSE json_build_object('client_id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS clients FROM client;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"clients\" | LINE 1: ...birth_date', client.birth_date) END), '[]') AS AS clients FR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 207.\n _id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS \u001b[4mclients\u001b[0m FROM client;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_139", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "select * from transactions_1k e\nwhere exists\n ( select * from transactions_1k e2\n where e.date=e2.date and e.time=e2.time\n and e.cardid=e2.cardid\n and e.gasstationid=e2.gasstationid\n and e.productid='2' and e2.productid='5') order by e.date asc;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN select * from transactions_1k e | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0771, + "pattern_signature": "SELECT-FROM-WHERE-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_140", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, amount as cum_sum, 1 as bucket from transfer where id = 1 union all select transfer.id, (case when cum_sum + amount > 20 then amount else cum_sum + amount end), (case when cum_sum + amount > 20 then bucket + 1 else bucket end) from cte join transfer on transfer.id = cte.id + 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"cte\" does not exist | LINE 1: ...amount > 20 then bucket + 1 else bucket end) from cte join t... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'cte' does not exist in schema", + "taxonomy_category": "semantic", + "context": "cte", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "cte", + "transfer" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_141", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceid mode() within group(order by laps) as modal_laps FROM results;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: EXPLAIN SELECT raceid mode() within group(order by laps) as ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 19.\n SELECT raceid mode\u001b[4m(\u001b[0m) within group(order by laps) as modal_laps FROM results;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_143", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "update match set stage = stage + 1 where id = 'match1';", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type bigint: \"match1\" | LINE 1: ...LAIN update match set stage = stage + 1 where id = 'match1'; | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + } + ], + "tags": [ + "value_format_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_148", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH player_names AS (SELECT 1 AS source, ROW_NUMBER() OVER (ORDER BY player_name) AS row_number, CONCAT(player_name, '(', LEFT(birthday, 4), ')') AS dest FROM player_table), birth_year_summary AS (SELECT 2 AS source, ROW_NUMBER() OVER (ORDER BY COUNT(*), LEFT(birthday, 4)) AS row_number, CONCAT('There are a total of ', COUNT(*), ' player', CASE WHEN COUNT(*) > 1 THEN 's' ELSE '' END, ' born in ', LEFT(birthday, 4), '.') AS dest FROM player_table GROUP BY LEFT(birthday, 4)) SELECT dest FROM (SEL", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"row_num\" does not exist | LINE 1: ...OM birth_year_summary) AS combined_results ORDER BY ROW_NUM; | ^ | Perhaps you meant to reference the column \"combined_results.row_number\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1292, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "birth_year_summary", + "player_names", + "player_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_153", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "WITH RECURSIVE cte AS ( SELECT id, parent_id, color FROM superhero2 WHERE parent_id IS NULL UNION ALL SELECT s.id, s.parent_id, CASE WHEN c1.color IS NULL THEN c2.color WHEN c2.color IS NULL THEN c1.color WHEN c1.color = c2.color THEN c1.color ELSE 'gray' END AS color FROM superhero2 s LEFT JOIN cte c1 ON s.id = c1.parent_id LEFT JOIN cte c2 ON s.id = c2.parent_id ) UPDATE superhero2 SET color = cte.color FROM cte WHERE superhero2.id = cte.id", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "recursive reference to query \"cte\" must not appear within an outer join | LINE 1: ...E 'gray' END AS color FROM superhero2 s LEFT JOIN cte c1 ON ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P19" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-UPDATE", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "UPDATE", + "WHERE", + "WITH" + ], + "tables": [ + "cte", + "superhero2" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_155", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\nFROM circuit_json;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FROM\" | LINE 3: FROM circuit_json; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 3, Col: 4.\n SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\n\u001b[4mFROM\u001b[0m circuit_json;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_156", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT y.district_id,\n CASE WHEN y.status IN ('A', 'B') THEN array_agg(loan_id) END AS type_A_B,\n CASE WHEN y.status = 'C' THEN array_agg(loan_id) END AS type_C\nFROM (\n SELECT x.district_id, l.loan_id, l.status\n FROM loan l\n JOIN account x ON l.account_id = x.account_id\n) y\nGROUP BY 1, y.status\nORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 6: FROM loan l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1385, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_160", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "select * from crosstab ('select id, uuid, text from ruling order by 1,2') AS final_result(id int, uuid1 text, uuid2 text, uuid3 text);", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function crosstab(unknown) does not exist | LINE 1: EXPLAIN select * from crosstab ('select id, uuid, text from ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_161", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.*\nFROM cards_info c\nWHERE NOT EXISTS (\n SELECT 1\n FROM card_choice cc\n WHERE cc.card_id = c.id\n AND c.id = ANY (cc.non_valid_cards)\n);", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "op ANY/ALL (array) requires array on right side | LINE 7: AND c.id = ANY (cc.non_valid_cards) | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42809" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "card_choice", + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_165", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM circuits WHERE ST_DWithin(ST_SetSRID(ST_MakePoint(lng, lat), 4326)::geography, ST_ClosestPoint((ST_MakePoint(lng, lat), 4326)::geography, ST_Collect(Array[ST_SetSRID(ST_MakePoint(2.76083, 101.73800), 4326)::geography, ST_SetSRID(ST_MakePoint(26.03250, 50.51060), 4326)::geography])), 1000000, FALSE);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "cannot cast type record to geography | LINE 1: ...hy, ST_ClosestPoint((ST_MakePoint(lng, lat), 4326)::geograph... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42846" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "circuits" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_169", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "insert into card_counters (card_name, counters) values ('Lightning Bolt', array[2,0,2,1]) on conflict (card_name) do update set counters = array_agg(unnest(card_counters.counters) + unnest(array[2,0,2,1]))", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "set-returning functions are not allowed in UPDATE | LINE 1: ...ct (card_name) do update set counters = array_agg(unnest(car... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "card_counters" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_175", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE FUNCTION calculate_loan_status()\n RETURNS SETOF loan_last\n AS $$\n DECLARE temp_table TABLE (loan_id int, status text);\n BEGIN INSERT INTO temp_table\n SELECT loan_id, status FROM loan_first WHERE status = 'A';\n INSERT INTO loan_last SELECT loan_id, status FROM temp_table;\n RETURN;\n END;\n $$ LANGUAGE plpgsql;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "type \"loan_last\" does not exist", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42704" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_177", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ID, Date, GOT, GPT FROM Laboratory GROUP BY ID HAVING COUNT(ID) > 1 ORDER BY Date DESC", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"laboratory.date\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT ID, Date, GOT, GPT FROM Laboratory GROUP BY I... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_182", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select jsonb_set(t.data, '{purchaseurls}', (select jsonb_agg(case when v.value::text ~ 'tcgplayer' or v.value::text ~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_array_elements(t.data -> 'purchaseurls') v)) from cards_info", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 1: ...~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_ar... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_186", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "create or replace function setup_vector_store(table_name text) returns void language plpgsql as $$ begin execute 'drop function if exists match_strategies(int, jsonb)'; execute format('create table %I ( id bigint primary key generated always as identity, description text, metadata jsonb )', table_name); execute format('create function match_strategies ( match_count int default null, filter jsonb default \"{}\"::jsonb ) returns table ( id bigint, description text, metadata jsonb, similarity float )", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"return\" | LINE 1: ..., similarity float ) language plpgsql as $$ begin return que... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_191", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT match_id, match_date FROM detail WHERE match_details @@ '$.player_stats[*] ? (@.player_id == :player_id).goals > 0';", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "(sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'player_id' | [SQL: EXPLAIN SELECT match_id, match_date FROM detail WHERE match_details @@ '$.player_stats[*] ? (@.player_id == %(player_id)s).goals > 0';] | (Background on this error at: https://sqlalche.me/e/20/cd3x)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "detail" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_194", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE UNIQUE INDEX conditional_unique_index ON match_results (match_id, team_id) WHERE (SELECT COUNT(*) FROM match_results t2 WHERE t2.match_id = match_results.match_id AND t2.team_id = match_results.team_id) = 1;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot use subquery in index predicate | LINE 1: ..._index ON match_results (match_id, team_id) WHERE (SELECT CO... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "match_results" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_196", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT attribute_name, to_number(attribute_name) FROM attribute;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_number(text) does not exist | LINE 1: EXPLAIN SELECT attribute_name, to_number(attribute_name) FRO... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_197", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT molecule_id, COUNT(*) FILTER (WHERE COUNT(*) > 5) AS total_bonds FROM bond GROUP BY molecule_id;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in FILTER | LINE 1: ...XPLAIN SELECT molecule_id, COUNT(*) FILTER (WHERE COUNT(*) >... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-FILTER", + "clauses_present": [ + "FILTER", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_200", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT county, AVG(avgscrread + avgscrmath + avgscrwrite) / 3 AS avg_total_sat FROM satscores GROUP BY county ORDER BY avg_total_sat DESC LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"county\" does not exist | LINE 1: EXPLAIN SELECT county, AVG(avgscrread + avgscrmath + avgscrw... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_201", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH vars AS ((select count(*) from laboratory) AS vars_id) select * from laboratory where id=vars.vars_id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"AS\" | LINE 1: ...N WITH vars AS ((select count(*) from laboratory) AS vars_id... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_202", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM match_location WHERE ST_INTERSECTS(location, CIRCLE(POINT(-73.935242, 40.730610), 2));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"match_location\" does not exist | LINE 1: EXPLAIN SELECT * FROM match_location WHERE ST_INTERSECTS(loc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'match_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "match_location", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match_location" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_203", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "INSERT INTO learners\n (\"Age\", \"Gender\", \"Geographic_Location\", \"Socioeconomic_Background\",\n \"Education_Level\", \"Previous_Academic_Performance\", \"Language_Proficiency\",\n \"Preferred_Learning_Medium\", \"Learning_Pace\", \"Engagement_History\")\nVALUES\n (18,\n 'Male',\n 'Urban',\n 'Low',\n 'UndergraduateUndergraduateUndergraduate',\n 88.55,\n 'Intermediate',\n 'Video',\n 'Moderate',\n 6);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "value too long for type character varying(15)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "22001" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_204", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n x.curriculum_id,\n ARRAY_LENGTH(x.combined_array, 1) AS distinct_count\nFROM\n(\n\nSELECT\n c.curriculum_id,\n ARRAY[e.\"Content_Type\", e.\"Platform_Used\"] AS combined_array\n FROM curriculum_resources cr\n JOIN educational_resources e\n ON cr.resource_key = e.resource_key\n JOIN curricula c\n ON c.curriculum_id = cr.curriculum_id\n\n UNION\nSELECT\n c2.curriculum_id,\n ARRAY[cr2.recommended] AS combined_array\n FROM curriculum_resources cr2\n JOI", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "UNION could not convert type boolean[] to character varying[] | LINE 19: ARRAY[cr2.recommended] AS combined_array | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42846" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.1885, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-UNION-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "curricula", + "curriculum_resources", + "educational_resources" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_213", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result FOR attribute_name IN (Strength, Speed, Intelligence))", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"FOR\" | LINE 1: ...e, result FROM superhero_performance PIVOT(result FOR attrib... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Strength", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Speed' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Speed", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Intelligence' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Intelligence", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expecting an aggregation function in PIVOT. Line 1, Col: 103.\n SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(\u001b[4mresult\u001b[0m FOR attribute_name IN (Strength, Speed, Intelligence))\n\nRequired keyword: 'this' missing for . Line 1, Col: 107.\n CT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result \u001b[4mFOR\u001b[0m attribute_name IN (Strength, Speed, Intelligence))", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero_performance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_214", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) FROM laboratory WHERE date_part('year', date) = date_part('year', CURRENT_DATE) AND date_part('month', date) = date_part('month', CURRENT_DATE) AND date [I don't know what to put here];", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"don\" | LINE 1: ...e) = date_part('month', CURRENT_DATE) AND date [I don't know... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unterminated_string", + "message": "Unterminated quoted string", + "taxonomy_category": "syntax", + "context": "Error tokenizing 'NT_DATE) AND date [I don't know what to put here]'" + } + ], + "tags": [ + "syntax_error", + "syntax_unterminated_string" + ] + }, + { + "instance_id": "PostgreSQL_218", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET type = ( SELECT type, client_id FROM disp WHERE card.disp_id = disp.disp_id );", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card\" does not exist | LINE 1: EXPLAIN UPDATE card SET type = ( SELECT type, client_id FROM... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "card", + "disp" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_219", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE card (card_id SERIAL PRIMARY KEY,loan_id INT UNIQUE,type TEXT NOT NULL,issued DATE NOT NULL,CONSTRAINT fk_loan_id FOREIGN KEY (loan_id) REFERENCES loan(loan_id) ON DELETE SET NULL);ALTER TABLE loan ADD CONSTRAINT fk_card_loan FOREIGN KEY (loan_id) REFERENCES card(loan_id) ON DELETE CASCADE;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card", + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_220", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$ DECLARE value RECORD[]; BEGIN SELECT t FROM transactions_1k t LIMIT 1 INTO value[1]; SELECT c FROM customers c LIMIT 1 INTO value[2]; RAISE NOTICE 'Transaction: %', value[1]; RAISE NOTICE 'Customer: %', value[2]; END $$;", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "variable \"value\" has pseudo-type record[] | compilation of PL/pgSQL function \"inline_code_block\" near line 1", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_221", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE loan l SET status = 'updated_status', date = 'new_date', amount = 'new_amount' WHERE l.loan_id = 'loan_id_value' AND l.status = 'current_status';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: EXPLAIN UPDATE loan l SET status = 'updated_status', date = ... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_222", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS patients, (SELECT * FROM doctors) AS doctors, (SELECT * FROM appointments) AS appointments;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \")\" | LINE 1: EXPLAIN SELECT coalesce(_agg(patients), '[]'::) as patients,... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expected type. Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nRequired keyword: 'to' missing for . Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nExpected type. Line 1, Col: 84.\n SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::\u001b[4m)\u001b[0m as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS p\n\n... and 3 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.2292, + "pattern_signature": "SELECT-FROM-JOIN-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "appointments", + "doctors", + "patients" + ], + "num_joins": 2, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_223", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE patients_info\nSET general_info = jsonb_set(general_info, '{accept_appointments}', '\"false\"');", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"patients_info\" does not exist | LINE 1: EXPLAIN UPDATE patients_info | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'patients_info' does not exist in schema", + "taxonomy_category": "semantic", + "context": "patients_info", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "patients_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_224", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.molecule_id, b.date AS buy_date, s.date AS sell_date, s.molecules, b.usd_total AS buy_usd_total, s.usd_total AS sell_usd_total FROM transaction b JOIN transaction s ON b.molecule_id = s.molecule_id WHERE b.sell = 0 AND s.sell = 1 ORDER BY b.date, s.date", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: boolean = integer | LINE 1: ...n s ON b.molecule_id = s.molecule_id WHERE b.sell = 0 AND s.... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transaction" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_227", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "CREATE VIEW overview AS SELECT count(*) AS learners_count FROM learners, SELECT count(*) AS institutions_count FROM institutions, SELECT count(*) AS curricula_count FROM curricula", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELECT\" | LINE 1: ... SELECT count(*) AS learners_count FROM learners, SELECT cou... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1125, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "curricula", + "institutions", + "learners", + "overview" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_228", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT patients.patient_id, demographics.height, treatment_and_followup.primary_pathology_karnofsky_performance_score, MIN(primary_pathology_karnofsky_performance_score) AS min_performance_score FROM patients JOIN treatment_and_followup ON patients.patient_id = treatment_and_followup.patient_id JOIN demographics ON patients.patient_id = demographics.patient_id WHERE informed_consent_verified = TRUE GROUP BY patients.patient_id;", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"demographics.height\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT patients.patient_id, demographics.height, tre... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "demographics", + "patients", + "treatment_and_followup" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_229", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE A(GroupNum, n, RollingSum, id) AS (\n SELECT 1, Performance_Prediction, Performance_Prediction, prediction_code\n FROM performance_predictions\n ORDER BY prediction_code ASC\n LIMIT 1\n UNION ALL\n SELECT\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN GroupNum + 1\n ELSE GroupNum\n END,\n P.Performance_Prediction,\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"UNION\" | LINE 6: UNION ALL | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.099, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WINDOW-UNION-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "a", + "performance_predictions" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_231", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT g.GasStationID FROM transactions_1k t JOIN gasstations g\nON t.GasStationID = g.GasStationID GROUP BY g.GasStationID\nHAVING SUM(t.Amount * t.Price) / SUM(t.Amount * t.Price) OVER (PARTITION BY t.CustomerID) >= 0.7", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT g.GasStationID FROM transactions_1k t JOIN ga... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0667, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-WINDOW", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "WINDOW" + ], + "tables": [ + "gasstations", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_232", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE WHEN c.type = 'gold' THEN 'Gold' ELSE 'Non-Gold'\nEND AS card_type_group, COUNT(l.loan_id) AS loan_count\nFROM loan l\nJOIN disp d ON l.account_id = d.account_id\nJOIN card c ON d.disp_id = c.disp_id\nGROUP BY c.type", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 3: FROM loan l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "card", + "disp", + "loan" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_234", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (CustomerID) * FROM transactions_1k ORDER BY Date DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT DISTINCT ON (CustomerID) * FROM transactions_... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_235", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "MERGE INTO treatment_and_followup_backup b USING treatment_and_followup_latest a ON b.patient_id = a.patient_id WHEN MATCHED THEN UPDATE SET followup_no = a.followup_no, primary_pathology_karnofsky_performance_score = a.primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cancer_oncology_group = a.primary_pathology_eastern_cancer_oncology_group WHEN NOT MATCHED THEN INSERT (patient_id, followup_no, primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cance", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"MERGE\" | LINE 1: MERGE INTO treatment_and_followup_backup b USING treatment_a... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'followup_no' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "followup_no" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'primary_pathology_karnofsky_performance_score' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "primary_pathology_karnofsky_performance_score" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'primary_pathology_eastern_cancer_oncology_group' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "primary_pathology_eastern_cancer_oncology_group" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'patient_id' is ambiguous \u2014 exists in tables: treatment_and_followup_backup, treatment_and_followup_latest", + "taxonomy_category": "semantic", + "context": "patient_id" + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "INSERT-UPDATE-MERGE", + "clauses_present": [ + "INSERT", + "MERGE", + "UPDATE" + ], + "tables": [ + "treatment_and_followup_backup", + "treatment_and_followup_latest" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_237", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Engagement_Level, MAX(rating), MIN(rating) FROM resource_usage JOIN target_labels ON resource_usage.learner_code = target_labels.learner_code GROUP BY Engagement_Level;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"engagement_level\" does not exist | LINE 1: EXPLAIN SELECT Engagement_Level, MAX(rating), MIN(rating) FR... | ^ | Perhaps you meant to reference the column \"target_labels.Engagement_Level\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0594, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "resource_usage", + "target_labels" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_239", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, CASE WHEN Geographic_Location = 'Urban' THEN 1 WHEN Geographic_Location = 'Rural' THEN 2 ELSE 0 END AS location_id, AVG(Pre_Test_Score) AS average_pre_test_score FROM learners WHERE Engagement_History > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"$\" | LINE 1: ...ciency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_st... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Pre_Test_Score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Pre_Test_Score", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 318.\n tory > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN $\u001b[4m{\u001b[0msocio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' \n\nRequired keyword: 'this' missing for . Line 1, Col: 395.\n diate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN $\u001b[4m{\u001b[0msocio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0552, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_240", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH src(id,geom) as (values (1, 'linestring(0 0, 0 10)'::geometry), (2, 'linestring(0 10, 0 11)'::geometry), (3, 'linestring(1 1, 0 5)'::geometry), (4, 'linestring(1 1, 2 2)'::geometry)) SELECT a.id, st_asText(st_intersection(a.geom, b.geom)) FROM src AS a WHERE NOT EXISTS (SELECT 1 FROM src as b WHERE a.id != b.id AND ST_Toches(a.geom, b.geom) AND ST_Equals(ST_EndPoint(b.geom), ST_Intersection(a.geom, b.geom)));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"b\" | LINE 1: ...)) SELECT a.id, st_asText(st_intersection(a.geom, b.geom)) F... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0917, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "VALUES", + "WHERE", + "WITH" + ], + "tables": [ + "src" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_241", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "select device_info::json ->> 'SerialNumber' as SerialNumber, cto ->> 'ChannelId'::INT AS channelid, cto ->> 'ChannelName' AS ChannelName from device_details CROSS JOIN LATERAL json_array_elements(device_info::json ->'ChannelListDto') Channels(cto);", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type integer: \"ChannelId\" | LINE 1: ...:json ->> 'SerialNumber' as SerialNumber, cto ->> 'ChannelId... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'cto' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "cto", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "value_format_mismatch", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "device_details" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_248", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "(SELECT COUNT(*) FROM sp_artists WHERE pop > 50) / (SELECT COUNT(*) FROM sp_artists);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"/\" | LINE 1: (SELECT COUNT(*) FROM sp_artists WHERE pop > 50) / (SELECT C... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_artists" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_250", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM sp_album_ctb WHERE (alb, art, feat_arts, start_date) IN (SELECT alb, art, feat_arts, end_date + INTERVAL '1 day' FROM sp_album_ctb);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"end_date\" does not exist | LINE 1: ...arts, start_date) IN (SELECT alb, art, feat_arts, end_date +... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_album_ctb" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_252", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT l.learner_code, l.gender, r.resource_key, 'Regular Feedback' as FeedbackType, r.feedback as UserFeedback FROM learners l INNER JOIN resource_usage r ON l.learner_code = r.learner_code WHERE UserFeedback = ANY(ARRAY['Negative']) UNION ALL SELECT l.learner_code, l.gender, 0 as resource_key, 'Synthetic Feedback' as FeedbackType, CASE WHEN o.learner_satisfaction_score < 3 THEN 'Negative' ELSE 'Positive' END as UserFeedback FROM learners l INNER JOIN outcomes o ON l.learner_code = o.learner_co", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column l.gender does not exist | LINE 1: EXPLAIN SELECT l.learner_code, l.gender, r.resource_key, 'Re... | ^ | Perhaps you meant to reference the column \"l.Gender\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "learners", + "outcomes", + "resource_usage" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_253", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM city ORDER BY COALESCE(SUBSTRING(name FROM '[A-Z]+'), ''), COALESCE(SUBSTRING(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\uff1b\" | LINE 1: ... COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 190.\n NG(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\u001b[4m\uff1b\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "city" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_255", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ST_Touches(ol.geom, l.geom)\nFROM institution_location ol, learner_institution_location l\nWHERE ST_Touches(ol.geom, l.geom)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"institution_location\" does not exist | LINE 2: FROM institution_location ol, learner_institution_location l | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'institution_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "institution_location", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'learner_institution_location' does not exist in schema", + "taxonomy_category": "semantic", + "context": "learner_institution_location", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "institution_location", + "learner_institution_location" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_257", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH sales AS ( SELECT \"gasstationid\" AS \"GasstationId\", \"customerid\" AS \"CustomerId\", \"date\" AS \"SaleDate\", \"amount\" AS \"Amount\" FROM \"transactions_1k\" ), initial_purchase AS ( SELECT \"GasstationId\", \"CustomerId\", MIN(CAST(\"SaleDate\" AS date)) AS \"FirstPurchaseDate\" FROM sales GROUP BY \"GasstationId\", \"CustomerId\" ), customer_wages AS ( SELECT i.\"CustomerId\", s.* FROM sales s JOIN initial_purchase i ON s.\"CustomerId\" = i.\"CustomerId\" WHERE s.\"SaleDate\" >= i.\"FirstPurchaseDate\" ORDER BY i.\"Custo", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..., \"date\" AS \"SaleDate\", \"amount\" AS \"Amount\" FROM \"transacti... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "customer_wages", + "initial_purchase", + "sales", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_258", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE (SELECT quote_ident(c.table_schema) || '.' || quote_ident(c.table_name) || ' RENAME \"' || c.column_name || '\" TO ' || quote_ident(lower(c.column_name)) || ';' As ddlsql FROM information_schema.columns As c WHERE c.table_schema NOT IN('information_schema', 'pg_catalog') AND c.column_name <> lower(c.column_name) ORDER BY c.table_schema, c.table_name, c.column_name);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: ALTER TABLE (SELECT quote_ident(c.table_schema) || '.' || qu... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_266", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH t1 AS ( SELECT e.event_id FROM event e LEFT JOIN attendance a ON e.event_id = a.link_to_event ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at end of input | LINE 1: ...t e INNEr JOIN attendance a ON e.event_id = a.link_to_event) | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Failed to parse any statement following CTE. Line 1, Col: 197.\n nt ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event\u001b[4m)\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_267", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.* FROM transactions_1k LEFT JOIN customers ON transactions_1k.customerid = customers.customerid LIMIT 5", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT transactions_1k.* FROM transactions_1k LEFT J... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_269", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(cost) AS total_cost, link_to_member FROM expense GROUP BY link_to_budget", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"expense.link_to_member\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT SUM(cost) AS total_cost, link_to_member FROM ... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "expense" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_272", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELEC Player.player_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_attributes ON Player.player_api_id = Player_Attributes.player_api_id WHERE Player_Attributes.overall_rating = 68", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELEC\" | LINE 1: SELEC Player.player_api_id, Player.player_name, Player_Attri... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 13.\n SELEC Player\u001b[4m.\u001b[0mplayer_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_att", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_274", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cdscode, COUNT(cdscode) FROM schools WHERE district = 'Alameda County Office of Education' LIMIT 1", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"schools.cdscode\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT cdscode, COUNT(cdscode) FROM schools WHERE di... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_276", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT status, SUM(amount) AS total_amount, SUM(payments) AS total_payments, (total_amount + total_payments) AS s FROM loan GROUP BY status", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...yments, (total_amount + total_payments) AS s FROM loan GROUP... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_278", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, b.name AS BadgeName, b.date AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000 AND b.name = 'Teacher' UNION ALL SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, NULL AS BadgeName, NULL AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "UNION types timestamp with time zone and text cannot be matched | LINE 1: ..., u.displayname, u.reputation, NULL AS BadgeName, NULL AS Ba... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "badges", + "users" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_281", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT customerid, *, MAX(date) AS maxdate FROM transactions_1k", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...DISTINCT customerid, *, MAX(date) AS maxdate FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-DISTINCT-FROM", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_282", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and power = '2') THEN coalesce(watermark, '998') watermark WHEN (colors = 'R' and power = '0') THEN coalesce(watermark, '999') watermark END) watermark FROM cards", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"watermark\" | LINE 1: ... and power = '4') THEN coalesce(watermark, '996') watermark ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expected END after CASE. Line 1, Col: 84.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996'\u001b[4m)\u001b[0m watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (color\n\nExpecting ). Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow\n\nInvalid expression / Unexpected token. Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_283", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT posts.owneruserid, posts.tags, AVG(posts.score) AS AvgOfScore FROM posts WHERE posts.owneruserid = 183 AND posts.tags LIKE '%distribution%' AND EXISTS(SELECT creaiondate FROM posts AS pdates WHERE pdates.owneruserid = posts.owneruserid AND pdates.tags = posts.tags AND pdates.creaiondate = posts.creaiondate ORDER BY pdates.creaiondate DESC NULLS LAST LIMIT 5)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column posts.owneruserid does not exist | LINE 1: EXPLAIN SELECT posts.owneruserid, posts.tags, AVG(posts.scor... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'owneruserid' does not exist in table 'posts' (referenced as 'posts.owneruserid')", + "taxonomy_category": "semantic", + "context": "posts.owneruserid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'score' does not exist in table 'posts' (referenced as 'posts.score')", + "taxonomy_category": "semantic", + "context": "posts.score", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'creaiondate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "creaiondate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'creaiondate' does not exist in table 'posts' (referenced as 'posts.creaiondate')", + "taxonomy_category": "semantic", + "context": "posts.creaiondate", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_284", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT link_to_member, COUNT(DISTINCT DATE(event_date)) AS total_attendance_days FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] WITH cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link_to_member ORDER BY DATE(event_date)) AS rn FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AN", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WITH\" | LINE 1: ... AND '2023-12-31' GROUP BY link_to_member [split] WITH cte A... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 244.\n ent.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] \u001b[4mWITH\u001b[0m cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_286", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT t.customerid, p.description, MAX(t.date) FROM transactions_1k AS t INNER JOIN products AS p ON t.productid = p.productid GROUP BY t.customerid", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...ECT t.customerid, p.description, MAX(t.date) FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "products", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_287", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.CustomerID AS Customer1, t2.CustomerID AS Customer2, COUNT(*) AS Count FROM (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t1, (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t2 WHERE t1.ConcatenatedValue = t2.ConcatenatedValue GROUP BY Customer1, Customer2 ORDER BY Count DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.175, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_288", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DAILY_REVENUE AS (SELECT date, SUM(amount) AS TotalAmount FROM transactions_1k GROUP BY date ORDER BY date ASC NULLS FIRST), MOVING_AVG AS (SELECT date, SUM(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS TotalAmount, CAST(AVG(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS DECIMAL(10, 2)) AS AverageAmount FROM daily_revenue) SELECT * FROM moving_avg", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... AS (SELECT date, SUM(amount) AS TotalAmount FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "daily_revenue", + "moving_avg", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_289", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.department, COUNT(e.expense_id) AS cnt, e.cost AS highest_cost FROM expense AS e INNER JOIN member AS mem ON e.link_to_member = mem.member_id INNER JOIN major AS m ON mem.link_to_major = m.major_id GROUP BY m.department ORDER BY cnt DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"e.cost\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ... SELECT m.department, COUNT(e.expense_id) AS cnt, e.cost AS ... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "expense", + "major", + "member" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_291", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND ex.\"aCL IgG\" > 3.0)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"patient\" | LINE 1: ...LECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 59.\n SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM \u001b[4mpatient\u001b[0m pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND e", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_292", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(b.bond_id) AS total, b1.bond AS bond, b2.bond_type_dash AS bond_type_dash, b3.bond_type_equal AS bond_type_equal, b4.bond_type_hash AS bond_type_hash FROM bond AS b LEFT JOIN (SELECT bond_id, COUNT(*) AS bond FROM bond WHERE bond_id = 'TR000_1_2') AS b1 ON b1.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_dash FROM bond WHERE bond_type = '-') AS b2 ON b2.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_equal FROM bond WHERE bond_type = '=') ", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"bond.bond_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...S bond_type_hash FROM bond AS b LEFT JOIN (SELECT bond_id, C... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.3542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 4, + "num_subqueries": 4, + "num_ctes": 0, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_293", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id GROUP BY l.country_id HAVING l.country_id > 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 1: ...', name) FROM country c WHERE l.country_id = c.id GROUP BY l... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 101.\n UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id \u001b[4mGROUP BY\u001b[0m l.country_id HAVING l.country_id > 1000;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_ambiguous_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "FROM-WHERE-UPDATE", + "clauses_present": [ + "FROM", + "UPDATE", + "WHERE" + ], + "tables": [ + "country", + "league" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_294", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.*, rank := rank + 1 AS ranking FROM (SELECT 0 AS rank) AS init, results AS r JOIN drivers AS d ON r.driverid = d.driverid ORDER BY r.fastestlap ASC NULLS FIRST, d.dob ASC NULLS FIRST LIMIT 10", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \":=\" | LINE 1: EXPLAIN SELECT r.*, rank := rank + 1 AS ranking FROM (SELECT... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1521, + "pattern_signature": "SELECT-FROM-JOIN-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "drivers", + "results" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_295", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE CONCAT(date, ' ', time) BETWEEN CAST('2012-08-22' AS DATE) AND CAST('2012-08-23' AS DATE) ORDER BY amount DESC NULLS LAST LIMIT 3", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT * FROM transactions_1k WHERE CONCAT(date, ' '... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_297", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account.account_id, loan.loan_id, SUM(loan.amount) AS total_amount FROM account JOIN loan ON account.account_id = loan.account_id JOIN trans ON loan.account_id = trans.account_id WHERE loan.status LIKE '%A%' AND trans.type LIKE '%PRIJEM%' AND trans.type LIKE '%VYDAJ%' GROUP BY loan.loan_id ORDER BY account.account_id NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"loan\" does not exist | LINE 1: ...UM(loan.amount) AS total_amount FROM account JOIN loan ON ac... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'loan' does not exist in schema", + "taxonomy_category": "semantic", + "context": "loan", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1177, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "loan", + "trans" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_298", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT date, COUNT(*) FROM transactions_1k WHERE EXTRACT(DAY FROM date) IN (3, 24)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: EXPLAIN SELECT date, COUNT(*) FROM transactions_1k WHERE EXT... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_299", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SELECT 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district WHERE A8 = 4 [split] SELECT 4 AS RATES, COUNT(A9) FROM district WHERE A9 = 4 [split] SELECT 3 AS RATES, COUNT(A8) FROM district WHERE A8 = 3 [split] SELECT 3 AS RATES, COUNT(A9) FROM district WHERE A9 = 3", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 1: ... 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SE... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 70.\n SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] \u001b[4mSELECT\u001b[0m 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "district" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_302", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH Partitioned AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY CustomerID, Date ORDER BY CustomerID NULLS FIRST, Date NULLS FIRST) AS RowNumber FROM transactions_1k) SELECT *, CASE WHEN RowNumber > 1 THEN 0 ELSE COALESCE(CAST(AGE(CAST((SELECT MAX(Date) FROM transactions_1k WHERE Date < a.Date AND CustomerID = a.CustomerID) AS TIMESTAMP), CAST(a.Date AS TIMESTAMP)) AS BIGINT), 0) END AS Days_between FROM partitioned AS a", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... NULLS FIRST, Date NULLS FIRST) AS RowNumber FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.124, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "partitioned", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_304", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.transactionid, transactions_1k.date, transactions_1k.customerid, STRING_AGG(gasstations.gasstationid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS gasstation_ids, STRING_AGG(products.productid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS product_ids FROM transactions_1k LEFT JOIN gasstations ON transactions_1k.gasstationid = gasstations.gasstationid LEFT JOIN products ON transactions_1k.productid = products.productid WHERE NOT trans", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ...1k.transactionid NULLS FIRST) AS product_ids FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_305", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM budget GROUP BY link_to_event WHEN event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN 'Open' WHEN event_status = 'Open' THEN 'Open' WHEN event_status = 'Planning' THEN 'Planning' ELSE 'Unknown' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHEN\" | LINE 1: ...PLAIN SELECT * FROM budget GROUP BY link_to_event WHEN event... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n SELECT * FROM budget GROUP BY link_to_event \u001b[4mWHEN\u001b[0m event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_306", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.customerid, SUM(t.amount) FROM customers AS c INNER JOIN transactions_1k AS t ON c.customerid = t.customerid GROUP BY c.customerid", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"customers\" does not exist | LINE 1: EXPLAIN SELECT c.customerid, SUM(t.amount) FROM customers AS... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_307", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Time\") FROM cards) NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"Update_Time\" does not exist | LINE 1: ...HERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Ti... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_schema' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_schema", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Update_Time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Update_Time", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "tables" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_308", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.* FROM match AS m WHERE m.league_id = '1' GROUP BY m.date ORDER BY m.date ASC NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"m.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT m.* FROM match AS m WHERE m.league_id = '1' G... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_310", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"??\" | LINE 1: EXPLAIN UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Expected table name but got . Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');\n\nInvalid expression / Unexpected token. Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_311", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE content (id serial PRIMARY KEY NOT NULL, item_id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_item_id <> id)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"nested_item_id\" | LINE 1: ...er\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_ite... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Required keyword: 'expressions' missing for . Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)\n\nExpecting ). Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_312", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cd.*, fd.* FROM cards cd INNER JOIN foreign_data fd ON cd.uuid = fd.uuid WHERE cd.availability = 'mtgo,paper' ORDER BY cd.releaseDate DESC, cd.uuid, fd.id LIMIT 100;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column cd.releasedate does not exist | LINE 1: ...uid WHERE cd.availability = 'mtgo,paper' ORDER BY cd.release... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "foreign_data" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_313", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.col2, t.col3 FROM (SELECT '2023-01-01' AS col1, 'Some ruling text.' AS col2, (SELECT uuid FROM cards WHERE borderColor = 'black' AND layout = 'normal') AS col3 UNION ALL SELECT '2023-01-02' AS col1, 'Another ruling text.' AS col2, (SELECT uuid FROM cards WHERE isAlternative = 1) AS col3) t WHERE NOT EXISTS (SELECT 1 FROM rulings WHERE rulings.date = t.col1::date);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"date\" is of type date but expression is of type text | LINE 1: ...AIN INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.... | ^ | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_type_mismatch", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2521, + "pattern_signature": "SELECT-FROM-WHERE-UNION-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "cards", + "rulings" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_317", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT humidity_level, (humidity_level - LAG(humidity_level, 1) OVER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_humidity WHERE diff = 0 OR diff > 10", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"warehouse_humidity\" does not exist | LINE 1: ...ER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'warehouse_humidity' does not exist in schema", + "taxonomy_category": "semantic", + "context": "warehouse_humidity", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "warehouse_humidity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_318", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders@lpu.edu;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"members\" does not exist | LINE 1: EXPLAIN SELECT s.member_id FROM members AS s WHERE s.positio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'members' does not exist in schema", + "taxonomy_category": "semantic", + "context": "members", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 95.\n SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders\u001b[4m@\u001b[0mlpu.edu;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "members" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_319", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, SUM(count) AS COUNT, SUM(excerptpostid) AS EXCERPTPOSTID FROM backup_colour", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"backup_colour.id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT id, SUM(count) AS COUNT, SUM(excerptpostid) A... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "backup_colour" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_320", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id FROM cards JOIN decks ON cards.id = decks.card1_id WHERE decks.card1_id <> 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"decks\" does not exist | LINE 1: EXPLAIN SELECT id FROM cards JOIN decks ON cards.id = decks.... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'decks' does not exist in schema", + "taxonomy_category": "semantic", + "context": "decks", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_321", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, COUNT(*) FROM races", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"races.name\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT name, COUNT(*) FROM races | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_327", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT type, COUNT(*) AS type_count FROM card_type WHERE cardid IN (SELECT DISTINCT cardid FROM info) GROUP BY type ORDER BY type_count DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"card_type\" does not exist | LINE 1: EXPLAIN SELECT type, COUNT(*) AS type_count FROM card_type W... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card_type' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card_type", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "card_type", + "info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_328", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT results.score, scores.value, scores.segment FROM customer_scores AS scores JOIN customer_results AS results ON scores.segment = results.segment WHERE results.score >= scores.score GROUP BY scores.segment ORDER BY scores.customerid DESC NULLS LAST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"results.score\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT results.score, scores.value, scores.segment F... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'customer_scores' does not exist in schema", + "taxonomy_category": "semantic", + "context": "customer_scores", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'customer_results' does not exist in schema", + "taxonomy_category": "semantic", + "context": "customer_results", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "logical_grouping_error", + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "customer_results", + "customer_scores" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_329", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CHECK(id <> spouseid)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"CHECK\" | LINE 1: CHECK(id <> spouseid) | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_330", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE log_content (\"log_id\" INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, \"content\" VARCHAR(32) NOT NULL, \"no_of_chars\" INT NULL DEFAULT CHAR_LENGTH(\"content\"), PRIMARY KEY (\"log_id\"))", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "cannot use column reference in DEFAULT expression | LINE 1: ... NULL, \"no_of_chars\" INT NULL DEFAULT CHAR_LENGTH(\"content\")... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "log_content" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_332", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CASE WHEN amount_sold < 1000 THEN 'Under 1000' WHEN amount_sold BETWEEN 1000 AND 9999 THEN '1000 to 9999' WHEN amount_sold BETWEEN 10000 AND 49999 THEN '10000 to 49999' WHEN amount_sold >= 50000 THEN '50000 and above' END AS range, AVG(Count) AS avg FROM sales_data GROUP BY range", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"sales_data\" does not exist | LINE 1: ...0 and above' END AS range, AVG(Count) AS avg FROM sales_data... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'sales_data' does not exist in schema", + "taxonomy_category": "semantic", + "context": "sales_data", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_336", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < 40000);", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 1: SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'list' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "list" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_338", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.product_code, t1.product_id, t1.assign_key, STRING_AGG(t2.value_name, ',') FROM products_sample AS t1 LEFT JOIN value_list AS t2 ON t2.value_id::text = ANY(string_to_array(t1.assign_key, ',')) GROUP BY t1.assign_key", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"t1.product_code\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT t1.product_code, t1.product_id, t1.assign_key... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "products_sample", + "value_list" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_339", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, p.name, c.item, c.size FROM packages p LEFT JOIN contents c ON (c.packageid=p.id) WHERE (( p.id IN ( SELECT packageid FROM contents WHERE item='square' AND size='A' ) AND ( p.id IN ( SELECT packageid FROM contents WHERE item='circle' AND size='B' )) GROUP BY p.id HAVING ( SELECT COUNT(*) FROM contents WHERE packageid=p.id ) = 2;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 1: ...FROM contents WHERE item='circle' AND size='B' )) GROUP BY p... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "2 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.2667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "contents", + "packages" + ], + "num_joins": 1, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_343", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)), u.displayname, COUNT(c.id) AS nbrOfComments FROM comments AS c INNER JOIN users AS u ON c.userid = u.id WHERE EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)) = '2010' GROUP BY u.id", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"c.creationdate\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT EXTRACT(YEAR FROM CAST(c.creationdate AS DATE... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "comments", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_344", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.transactionid, g.gasstationid, p.productid, COALESCE(t1.date, g.country, p.description) AS date, COALESCE(t1.amount, 0) AS amount, COALESCE(g.chainid, 0) AS chainid, COALESCE(p.description, '') AS description FROM transactions_1k AS t1 FULL OUTER JOIN gasstations AS g ON t1.gasstationid = g.gasstationid FULL OUTER JOIN products AS p ON COALESCE(t1.date, g.country) = p.productid WHERE t1.date IS NULL AND g.country IS NULL", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ..., COALESCE(p.description, '') AS description FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_345", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (\"account_id\", \"district_id\", \"frequency\", \"account_type\", \"date\") VALUES (12345, 18, 'POPLATEK MESICNE', 'Regular', '1970-12-13')", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type bigint: \"1970-12-13\" | LINE 1: ...VALUES (12345, 18, 'POPLATEK MESICNE', 'Regular', '1970-12-1... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + } + ], + "tags": [ + "value_format_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_346", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE HierarchyCTE(entityid, parentid, emission, total_emission, percentage, level) AS (\n SELECT entityid, parentid, emission, emission AS total_emission, pctcontribution, 0\n FROM tree_table\n WHERE NOT entityid IN (SELECT DISTINCT parentid FROM tree_table WHERE NOT parentid IS NULL)\n UNION ALL\n SELECT h.entityid, h.parentid, h.emission, h.emission + cte.total_emission * (CAST(cte.pctcontribution AS DOUBLE PRECISION) / NULLIF(100, 0)) AS total_emission, h.pctcontribution, ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 11: FROM ( | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.2323, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "hierarchycte", + "tree_table" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_348", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT j.* FROM event e, json_array_elements(e.event_schedule->'$.*[*]') AS j(element)\nCROSS JOIN LATERAL (\n SELECT\n (j.element->>'start')::TIME AS date_start,\n (j.element->>'end')::TIME AS date_end,\n (j.element->>'*')::VARCHAR(10) AS day\n) AS j\nWHERE e.event_id='rec0Si5cQ4rJRVzd6';", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "table name \"j\" specified more than once", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42712" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_349", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT\n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"[\" | LINE 5: ...part('day', lastaccessdate - creationdate) + 1) - [subtract ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Expected ]. Line 5, Col: 79.\n \n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract \u001b[4mholidays\u001b[0m] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;\n\nInvalid expression / Unexpected token. Line 5, Col: 80.\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays\u001b[4m]\u001b[0m AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_351", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ct.c_id, bt.start_time::date AS date, trip_counts.trip_count, SUM(CASE WHEN tc.duration = 'Single' AND trip_counts.trip_count = 1 THEN tc.cost WHEN tc.duration = 'Single' AND trip_counts.trip_count = 2 THEN tc.cost * 2 ELSE 0 END) + SUM(CASE WHEN tc.duration = 'Day' AND trip_counts.trip_count >= 3 THEN tc.cost ELSE 0 END) AS total_cost FROM customertrip ct JOIN bustrip bt ON ct.b_id = bt.b_id JOIN ticketcosts tc ON tc.duration IN ('Single', 'Day') JOIN (SELECT b_id, start_time::date AS tr", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"trip_counts.trip_count\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...LAIN SELECT ct.c_id, bt.start_time::date AS date, trip_count... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'b_id' is ambiguous \u2014 exists in tables: customertrip, bustrip", + "taxonomy_category": "semantic", + "context": "b_id", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "logical_grouping_error", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.249, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bustrip", + "customertrip", + "ticketcosts" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_353", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE `lessonschedule` (`record_id` SMALLINT NOT NULL, `student_id` SMALLINT, `lesson_date_time` TIMESTAMP NOT NULL, PRIMARY KEY (`record_id`, `student_id`, `lesson_date_time`), CONSTRAINT `fk_record` FOREIGN KEY (`record_id`) REFERENCES `record`(`id`), CONSTRAINT `fk_student` FOREIGN KEY (`student_id`) REFERENCES `student`(`id`));", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"`\" | LINE 1: CREATE TABLE `lessonschedule` (`record_id` SMALLINT NOT NULL... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_354", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE \"member_privileges\" ADD CONSTRAINT \"member_fk\" FOREIGN KEY REFERENCES \"member\"(\"member_id\");", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"REFERENCES\" | LINE 1: ...rivileges\" ADD CONSTRAINT \"member_fk\" FOREIGN KEY REFERENCES... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "member", + "member_privileges" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_355", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE hero_event (event_id SERIAL PRIMARY KEY, superhero TEXT NOT NULL, event_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIME);", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "column \"event_date\" is of type timestamp without time zone but default expression is of type time with time zone | You will need to rewrite or cast the expression.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "hero_event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_356", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE superhero ALTER COLUMN description TYPE JSON SET NOT NULL SET DEFAULT '{}';", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SET\" | LINE 1: ...ABLE superhero ALTER COLUMN description TYPE JSON SET NOT NU... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_358", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.\"event_id\", b.\"amount\", b.\"link_to_member\", \"link_to_event\" FROM event AS b JOIN budget AS b ON b.\"event_id\" = b.\"link_to_event\" LEFT JOIN attendance AS b ON b.\"event_id\" = b.\"link_to_event\" ORDER BY b.\"event_id\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "table name \"b\" specified more than once", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42712" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'link_to_event' is ambiguous \u2014 exists in tables: attendance, budget", + "taxonomy_category": "semantic", + "context": "link_to_event", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_unknown_error", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0833, + "pattern_signature": "SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_359", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE FUNCTION check_alignment(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "unterminated dollar-quoted string at or near \"$$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END\" | LINE 1: ...ent(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN R... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_error", + "message": "Error tokenizing 'alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' EN'", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_error" + ] + }, + { + "instance_id": "PostgreSQL_361", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MaxHeightCTE\" AS (SELECT \"alignment_id\", \"publisher_id\", MAX(\"height_cm\") AS \"max_height\" FROM superhero GROUP BY \"alignment_id\", \"publisher_id\"), \"JoinedCTE\" AS (SELECT s.\"id\", s.\"superhero_name\", s.\"alignment_id\", s.\"publisher_id\", s.\"height_cm\", s.\"hair_colour_id\" FROM superhero AS s JOIN maxheightcte AS m ON s.\"alignment_id\" = m.\"alignment_id\" AND s.\"publisher_id\" = m.\"publisher_id\" AND s.\"height_cm\" = m.\"max_height\") SELECT \"alignment_id\", \"publisher_id\", SUM(\"hair_colour_id\") AS \"tot", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"maxheightcte\" does not exist | LINE 1: ..._cm\", s.\"hair_colour_id\" FROM superhero AS s JOIN maxheightc... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "joinedcte", + "maxheightcte", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_363", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_year NUMERIC;\nv_week NUMERIC;\nv_home_team_wins NUMERIC;\nv_away_team_wins NUMERIC;\nv_draws NUMERIC;\nv_total_matches NUMERIC;\nBEGIN\nSELECT EXTRACT(YEAR\n FROM TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')),\n TO_CHAR(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'IW'),\n SUM(CASE\n WHEN \"home_team_goal\" > \"away_team_goal\" THEN 1\n ELSE 0\n END),\n SUM(CASE\n WHEN \"home_team_goal\" < \"away_team_goal\" THEN 1\n", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 9 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_365", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", 1 AS level, CAST(m.\"molecule_id\" AS VARCHAR(4000)) AS path\n FROM molecule AS m\n JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n WHERE a.\"element\" = 'cl'\n\n UNION ALL\n\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", mh.level + 1, mh.path || '->' || m.\"molecule_id\"\n FROM molecule_hierarchy AS mh\n JOIN connected AS c ON mh.\"atom_id\" = c.\"atom_id\"\n JOIN ", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"molecule_hierarchy\" column 6 has type character varying(4000) in non-recursive term but type character varying overall | LINE 3: ... m.\"label\", a.\"atom_id\", a.\"element\", 1 AS level, CAST(m.\"mo... | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.3458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy" + ], + "num_joins": 8, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_367", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_stats AS (SELECT \"m\".\"date\" AS \"match_date\", \"l\".\"name\" AS \"league_name\", \"c\".\"name\" AS \"country_name\", \"ht\".\"team_long_name\" AS \"home_team\", \"at\".\"team_long_name\" AS \"away_team\", \"m\".\"home_team_goal\" AS \"home_team_goals\", \"m\".\"away_team_goal\" AS \"away_team_goals\", RANK() OVER (PARTITION BY \"m\".\"league_id\", \"m\".\"season\" ORDER BY \"m\".\"home_team_goal\" + \"m\".\"away_team_goal\" DESC NULLS LAST) AS \"high_scoring_rank\" FROM match AS \"m\" INNER JOIN league AS \"l\" ON \"m\".\"league_id\" = \"l\".\"id\" I", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: ...ay_team_goals\" END) AS \"avg_goals_per_match\" FROM (SELECT \"m... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.376, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "country", + "league", + "match", + "match_stats", + "team", + "team_performance" + ], + "num_joins": 6, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_370", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT a.molecule_id, COUNT(a.atom_id) AS atom_count,\n STRING_AGG(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements\n FROM atom AS a\n GROUP BY a.molecule_id\n),\nbond_hierarchy AS (\n SELECT bond_id, molecule_id, bond_type,\n SUBSTRING(bond_id FROM '^[^_]+') AS molecule_prefix,\n CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOUBLE PRECISION) AS first_atom_num,\n CAST(SUBSTRING(bond_id FROM '[^_]+$') AS DOUBLE PRECISION)", + "valid": false, + "errors": [ + { + "tag": "value_format_mismatch", + "message": "invalid input syntax for type integer: \"[^_]+\" | LINE 10: CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOU... | ^", + "taxonomy_category": "value_representation", + "context": "PostgreSQL EXPLAIN", + "error_code": "22P02" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'molecule_id' is ambiguous \u2014 exists in tables: bond, molecule, atom", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "value_format_mismatch", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.4229, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "molecule", + "molecule_connectivity" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_371", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_molecule_id VARCHAR(512);\n v_label TEXT;\n v_atom_id VARCHAR(512);\n v_element TEXT;\n v_atom_id2 VARCHAR(512);\n v_bond_id VARCHAR(512);\n v_bond_type TEXT;\nBEGIN\n SELECT \"m\".\"molecule_id\",\n \"m\".\"label\",\n \"a\".\"atom_id\",\n \"a\".\"element\",\n \"c\".\"atom_id2\",\n \"b\".\"bond_id\",\n \"b\".\"bond_type\"\n FROM \"molecule\" \"m\"\n INNER JOIN \"atom\" \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\"\n INNER JOIN \"connected\"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 11 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_372", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_elements AS (\n SELECT a.atom_id, a.molecule_id, a.element,\n RANK() OVER (PARTITION BY a.molecule_id ORDER BY a.atom_id NULLS FIRST) AS element_rank\n FROM atom AS a\n),\nbond_details AS (\n SELECT b.bond_id, b.molecule_id, b.bond_type,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_rank\n FROM bond AS b\n),\nmolecule_connections AS (\n SELECT c.atom_id, c.atom_id2, c.bond_id,\n STRING_AGG(c.atom_id2, ',' ORDER ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "aggregate ORDER BY is not implemented for window functions | LINE 13: STRING_AGG(c.atom_id2, ',' ORDER BY c.atom_id2 NU... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_elements", + "bond", + "bond_details", + "connected", + "molecule", + "molecule_connections" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_373", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result\nFROM \"molecule\" m\nINNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\nINNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" INTO :result_variable", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "(sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'result_variable' | [SQL: EXPLAIN SELECT m.\"molecule_id\", | COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result | FROM \"molecule\" m | INNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\" | INNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\" | INNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\" | GROUP BY m.\"molecule_id\" INTO %(result_variable)s] | (Background on this error at: https://sqlalche.me/e/20/cd3x)", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 7, Col: 29.\n a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" \u001b[4mINTO\u001b[0m :result_variable", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_unknown_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_375", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS ( SELECT m.molecule_id, m.label, a.atom_id, a.element, CAST(NULL AS VARCHAR(512)) AS atom_id2, CAST(NULL AS VARCHAR(512)) AS bond_id, CAST(NULL AS TEXT) AS bond_type, 1 AS level, CAST(a.atom_id AS VARCHAR(4000)) AS path FROM molecule AS m JOIN atom AS a ON m.molecule_id = a.molecule_id UNION ALL SELECT h.molecule_id, h.label, h.atom_id, h.element, c.atom_id2, c.bond_id, b.bond_type, h.level + 1, h.path || '->' || c.atom_id2 FROM molecule_hierarchy AS h JOIN", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 1: ...SE WHEN rn = 3 THEN element END) AS element3 FROM (SELECT mo... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.5208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "pivoted_elements" + ], + "num_joins": 8, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_377", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_pairs AS (\n SELECT\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM 1 FOR POSITION(',' IN pair_str) - 1))\n ELSE pair_str END AS mol_id1,\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM POSITION(',' IN pair_str) + 1))\n ELSE NULL END AS mol_id2\n FROM (\n SELECT 'TR427, TR430' AS pair_str\n UNION ALL\n SELECT 'TR427, TR431'\n UNION ALL\n ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "DISTINCT is not implemented for window functions | LINE 22: COUNT(DISTINCT b.\"bond_id\") OVER (PARTITION BY m.\"mo... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.3823, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pairs", + "molecule_stats" + ], + "num_joins": 5, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_378", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"m\".\"molecule_id\", \"m\".\"label\", \"a\".\"element\" FROM molecule AS \"m\" INNER JOIN atom AS \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\" ORDER BY \"m\".\"molecule_id\" NULLS FIRST, \"a\".\"atom_id2\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column a.atom_id2 does not exist | LINE 1: ...ecule_id\" ORDER BY \"m\".\"molecule_id\" NULLS FIRST, \"a\".\"atom_... | ^ | Perhaps you meant to reference the column \"a.atom_id\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_379", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\",\n COUNT(DISTINCT a.\"atom_id\") AS atom_count,\n COUNT(DISTINCT b.\"bond_id\") AS bond_count,\n string_agg(DISTINCT CASE WHEN a.\"element\" IS NULL THEN NULL WHEN ',' IS NULL THEN NULL ELSE a.\"element\" END, ',') AS elements\n FROM molecule AS m\n LEFT OUTER JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n LEFT OUTER JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n LEFT OUTER JOIN bond AS b ON c.\"bond_id\" = b", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column mp.chlorine does not exist | LINE 32: mp.chlorine, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.4594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pivot", + "molecule_stats" + ], + "num_joins": 9, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_380", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\", COUNT(a.\"atom_id\") AS atom_count,\n STRING_AGG(a.\"element\", ',' ORDER BY a.\"atom_id\" NULLS FIRST) AS elements\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n GROUP BY m.\"molecule_id\"\n),\nbond_stats AS (\n SELECT b.\"molecule_id\", COUNT(b.\"bond_id\") AS bond_count\n FROM bond AS b\n GROUP BY b.\"molecule_id\"\n)\nSELECT ms.\"molecule_id\", ms.atom_count AS \"total_atoms\", bs.bond_count,\n CASE W", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function round(double precision, integer) does not exist | LINE 14: CASE WHEN ms.atom_count > 0 THEN ROUND(CAST(bs.bond_c... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1896, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "bond_stats", + "molecule", + "molecule_stats" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_382", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n TO_CHAR(type) AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 END) -\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = oldest_year THEN 1 END) AS year_difference\nFROM event,\n (\n SELECT\n MAX(EXTRACT(YEAR FROM event_date::timestamp)) AS recent_year,\n MIN(EXTRACT(YEAR FROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type), recent_year, oldest_year;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_char(text) does not exist | LINE 2: TO_CHAR(type) AS event_type, | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'format' missing for . Line 2, Col: 17.\n SELECT\n TO_CHAR(type\u001b[4m)\u001b[0m AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 EN\n\nRequired keyword: 'format' missing for . Line 12, Col: 22.\n ROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type\u001b[4m)\u001b[0m, recent_year, oldest_year;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "schema_undefined_function", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "event" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_384", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_match_id BIGINT;\nv_match_date TEXT;\nv_home_team_goals BIGINT;\nv_away_team_goals BIGINT;\nv_home_team_name TEXT;\nv_away_team_name TEXT;\nv_league_name TEXT;\n\nBEGIN\nSELECT \"match\".\"id\",\n \"match\".\"date\",\n \"match\".\"home_team_goal\",\n \"match\".\"away_team_goal\",\n \"HomeTeam\".\"team_long_name\",\n \"AwayTeam\".\"team_long_name\",\n \"league\".\"name\"\nFROM \"match\"\nINNER JOIN \"team\" \"HomeTeam\" ON \"match\".\"home_team_api_id\" = \"HomeTeam\".\"team_api_id\"\nINNER JOIN \"team\" \"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "query has no destination for result data | If you want to discard the results of a SELECT, use PERFORM instead. | PL/pgSQL function inline_code_block line 11 at SQL statement", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_386", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH temp AS\n (SELECT a.\"atom_id\",\n a.\"molecule_id\",\n ROW_NUMBER() OVER (PARTITION BY a.\"molecule_id\"\n ORDER BY a.\"atom_id\") - TO_DATE(REGEXP_SUBSTR(a.\"atom_id\", '\\d+$'), 'DD') AS grp\n FROM \"atom\" a), temp2 AS\n (SELECT t.\"atom_id\",\n t.\"molecule_id\",\n COUNT(*) OVER (PARTITION BY t.\"molecule_id\", t.grp) AS cnt\n FROM temp t)\nSELECT t2.\"atom_id\",\n t2.\"molecule_id\"\nFROM temp2 t2\nWHERE t2.cnt >= 3\nORDER BY t2.\"molecule_id\",\n ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(text, unknown) does not exist | LINE 5: ... ORDER BY a.\"atom_id\") - TO_DATE(REGEXP_SUB... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "temp", + "temp2" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_387", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n\n set_a (molecule_id, element_count) AS (\n SELECT molecule_id, COUNT(DISTINCT element)\n FROM atom\n GROUP BY molecule_id\n HAVING COUNT(DISTINCT element) > 1\n ),\n set_b (molecule_id, element_count) AS (\n SELECT m.molecule_id, COUNT(DISTINCT a.element)\n FROM molecule m\n JOIN atom a ON m.molecule_id = a.molecule_id\n WHERE m.label IS NOT NULL\n GROUP BY m.molecule_id\n ),\n\n unique_a (molecule_id, element_count, rn, densi", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"molecule_hierarchy\" does not exist | LINE 49: JOIN molecule_hierarchy h ON m.molecule_id = h.molec... | ^ | There is a WITH item named \"molecule_hierarchy\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'bond_id' is ambiguous \u2014 exists in tables: bond, connected", + "taxonomy_category": "semantic", + "context": "bond_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'element_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "element_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.5177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "set_a", + "set_b", + "unique_a", + "unique_b" + ], + "num_joins": 6, + "num_subqueries": 2, + "num_ctes": 5, + "num_aggregations": 12 + } + }, + { + "instance_id": "PostgreSQL_389", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT \"molecule_id\",\n STRING_AGG(DISTINCT \"atom_id\", ',') OVER (PARTITION BY \"molecule_id\" ORDER BY \"atom_id\") AS \"atom_ids\"\nFROM \"atom\"\nWHERE \"molecule_id\" = 'TR011'\nGROUP BY \"molecule_id\",\n \"atom_id\"", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "DISTINCT is not implemented for window functions | LINE 2: STRING_AGG(DISTINCT \"atom_id\", ',') OVER (PA... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_390", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS\n (SELECT \"id\",\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_date,\n TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'fmDay', 'English') AS day_of_week,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_start_time,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '2 HOUR' AS match_end_time\n FROM \"match\")\nSELECT m.*,\n ROUND(GREATEST(LEAST(m.match_end_time, m.match_date + INTERVAL '17:00:00' HOUR TO SECOND) - GREATEST(m.ma", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function to_char(date, unknown, unknown) does not exist | LINE 4: TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'DBA_VIEWS' does not exist in schema", + "taxonomy_category": "semantic", + "context": "DBA_VIEWS", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_undefined_function", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "dba_views", + "match", + "match_dates" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_392", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"home_team_api_id\" AS \"team_api_id\",\n \"start_date\",\n \"end_date\",\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (consecutive_wins+) DEFINE consecutive_wins AS \"league_id\" = 'EUROPEAN_FOOTBALL_2')", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"BY\" | LINE 5: FROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\" | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'match_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "match_count", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 6, Col: 38.\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n \u001b[4mORDER BY\u001b[0m \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\n\nInvalid expression / Unexpected token. Line 6, Col: 54.\n OM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" \u001b[4mMEASURES\u001b[0m FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (conse", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_394", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE split_date AS (\n SELECT id,\n date,\n 1 AS level,\n SPLIT_PART(date, ' ', 1) AS date_part\n FROM team_attributes\n\n UNION ALL\n\n SELECT s.id,\n s.date,\n s.level + 1,\n SPLIT_PART(s.date, ' ', s.level + 1) AS date_part\n FROM split_date s\n WHERE s.level < regexp_count(s.date, ' ') + 1\n AND s.date_part != ''\n)\nSELECT id, date_part\nFROM split_date", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_count(text, unknown) does not exist | LINE 15: WHERE s.level < regexp_count(s.date, ' ') + 1 | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0844, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "split_date", + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_396", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n m.\"molecule_id\" AS root_molecule_id,\n 1 AS hierarchy_level,\n '/' || m.\"molecule_id\" AS molecule_path\n FROM \"molecule\" m\n JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\n JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\n JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\n WHERE b.\"bond_type\" = '-'\n\n UNION ALL\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n ", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"month_generator\" column 1 has type date in non-recursive term but type timestamp without time zone overall | LINE 33: TO_DATE('01/01/2018', 'MM/DD/YYYY') AS month_start_d... | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.4427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "molecule_months", + "month_generator" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_397", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH tbl AS\n (SELECT TO_DATE('12.01.2023', 'dd.mm.yyyy') AS act_date\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('12.02.2023', 'dd.mm.yyyy')\n FROM (S", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"g.rn_1\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 64: WHEN g.rn_1 = g.rn_2 THEN | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.4104, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "grid", + "molecule", + "molecule_activity", + "t2", + "tbl" + ], + "num_joins": 2, + "num_subqueries": 19, + "num_ctes": 4, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_399", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\"\nFROM\n (SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\",\n ROW_NUMBER() OVER (PARTITION BY \"team_api_id\"\n ORDER BY TO_NUMBER(\"date\") DESC) AS seq\n FROM \"team_attributes\")\nWHERE seq = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 5: (SELECT \"team_api_id\", | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_401", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MY_TABLE\" AS\n (SELECT '1111' AS \"TECHNICAL_ID\",\n 'NOTIONALCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '1111' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n 'FWDNOTLCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_I", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"CTE\" does not exist | LINE 53: FROM \"CTE\" C | ^ | There is a WITH item named \"CTE\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.125, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "map_recrf_asset_type", + "my_table" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_403", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT T.\"team_long_name\",\n T.\"team_short_name\",\n TA.\"buildUpPlaySpeed\",\n TA.\"buildUpPlaySpeedClass\",\n TA.\"chanceCreationShooting\",\n TA.\"chanceCreationShootingClass\",\n TA.\"defencePressure\",\n TA.\"defencePressureClass\"\nFROM \"team\" T\nINNER JOIN \"team_attributes\" TA ON T.\"team_api_id\" = TA.\"team_api_id\"\nWHERE TA.\"date\" = '2013-09-20 00:00:00'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column ta.buildUpPlaySpeed does not exist | LINE 3: TA.\"buildUpPlaySpeed\", | ^ | Perhaps you meant to reference the column \"ta.buildupplayspeed\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_404", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"valid_from\",\n \"valid_until\",\n \"count\"\nFROM\n (SELECT \"dt\" AS \"valid_from\",\n LEAD(\"dt\") OVER (\n ORDER BY \"dt\") - INTERVAL '1' SECOND AS \"valid_until\",\n SUM(\"count\" * \"type\") OVER (\n ORDER BY \"dt\") AS \"count\"\n FROM\n (SELECT \"valid_from\",\n \"valid_until\" + INTERVAL '1 DAY' AS \"valid_until\",\n 1 AS \"count\"\n FROM\n (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 15: (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"vali... | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2885, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_405", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH school_data AS (\n SELECT\n s.cdscode AS \"pk\",\n CASE\n WHEN s.charter = 1 THEN 'Charter'\n WHEN s.magnet = 1 THEN 'Magnet'\n ELSE 'Regular'\n END AS \"col2\",\n SUBSTRING(s.county FROM 1 FOR POSITION(' ' IN s.county) - 1) AS \"col3\",\n TO_TIMESTAMP(TO_CHAR(s.lastupdate, 'YYYY/MM/DD') || ' ' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode), 24) AS TEXT), 2, '0') || ':' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode) * 7, 60) AS TEXT), ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: timestamp with time zone < text | LINE 26: AND sd.\"col4\" < TO_CHAR(TO_TIMESTAMP('2024/09/04 00:05',... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "aggregated_data", + "filtered_data", + "school_data", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_407", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"columns\" (\"column_name\") AS\n (SELECT 'cdscode'\n UNION ALL SELECT 'statustype'\n UNION ALL SELECT 'school'),\n \"column_exists\" (\"column_name\",\n \"column_exists\") AS\n (SELECT c.\"column_name\",\n COALESCE(a.attname, 'NO')\n FROM \"columns\" c\n LEFT OUTER JOIN pg_attribute a ON (a.attrelid = 'schools'::regclass\n AND c.\"column_name\" = a.attname))\nSELECT *\nFROM \"column_exists\"\nPIVOT (MAX(\"column_exists\")\n FOR \"column_", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"(\" | LINE 14: PIVOT (MAX(\"column_exists\") | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1604, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "column_exists", + "columns", + "pg_attribute" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_408", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH string1_tab AS (\n SELECT REGEXP_SUBSTR('24,36,78,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('24,36,78,98') - LENGTH(REPLACE('24,36,78,98', ',', '')) + 1)\n),\nstring2_tab AS (\n SELECT REGEXP_SUBSTR('25,36,88,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('25,36,88,98') - LENGTH(REPLACE('25,36,88,98', ',', '')) + 1)\n),\nstring1_parsed AS (\n S", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(unknown, unknown, integer, integer) does not exist | LINE 2: SELECT REGEXP_SUBSTR('24,36,78,98', '[^,]+', 1, generate... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "common_values", + "string1_parsed", + "string1_tab", + "string2_parsed", + "string2_tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 5, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_410", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n GREATEST(DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 day') + INTERVAL '1 day' + (m.months * INTERVAL '1 month'), CURRENT_DATE) AS bond_formation_date\nFROM \"bond\" b\nJOIN\n (SELECT generate_series(0, 5) AS months) m\nGROUP BY b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n m.months\nHAVING b.\"molecule_id\" = 'TR011'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"GROUP\" | LINE 8: GROUP BY b.\"bond_id\", | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bond" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_411", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH team_speed_stats AS (\n SELECT\n team_api_id,\n date,\n buildupplayspeed,\n ROW_NUMBER() OVER (PARTITION BY team_api_id ORDER BY date DESC) as rn,\n AVG(buildupplayspeed) OVER (PARTITION BY buildupplayspeedclass) as class_avg_speed\n FROM team_attributes\n),\nmatch_details AS (\n SELECT\n m.id,\n m.date,\n m.home_team_api_id,\n m.away_team_api_id,\n m.home_team_goal,\n m.away_team_goal,\n t.team_long_name as home_te", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text >= date | LINE 34: WHERE m.date BETWEEN TO_DATE('2015-01-01', 'YYYY-MM-DD')... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_undefined_function", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.499, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "match_details", + "team", + "team_attributes", + "team_speed_stats" + ], + "num_joins": 5, + "num_subqueries": 4, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_412", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with lose_agg as\n (select team_api_id,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2011 then defencepressure\n end) as lose_5,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2012 then defencepressure\n end) as lose_10\n from team_attributes\n group by team_api_id),\n profit_agg as\n (select team_api_id,\n sum(case\n when extract(ye", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"select\" | LINE 29: select extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:S... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 29, Col: 6.\n join profit_agg p on l.team_api_id = p.team_api_id\norder by coalesce(p.team_api_id, l.team_api_id)\n\u001b[4mselect\u001b[0m extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) as year\nfrom team_attributes\nwhere date =", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "lose_agg", + "profit_agg", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_414", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT \"atom_id\",\n \"bond_id_1\",\n \"bond_id_2\",\n \"bond_id_3\"\nFROM (\n SELECT \"atom_id\", \"bond_id\",\n CASE WHEN \"bond_id\" = 1 THEN \"bond_id\" END AS \"bond_id_1\",\n CASE WHEN \"bond_id\" = 2 THEN \"bond_id\" END AS \"bond_id_2\",\n CASE WHEN \"bond_id\" = 3 THEN \"bond_id\" END AS \"bond_id_3\"\n FROM \"connected\"\n) AS pivoted_data\nORDER BY \"atom_id\"", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text = integer | LINE 7: CASE WHEN \"bond_id\" = 1 THEN \"bond_id\" END AS \"bo... | ^ | No operator matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "connected" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_416", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT player_id,\n MAX(overall_rating) AS overall_rating,\n potential,\n preferred_foot,\n attacking_work_rate\nFROM (SELECT player_api_id AS player_id, overall_rating, potential, preferred_foot, attacking_work_rate, row_number() OVER (PARTITION BY player_api_id ORDER BY date DESC) as rn FROM player_attributes WHERE date <= '2015-12-31') subquery\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"subquery.player_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: EXPLAIN SELECT player_id, | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_417", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_name\"))\n ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZE = 2) AS result\nFROM \"team\"\nWHERE \"id\" IN\n (SELECT \"id\"\n FROM \"team_attributes\"\n WHERE \"date\" IS NULL)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"INDENT\" | LINE 2: ... ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 1, Col: 39.\n SELECT XMLSERIALIZE(DOCUMENT \u001b[4mXMLELEMENT\u001b[0m(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long\n\nInvalid expression / Unexpected token. Line 1, Col: 40.\n SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT\u001b[4m(\u001b[0mNAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_419", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT REPLACE(SUBSTR(date, 1, INSTR(date, '.', -1) - 1), '.') || SUBSTR(date, INSTR(date, '.', -1)) AS \"updated_value\"\nFROM team_attributes\nWHERE date LIKE '%.%'", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function instr(text, unknown, integer) does not exist | LINE 1: EXPLAIN SELECT REPLACE(SUBSTR(date, 1, INSTR(date, '.', -1) ... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_421", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"my_table\" AS\n (SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A1' AS \"file_\",\n 5 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A2' AS \"file_\",\n 3 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A3' AS \"file_\",\n 2 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A4' AS \"file_\",\n ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"BY\" | LINE 37: FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\" | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 38, Col: 46.\n ize\"\n FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n \u001b[4mORDER BY\u001b[0m \"rn\" MEASURES MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((\n\nInvalid expression / Unexpected token. Line 38, Col: 60.\n my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n ORDER BY \"rn\" \u001b[4mMEASURES\u001b[0m MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((same_nif* nif)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "my_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_422", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE \"a\" (\"test\") AS\n (SELECT 'Jack|Sparrow|17-09-16|DY7009|Address at some where|details '\n UNION ALL SELECT 'Jack|Sparrow|17-09-16|DY7009|'\n UNION ALL SELECT 'Jack|Sparrow|17-09-16'\n UNION ALL SELECT \"test\" || '|MoreData'\n FROM \"a\")\nSELECT \"test\",\n REGEXP_SUBSTR(\"test\", '([^|]+\\|?){1,5}') AS \"res\"\nFROM \"a\"", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function regexp_substr(text, unknown) does not exist | LINE 8: REGEXP_SUBSTR(\"test\", '([^|]+\\|?){1,5}') AS \"res\" | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "a" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_424", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n \"molecule\".\"molecule_id\",\n MIN(\"atom\".\"atom_id\") AS \"first_atom_id\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\";", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"molecule.molecule_id\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 2: \"molecule\".\"molecule_id\", | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_425", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule\".\"molecule_id\",\n \"molecule\".\"label\",\n \"atom\".\"atom_id\",\n \"atom\".\"element\",\n \"bond\".\"bond_id\",\n \"bond\".\"bond_type\",\n \"connected\".\"atom_id2\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\"\nINNER JOIN \"connected\" ON \"atom\".\"atom_id\" = \"connected\".\"atom_id\"\nINNER JOIN \"bond\" ON \"connected\".\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \"connected\".\"atom_id2\";", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\"connected\"\" | LINE 14: \"connected\".\"atom_id2\"; | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 14, Col: 20.\n .\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \u001b[4m\"connected\"\u001b[0m.\"atom_id2\";", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_426", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE \"frpm\" AS target\n \"Charter School (Y/N)\" = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Eligible Free (K-12)\" >= 0.5\n ) AS source\n WHERE target.\"cdscode\" = source.\"cdscode\";", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"\"Charter School (Y/N)\"\" | LINE 2: \"Charter School (Y/N)\" = 1000 | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 26.\n UPDATE \"frpm\" AS target\n \u001b[4m\"Charter School (Y/N)\"\u001b[0m = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Elig", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_430", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE replacements (molecule_id, current_label, current_spos) AS (\n SELECT molecule_id,\n label::text,\n strpos(label::text, '+')\n FROM molecule\n UNION ALL\n SELECT r.molecule_id,\n overlay(r.current_label placing '-' from r.current_spos for 1),\n strpos(overlay(r.current_label placing '-' from r.current_spos for 1), '+')\n FROM replacements r\n WHERE r.current_spos > 0\nSELECT molecule_id,\n current_label AS label\nFROM replacements\n\nWHERE current_spos", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"SELECT\" | LINE 12: SELECT molecule_id, | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_error", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "molecule", + "replacements" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_431", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.\"cds\",\n s.\"sname\"::text,\n (SELECT json_agg(json_build_object(\n 'enroll12', t.\"enroll12\"::text,\n 'NumTstTakr', t.\"numtsttakr\"::text,\n 'AvgScrRead', t.\"avgscrread\"::text,\n 'AvgScrMath', t.\"avgscrmath\"::text,\n 'AvgScrWrite', t.\"avgscrwrite\"::text\n ) ORDER BY t.\"enroll12\" DESC)\n\n WHERE t.\"rtype\"::text = 'S'\n AND t.\"cds\" = s.\"cds\"\n )\nFROM \"satscores\" s\nWHERE s.\"rtype\"::text = 'S';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "missing FROM-clause entry for table \"t\" | LINE 4: 'enroll12', t.\"enroll12\"::text, | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_433", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT M.\"id\", MAX(M.\"date\"), M.\"overall_rating\" FROM player_rate AS M GROUP BY M.\"id\", MAX(M.\"date\"), M.\"overall_rating\"", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "aggregate functions are not allowed in GROUP BY | LINE 1: ...ll_rating\" FROM player_rate AS M GROUP BY M.\"id\", MAX(M.\"dat... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "player_rate" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_438", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM bl.transact_dt_tm) as year, bl.bond_type, COUNT(*) as bond_count FROM bond_list bl RIGHT JOIN bond_ref br ON bl.bond_type = br.bond_type GROUP BY EXTRACT(YEAR FROM bl.transact_dt_tm), bl.bond_type ORDER BY year, br.bond_seq", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"br.bond_seq\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...M bl.transact_dt_tm), bl.bond_type ORDER BY year, br.bond_se... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "bond_list", + "bond_ref" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_439", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT header || ': ' || name AS grouped_countries\nFROM (\n SELECT\n MAX(CASE WHEN name LIKE 'Country Group%' THEN name END)\n OVER (ORDER BY id) AS header,\n id,\n name\n FROM country\n)\nWHERE name NOT LIKE 'Country Group%'", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "subquery in FROM must have an alias | LINE 2: FROM ( | ^ | For example, FROM (SELECT ...) [AS] foo.", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "country" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_449", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER (ORDER BY T.transactionid NULLS FIRST) AS Row, CAST(EXTRACT(epoch FROM CAST(CAST(LEAD(T.date, 1, 0) OVER (ORDER BY T.date NULLS FIRST) AS TIMESTAMP) AS TIMESTAMP) - CAST(CAST(T.date AS TIMESTAMP) AS TIMESTAMP)) AS BIGINT) AS TimeDifference FROM transactions_1k AS T LIMIT 100", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"transactions_1k\" does not exist | LINE 1: ... AS TIMESTAMP)) AS BIGINT) AS TimeDifference FROM transactio... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_450", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH CardIssuanceDays AS ( SELECT c.card_id, c.issued, TO_CHAR(CAST(CAST(TO_CHAR(c.issued, 'MM/DD/YYYY') AS VARCHAR(10)) AS TIMESTAMP), 'TMDay') AS day_of_week , ROW_NUMBER() OVER (PARTITION BY TO_CHAR(CAST(c.issued AS TIMESTAMP), '%W') ORDER BY c.issued NULLS FIRST) AS rank_in_day FROM card AS c INNER JOIN disp AS d ON c.disp_id = d.disp_id AND d.type = 'OWNER' WHERE c.issued BETWEEN CURRENT_TIMESTAMP + INTERVAL '-5 YEAR' AND 0 + INTERVAL MONTH + INTERVAL '-1 DAY'), WeekdayReference AS ", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"MONTH\" | LINE 1: ...T_TIMESTAMP + INTERVAL '-5 YEAR' AND 0 + INTERVAL MONTH + IN... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'card' does not exist in schema", + "taxonomy_category": "semantic", + "context": "card", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.2156, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "card", + "cardissuancedays", + "disp", + "weekdayreference" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_452", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT date, account_id, CASE WHEN EXISTS(type = 'PRIJEM' AND 'VYDAJ' AND 'SLUZBY') THEN 1 ELSE 0 END FROM trans GROUP BY \"date\", account_id", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"type\" | LINE 1: EXPLAIN SELECT date, account_id, CASE WHEN EXISTS(type = 'PR... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0313, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_455", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"PIVOT\" | LINE 2: WHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR pro... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 36.\n T \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) \u001b[4mPIVOT\u001b[0m(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_457", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ???, s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE s.id IN (1, 2, 3)", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 1: EXPLAIN SELECT ???, s.superhero_name, p.publisher_name FROM ... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 11.\n SELECT ???\u001b[4m,\u001b[0m s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "publisher", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_458", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CircuitFilters AS (SELECT c.circuitid, CASE WHEN c.country LIKE 'M%' THEN 1 ELSE 0 END AS IsCountryStartingWithM, CASE WHEN c.name LIKE '%International%' THEN 1 ELSE 0 END AS HasInternationalInName FROM circuits AS c) SELECT r.raceid FROM races AS r INNER JOIN circuitfilters AS cf ON cf.circuitid = r.circuitid WHERE cf.IsCountryStartingWithM = 1 EXCEPT SELECT r.raceid FROM races AS r INNER JOIN circuits AS c ON c.circuitid = r.circuitid WHERE c.name LIKE '%International%' HAVING COUNT(DISTI", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"r.raceid\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...WHERE cf.IsCountryStartingWithM = 1 EXCEPT SELECT r.raceid F... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-HAVING-EXCEPT", + "clauses_present": [ + "CTE", + "EXCEPT", + "FROM", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "circuitfilters", + "circuits", + "races" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_460", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT atom_id FROM ( SELECT CASE WHEN element = 'cl' AND lead(element) OVER\n(ORDER BY atom_id) = 'c' THEN REPLACE(CONCAT(atom_id, lead(atom_id) OVER (ORDER BY atom_id)), ' ', '')\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \",\" | LINE 4: ...ment) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMB... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Expected END after CASE. Line 4, Col: 82.\n _id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN \u001b[4matom_id\u001b[0m, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_467", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH AtomBondMapping AS (\n SELECT\n a.atom_id,\n SUBSTRING(a.atom_id FROM 1 FOR POSITION('_' IN a.atom_id) - 1) || '_' ||\n SUBSTRING(a.atom_id FROM POSITION('_' IN a.atom_id) + 1 FOR LENGTH(a.atom_id)) || '_' ||\n CAST(CAST(SUBSTRING(c.atom_id2 FROM POSITION('_' IN c.atom_id2) + 1 FOR LENGTH(c.atom_id2)) AS INTEGER) AS VARCHAR) AS derived_bond_id\n FROM atom AS a\n INNER JOIN connected AS c ON a.atom_id = c.atom_id\n WHERE a.element = 'c'\n),\nMoleculeStats AS (\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column ms.atom_id does not exist | LINE 30: ...ON a.molecule_id = ms.molecule_id AND a.atom_id = ms.atom_id | ^ | Perhaps you meant to reference the column \"a.atom_id\" or the column \"c.atom_id\".", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2958, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atombondmapping", + "bond", + "connected", + "molecule", + "moleculestats" + ], + "num_joins": 6, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_474", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (SELECT r.raceId, r.year, r.name AS raceName, res.positionText, d.forename || ' ' || d.surname AS driverName, res.driverId, ROW_NUMBER() OVER (PARTITION BY r.raceId, res.positionText ORDER BY res.resultId NULLS FIRST) AS position_rank FROM results AS res INNER JOIN races AS r ON res.raceId = r.raceId INNER JOIN drivers AS d ON res.driverId = d.driverId WHERE CAST(res.positionText AS INT) <= 3) SELECT rr.raceId, MAX(rr.year) AS year, MAX(rr.raceName) AS raceName, MAX(CASE WHEN", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"rr.positiontext\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ... rr.raceId ORDER BY MAX(rr.year) DESC NULLS LAST, rr.positio... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_475", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH x AS (SELECT driverid, statusid, ROW_NUMBER() OVER (PARTITION BY driverid ORDER BY COUNT(*) DESC NULLS LAST) AS rn FROM results GROUP BY driverid, statusid) INSERT INTO results (resultid, raceid, driverid, constructorid, number, grid, position, positiontext, positionorder, points, laps, time, milliseconds, fastestlap, rank, fastestlaptime, fastestlapspeed, statusid) SELECT driverid, 1, driverid, 1, 1, 1, position, positiontext, positionorder, points, 1, '00:00:00', 0, 1, 1, '00:00:00', '000", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"position\" does not exist | LINE 1: ... statusid) SELECT driverid, 1, driverid, 1, 1, 1, position, ... | ^ | There is a column named \"position\" in table \"results\", but it cannot be referenced from this part of the query.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-WINDOW-ORDER-INSERT", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "INSERT", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "results", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_481", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH x AS (SELECT FLOOR(COALESCE(LENGTH(CAST(label AS TEXT)), 0) / 100) AS labellength FROM molecule) SELECT labellength * 100 AS labellengthstart, (labellength + 1) * 100 - 1 AS labellengthend, COUNT(*) AS moleculecount FROM x ORDER BY labellength NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"x.labellength\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 1: ...), 0) / 100) AS labellength FROM molecule) SELECT labellengt... | ^", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "WITH-CTE-SELECT-FROM-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "molecule", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_488", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT RACEID, NAME, \"date\", LAG(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS PREVRACEID, LEAD(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS NEXTRACEID FROM races ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_existent_column\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"non_existent_column\" does not exist | LINE 1: ...es ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_exist... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'non_existent_column' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "non_existent_column", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_491", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH ATOMRNS AS (SELECT MOLECULE_ID, ELEMENT, ROW_NUMBER() OVER (PARTITION BY MOLECULE_ID ORDER BY ATOM_ID NULLS FIRST) AS RN FROM atom) SELECT MOLECULE_ID, MAX(CASE WHEN RN = 1 THEN ELEMENT END) AS ELEMENT1, MAX(CASE WHEN RN = 2 THEN ELEMENT END) AS ELEMENT2, MAX(CASE WHEN RN = 3 THEN ELEMENT END) AS ELEMENT3 FROM atomrns JOIN atom ON ATOMRNS.MOLECULE_ID = ATOM.MOLECULE_ID GROUP BY MOLECULE_ID", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "column reference \"molecule_id\" is ambiguous | LINE 1: ...R BY ATOM_ID NULLS FIRST) AS RN FROM atom) SELECT MOLECULE_I... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42702" + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1115, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atomrns" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_492", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH SUPERHEROLIST AS (SELECT ID, SUPERHERO_NAME, FULL_NAME, ROW_NUMBER() OVER (PARTITION BY PUBLISHER_ID ORDER BY ID NULLS FIRST) AS PUBLISHER_RANK, DENSE_RANK() OVER (ORDER BY ALIGNMENT_ID NULLS FIRST, ID NULLS FIRST) AS GLOBAL_RANK FROM superhero WHERE NOT HEIGHT_CM IS NULL), SUPERHERO_POWERS AS (SELECT S.ID, S.SUPERHERO_NAME, COUNT(HP.POWER_ID) AS POWER_COUNT, STRING_AGG(SP.POWER_NAME, ', ' ORDER BY SP.POWER_NAME NULLS FIRST) AS POWERS FROM superhero AS S LEFT JOIN hero_power AS HP ON S.ID =", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column s2.publisher_id does not exist | LINE 1: ... AS S2 ON S2.GLOBAL_RANK = S1.GLOBAL_RANK + 4 AND S2.PUBLISH... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "hero_power", + "superhero", + "superhero_powers", + "superherolist", + "superpower" + ], + "num_joins": 5, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_497", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n xml_result xml;\nBEGIN\n -- First attempt to build the XML structure with nested XML queries\n WITH SchemaInfo AS (\n SELECT\n COLUMN_NAME,\n DATA_TYPE,\n ORDINAL_POSITION\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'schools' AND TABLE_SCHEMA = current_schema()\n ),\n SATData AS (\n SELECT\n cds,\n rtype,\n ROW_NUMBER() OVER(PARTITION BY cds ORDER BY NumTstTakr DESC) AS RowRank", + "valid": false, + "errors": [ + { + "tag": "logical_grouping_error", + "message": "column \"schemainfo.ordinal_position\" must appear in the GROUP BY clause or be used in an aggregate function | LINE 31: ORDER BY ORDINAL_POSITION) | ^ | QUERY: WITH SchemaInfo AS ( | SELECT | COLUMN_NAME, | DATA_TYPE, | ORDINAL_POSITION | FROM INFORMATION_SCHEMA.COLUMNS | WHERE TABLE_NAME = 'schools' AND TABLE_SCHEMA = current_schema() | ), | SATData AS ( | SELECT | cds, | rtype, | ROW_NUMBER() OVER(PARTITION BY cds ORDER BY NumTstTakr DESC) AS RowRank | FROM satscores | WHERE NumTstTakr > 0 | ) | SELECT xmlelement( | name \"Results\", | (SELECT xmlagg( | xmlelement( | name \"Columns\", | (SELECT xmlagg( | xmlelement( | name \"Column\", | xmlattributes(COLUMN_NAME as \"Name\"), | xmlelement(name \"DataType\", DATA_TYPE) | ) | ) | FROM SchemaInfo | ORDER BY ORDINAL_POSITION) | ) | )), | (SELECT xmlagg( | xmlelement( | name \"Rows\", | (SELECT xmlagg( | xmlelement( | name \"Row\", | xmlelement(name \"cds\", CASE WHEN cds IS NULL THEN 'xsi:nil=\"true\"' ELSE cds END), | xmlelement(name \"rtype\", CASE WHEN rtype IS NULL THEN 'xsi:nil=\"true\"' ELSE rtype END) | ) | ) | FROM SATData | WHERE RowRank = 1) | ) | )) | ) | PL/pgSQL function inline_code_block line 6 at SQL statement", + "taxonomy_category": "logical", + "context": "PostgreSQL EXPLAIN", + "error_code": "42803" + } + ], + "tags": [ + "logical_grouping_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_498", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CustomerID, Consumption, MIN(Date) AS MinDate, MAX(Date) AS MaxDate\nFROM yearmonth WHERE Consumption = 0 GROUP BY CustomerID, Consumption;\n\nUPDATE yearmonth TGT SET DenseRankTest = SRC.NewRank\nFROM (SELECT Row_ID, DENSE_RANK() OVER (PARTITION BY CustomerID ORDER BY Consumption ASC) AS NewRank\n FROM yearmonth) AS SRC\nWHERE SRC.Row_ID = TGT.Row_ID;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"row_id\" does not exist | LINE 5: FROM (SELECT Row_ID, DENSE_RANK() OVER (PARTITION BY Custome... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "yearmonth" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_499", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n c.customerid,\n (\n SELECT\n CAST(t.transactionid AS TEXT) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n FOR JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.customerid\nWHERE segment = 'SME'\nFOR JSON PATH, WITHOUT_ARRAY_WRAPPER;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JSON\" | LINE 8: FOR JSON PATH | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'transactions_1k' does not exist in schema", + "taxonomy_category": "semantic", + "context": "transactions_1k", + "affected_clauses": [ + "FROM" + ] + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c\n\nInvalid expression / Unexpected token. Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_table", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_501", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER () AS rownum, id_column, decimal_column, nvarchar_column\nFROM json_table(\n '[\n {\"id_column\": 1234, \"decimal_column\": 12.34, \"nvarchar_column\": \"asdf\"},\n {\"id_column\": 5678, \"decimal_column\": 56.78, \"nvarchar_column\": \"fdsa\"}\n ]',\n '$[*]' COLUMNS (\n id_column BIGINT PATH '$.id_column',\n decimal_column DECIMAL(28,8) PATH '$.decimal_column',\n nvarchar_column VARCHAR(30) PATH '$.nvarchar_column'\n )\n) AS data", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"COLUMNS\" | LINE 7: '$[*]' COLUMNS ( | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM-WINDOW", + "clauses_present": [ + "FROM", + "SELECT", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_502", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, value FROM races CROSS JOIN LATERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GROUPING(name) as name FOR value in ('name1','name2','name3','name4')) piv;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"PIVOT\" | LINE 1: ...TERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GRO... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_error", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_503", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_id bigint;\n v_date date;\n db_update_cursor CURSOR FOR\n SELECT id, date\n FROM laboratory\n ORDER BY id, date\n LIMIT 2;\nBEGIN\n OPEN db_update_cursor;\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n WHILE FOUND LOOP\n INSERT INTO destinationTable(testRow)\n VALUES ((SELECT v_id, v_date FOR JSON AUTO));\n\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n END LOOP;\n\n CLOSE db_update_cursor;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"JSON\" | LINE 15: VALUES ((SELECT v_id, v_date FOR JSON AUTO)); | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + } + ], + "tags": [ + "syntax_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_504", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH hero_activity AS\n (SELECT id,\n activity_date,\n activity_value,\n hero_id\n FROM (\n VALUES (1,\n '2023-01-01',\n 10,\n 1), (2,\n '2023-01-02',\n 20,\n 1), (3,\n '2023-02-01',\n 15,\n 1), (4,\n '2023-02-02',\n 25,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function pg_catalog.extract(unknown, text) does not exist | LINE 32: ... SUM(activity_value) OVER (PARTITION BY EXTRACT(YE... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1052, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "VALUES", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "activity_totals", + "hero_activity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_506", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH cte AS\n (SELECT id,\n \"Examination Date\",\n thrombosis,\n risklag = LAG(thrombosis, 1, thrombosis) OVER (PARTITION BY id\n ORDER BY \"Examination Date\"),\n rn = ROW_NUMBER() OVER (PARTITION BY id,\n EXTRACT(YEAR FROM \"Examination Date\"),\n EXTRACT(MONTH FROM \"Examination Date\")\n ORDER", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"risklag\" does not exist | LINE 5: risklag = LAG(thrombosis, 1, thrombosis) OVER (PAR... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_508", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH KEYWORDMATCHES AS\n (SELECT P.ID,\n CASE\n WHEN POSITION(LOWER('Aaron') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Aaron'\n END AS COLAKEYWORD,\n CASE\n WHEN POSITION(LOWER('Cresswell') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Cresswell'\n END AS COLBKEYWORD,\n CASE\n WHEN POSITION(LOWER('Doran') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Doran'\n END AS COLCKEYWORD\n FROM PLAYER AS P),\n KEYWORDSCORES AS\n (SELECT ID,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "for SELECT DISTINCT, ORDER BY expressions must appear in select list | LINE 37: ORDER BY KS.COLASCORE; | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P10" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.1625, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-FILTER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FILTER", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "keywordmatches", + "keywordscores", + "player" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_509", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH ChangeHistory AS (\n\n SELECT\n s.cdscode,\n s.school,\n s.fundingtype,\n s.lastupdate,\n\n DENSE_RANK() OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) AS ChangeSequence,\n\n CASE WHEN LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) IS NULL\n OR LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) <> s.school\n THEN 1 ELSE 0 END AS SchoolChanged,\n CASE WHEN LAG(s.fundingtype) OVER (PARTITION ", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "invalid UNION/INTERSECT/EXCEPT ORDER BY clause | LINE 70: CASE WHEN ColumnName = 'School' THEN 1 ELSE 2 END; | ^ | Only result column names can be used, not expressions or functions. | Add the expression/function to every SELECT, or move the UNION into a FROM clause.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.3083, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "changehistory", + "changesonly", + "schools" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_510", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' || pa.player_api_id::text || ','\n LIKE '%,' || p.player_api_id::text || ',%'\n)\nSELECT\n id,\n name,\n player_api_id = xpath('text()', col)::VARCHAR(100)\nFROM CTE\nCROSS JOIN LATERAL XMLTABLE('/t' PASSING xml_val COLUMNS col XML PATH '.') AS CA\nLI", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"xml_val\" does not exist | LINE 5: xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + }, + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\nExpecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\ndpipe does not support CTE. Line 5, Col: 101.\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''\u001b[4m)\u001b[0m,\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' |\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "schema_hallucination_col", + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "WITH-CTE-SELECT", + "clauses_present": [ + "CTE", + "SELECT", + "WITH" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_511", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH t AS\n (SELECT e.*,\n ROW_NUMBER() OVER (PARTITION BY e.id\n ORDER BY e.\"Examination Date\") AS seqnum\n FROM examination AS e),\n cte AS\n (SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n 'N' AS isrehire,\n t.\"Examination Date\" AS anchordate\n FROM t\n WHERE t.seqnum = 1\n UNION ALL SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n CAS", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"cte\" does not exist | LINE 25: FROM cte | ^ | There is a WITH item named \"cte\", but it cannot be referenced from this part of the query. | Use WITH RECURSIVE, or re-order the WITH items to remove forward references.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination", + "t" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_512", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE T_period_futur AS\n (SELECT 1 AS Tpf_period_id,\n CAST('2021-10-25' AS DATE) AS Tpf_start_period\n UNION ALL SELECT Tpf_period_id + 1 AS Tpf_period_id,\n Tpf_start_period + INTERVAL '1 week'\n FROM T_period_futur\n WHERE Tpf_period_id < 12 )\nSELECT Tpf_period_id,\n Tpf_start_period,\n EXTRACT(YEAR FROM Tpf_start_period) AS Tpf_year,\n CAST(EXTRACT(YEAR FROM Tpf_start_period) AS VARCHAR) || '.' || RIGHT('00' || CAST(EXTRACT(WEEK FROM Tpf_", + "valid": false, + "errors": [ + { + "tag": "schema_type_mismatch", + "message": "recursive query \"t_period_futur\" column 2 has type date in non-recursive term but type timestamp without time zone overall | LINE 3: CAST('2021-10-25' AS DATE) AS Tpf_start_period | ^ | Cast the output of the non-recursive term to the correct type.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42804" + } + ], + "tags": [ + "schema_type_mismatch" + ], + "query_metadata": { + "complexity_score": 0.0635, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "t_period_futur" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_518", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"first_name\" || ' ' || e.\"last_name\" AS email_full_name, e.email, p.position FROM member_email AS e INNER JOIN member_position AS p ON email_full_name = p.full_name", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "column \"email_full_name\" does not exist | LINE 1: ...ber_email AS e INNER JOIN member_position AS p ON email_full... | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42703" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "member_email", + "member_position" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_519", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(motherGroups.Mothers) AS UniqueMotherGroups FROM\n(SELECT STRING_AGG(CAST(c.id AS VARCHAR), '') WITHIN GROUP (ORDER BY c.id) AS Mothers FROM laboratory c GROUP BY c.id) AS motherGroups", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "function string_agg(character varying, unknown, bigint) does not exist | LINE 2: (SELECT STRING_AGG(CAST(c.id AS VARCHAR), '') WITHIN GROUP (... | ^ | No function matches the given name and argument types. You might need to add explicit type casts.", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_520", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n StartDate timestamp;\n EndDate timestamp;\nBEGIN\n StartDate := '2010-02-22 00:00:00';\n EndDate := '2010-02-22 23:59:59';\n\n SELECT *\n FROM team_attributes\n WHERE date BETWEEN StartDate AND EndDate;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "schema_undefined_function", + "message": "operator does not exist: text >= timestamp without time zone | LINE 3: WHERE date BETWEEN StartDate AND EndDate | ^ | No operator matches the given name and argument types. You might need to add explicit type casts. | QUERY: SELECT * | FROM team_attributes | WHERE date BETWEEN StartDate AND EndDate | PL/pgSQL function inline_code_block line 9 at SQL statement", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42883" + } + ], + "tags": [ + "schema_undefined_function" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_521", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH PaymentRanks AS (SELECT payments, ROW_NUMBER() OVER (ORDER BY payments DESC NULLS LAST) AS row_num, DENSE_RANK() OVER (ORDER BY payments DESC NULLS LAST) AS dense_rank_num, COUNT(*) OVER () AS total_count FROM loan), DistinctPayments AS (SELECT COUNT( payments) AS distinct_payment_count FROM loan) SELECT CASE WHEN (SELECT COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM payme", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "syntax error at or near \"WHERE\" | LINE 1: ...inct_payment_count FROM distinctpayments) = 1 AND WHERE paym... | ^", + "taxonomy_category": "syntax", + "context": "PostgreSQL EXPLAIN", + "error_code": "42601" + }, + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'expression' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nRequired keyword: 'true' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nExpected END after CASE. Line 1, Col: 430.\n T COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 \u001b[4mAND\u001b[0m WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END\n\n... and 1 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error", + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distinctpayments", + "loan" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_524", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n spell_starts AS (\n SELECT start_date, end_date\n FROM blackout_periods s1\n WHERE NOT EXISTS (\n SELECT 1\n FROM blackout_periods s2\n WHERE s2.start_date < s1.start_date\n AND s1.start_date <= s2.end_date\n )\n ),\n spell_ends AS (\n SELECT start_date, end_date\n FROM blackout_periods t1\n WHERE NOT EXISTS (\n SELECT 1\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "relation \"merge_table_2\" does not exist | LINE 33: FROM merge_table_2 | ^", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "42P01" + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "blackout_periods", + "spell_ends", + "spell_starts" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_525", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n batch INT := 10000;\nBEGIN\n WHILE batch > 0 LOOP\n BEGIN\n START TRANSACTION;\n INSERT INTO player_stats\n SELECT * FROM player_stats_temp\n LIMIT batch;\n GET DIAGNOSTICS batch = ROW_COUNT;\n COMMIT;\n END;\n END LOOP;\nEND $$;", + "valid": false, + "errors": [ + { + "tag": "schema_unknown_error", + "message": "unsupported transaction command in PL/pgSQL | PL/pgSQL function inline_code_block line 7 at SQL statement", + "taxonomy_category": "semantic", + "context": "PostgreSQL EXPLAIN", + "error_code": "0A000" + } + ], + "tags": [ + "schema_unknown_error" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + } +] \ No newline at end of file diff --git a/tests/output/validator_benchmark_results.json b/tests/output/validator_benchmark_results.json new file mode 100644 index 0000000..94c0fd8 --- /dev/null +++ b/tests/output/validator_benchmark_results.json @@ -0,0 +1,16598 @@ +{ + "summary": { + "total_queries": 514, + "valid": 412, + "invalid": 102, + "parse_exceptions": 0, + "tag_distribution": { + "schema_hallucination_col": 102, + "syntax_invalid_token": 27, + "schema_ambiguous_col": 21, + "syntax_keyword_misuse": 9, + "syntax_unbalanced_tokens": 12, + "schema_hallucination_table": 9, + "syntax_unterminated_string": 1, + "syntax_error": 1 + }, + "per_database": { + "financial": { + "valid": 40, + "invalid": 11 + }, + "codebase_community": { + "valid": 10, + "invalid": 8 + }, + "student_club": { + "valid": 31, + "invalid": 11 + }, + "debit_card_specializing": { + "valid": 34, + "invalid": 2 + }, + "card_games": { + "valid": 37, + "invalid": 14 + }, + "european_football_2": { + "valid": 57, + "invalid": 14 + }, + "superhero": { + "valid": 33, + "invalid": 6 + }, + "toxicology": { + "valid": 53, + "invalid": 10 + }, + "formula_1": { + "valid": 37, + "invalid": 6 + }, + "california_schools": { + "valid": 21, + "invalid": 6 + }, + "thrombosis_prediction": { + "valid": 25, + "invalid": 7 + }, + "erolp": { + "valid": 25, + "invalid": 3 + }, + "esophageal": { + "valid": 6, + "invalid": 2 + }, + "global_atlas": { + "valid": 2, + "invalid": 1 + }, + "spotify": { + "valid": 1, + "invalid": 1 + } + }, + "per_category": { + "Query": { + "valid": 234, + "invalid": 51 + }, + "Management": { + "valid": 60, + "invalid": 20 + }, + "Personalization": { + "valid": 118, + "invalid": 31 + } + } + }, + "results": [ + { + "instance_id": "PostgreSQL_0", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account_id, MAX(payments) AS max_payment, MIN(payments) AS min_payment FROM loan GROUP BY account_id HAVING COUNT(account_id) > 1 AND (MAX(payments) - MIN(payments)) > 2;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0594, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_1", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CreationDate::time FROM comments;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "comments" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_3", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "CREATE UNIQUE INDEX unique_name ON event(event_name, event_date) where event_name is not null;CREATE UNIQUE INDEX unique_location ON event(location, event_date) where location is not null;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE", + "clauses_present": [ + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_4", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE transactions_1k\n SET Amount = 100\n FROM ( SELECT TransactionID FROM transactions_1k WHERE Amount = 50 ORDER BY Date LIMIT 100 FOR UPDATE ) sub\n WHERE transactions_1k.TransactionID = sub.TransactionID RETURNING *;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1042, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT-LOCKING-UPDATE-RETURNING-SUBQUERY", + "clauses_present": [ + "FROM", + "LIMIT", + "LOCKING", + "ORDER", + "RETURNING", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_5", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT users.Id, COUNT(posts.Id) as answered FROM users LEFT JOIN posts ON users.Id = posts.OwnerUserId GROUP BY users.Id ORDER BY answered DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "posts", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_6", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS users;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "users" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_7", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ARRAY_AGG(DISTINCT u.id) AS ids, ARRAY_AGG(DISTINCT u.username) AS usernames, ARRAY_AGG(DISTINCT u.ref1) AS refs1, ARRAY_AGG(DISTINCT u.ref2) AS refs2, COUNT(DISTINCT a.id) AS asset_count FROM assets a JOIN users u ON a.owner = u.ref1 OR a.owner = u.ref2 GROUP BY a.owner ORDER BY MIN(a.id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0948, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "assets", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_8", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH CTE AS ( SELECT link_to_event, COUNT(link_to_member) AS count FROM attendance GROUP BY link_to_event ) SELECT CTE.link_to_event, CTE.count AS newCount, budget.count AS oldCount FROM budget JOIN CTE ON budget.link_to_event = CTE.link_to_event WHERE budget.count != CTE.count;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "attendance", + "budget", + "cte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_9", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "INSERT INTO attendance VALUES ('recEVTik3MlqbvLFi', 'rec280Sk7o31iG0Tx', 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_10", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE account\n SET date__timestamp = date__bigint::timestamp;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'date__timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__timestamp" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__bigint' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__bigint" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_11", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM cards GROUP BY artist;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_12", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "IF SELECT * FROM transactions_1k WHERE CustomerID = 3 AND Date = '2012-08-24' RETURNS NO ROWS\nTHEN SELECT * FROM transactions_1k WHERE CustomerID = 7626 AND Date = '2012-08-24'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_13", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_name\n FROM information_schema.columns As c\n WHERE table_name = 'account'\n AND c.column_name NOT IN('account_id', 'date')\n), ',') || ' FROM accountAs o' As sqlstmt", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "columns" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_14", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 0 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_id = l.account_id\n WHERE account.district_id = '18'\n AND l.date >= (NOW() - INTERVAL '48 hours')\n ORDER BY l.date DESC NULLS LAST\n LIMIT 6\n)\nUNION\n(\n SELECT\n account.account_id,\n account.frequency,\n l.loan_id,\n l.date AS loan_date,\n 1 AS priority\n FROM account\n LEFT JOIN loan l\n ON account.account_i", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_15", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Array_agg(rw) FROM (SELECT link_to_event, (SELECT To_(Array_agg(Row_to_(t))) FROM (SELECT link_to_member FROM public.attendance WHERE link_to_event = b.link_to_event) t) rw FROM attendance b GROUP BY link_to_event);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_16", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT to_char(generate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 123.\n rate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') \u001b[4mFROM\u001b[0m loan;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0125, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_17", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account_id, amount FROM (SELECT account_id, amount, ROW_NUMBER() OVER(PARTITION BY account_id ORDER BY amount DESC) AS rn FROM loan) AS a WHERE rn = 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_18", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE client_information ( client_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) GENERATED ALWAYS AS (concat(first_name, ' ', last_name)) STORED, PRIMARY KEY (client_id) );", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "client_information" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_19", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO cards(uuid, name) VALUES ('5f8287b1-5bb6-5f4c-ad17-316a40d5bb0c', 'Ancestor''s Chosen') ON CONFLICT DO NOTHING RETURNING id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT-RETURNING", + "clauses_present": [ + "INSERT", + "RETURNING", + "VALUES" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_20", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (account_id, district_id, frequency, date) VALUES (1, 18, 'POPLATEK MESICNE', CURRENT_DATE) ON CONFLICT (account_id) DO UPDATE SET date = CURRENT_DATE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_21", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) -1 AS count, MAX(releaseDate), MIN(releaseDate) FROM (SELECT *, date(releaseDate) - row_number() OVER (PARTITION BY releaseDate ORDER BY date(releaseDate)) * INTERVAL '1 day' AS filter FROM sets_releaseInfo ) t1 GROUP BY filter HAVING COUNT(*) -1 > 0 ORDER BY count DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "sets_releaseinfo" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_22", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE path_cte AS (SELECT id, nextCardId, id::TEXT AS Path FROM collection WHERE nextCardId IS NULL UNION ALL SELECT collection.id, collection.nextCardId, collection.id || ' --> ' || cte.Path FROM collection JOIN path_cte cte ON collection.nextCardId = cte.id) SELECT Path FROM path_cte ORDER BY id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "collection", + "path_cte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_23", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_24", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\\n a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) as referencing_table,\\n UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as referencing_col,\\n pg_get_constraintdef(c.oid) contraint_sql FROM pg_constraint c join pg_attribute a on c.confrelid=a.attrelid and a.attnum = ANY(confkey)\\n WHERE c.", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 83.\n SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\u001b[4m\\\u001b[0mn a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) a", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pg_class" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_25", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT first_value(bank ignore nulls) over (partition by account_id order by date rows unbounded following) as next_bank FROM trans;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_26", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team_api_id, team_short_name FROM Team as data FULL OUTER JOIN (SELECT buildUpPlaySpeed, team_api_id FROM Team_Attributes ta WHERE team_api_id = data.team_api_id) AS subquery_alias ON data.team_api_id = subquery_alias.team_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_27", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH one AS ( SELECT date_trunc('year', date) as timeOne, COUNT(*) as trans_count FROM trans ORDER BY timeOne ), two AS ( SELECT date_trunc('year', date) as timeTwo, COUNT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count) as count FROM one, two ORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "The number of provided arguments (2) is greater than the maximum number of supported arguments (1). Line 1, Col: 270.\n NT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count\u001b[4m)\u001b[0m as count FROM one, two ORDER BY 1;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "loan", + "one", + "trans", + "two" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_28", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH gen_transactions AS ( SELECT CustomerID, Amount FROM transactions_1k CROSS JOIN LATERAL generate_series(1, CAST(Amount AS INTEGER)) ) SELECT CustomerID, Amount, ROW_NUMBER() OVER (ORDER BY random()) AS rn FROM gen_transactions LIMIT 5;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0927, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "gen_transactions", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_29", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO card_information(price) SELECT jsonb_agg(price) FROM (SELECT price FROM card_information) AS subquery;SELECT * FROM card_information;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "card_information" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_30", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.k_symbol, t.operation, t.amount, t.balance, a.frequency FROM trans t INNER JOIN account a ON t.account_id = a.account_id WHERE t.account_id = 1 AND t.type = 'PRIJEM' GROUP BY t.k_symbol", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "trans" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_31", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT user_id, COUNT(*) AS num_consecutive_months FROM (SELECT user_id, purchase_date, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) AS month_date, ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD'))) - ROW_NUMBER() OVER(PARTITION BY user_id, DATE_TRUNC('month', TO_DATE(purchase_date || '-01', 'YYYY-MM-DD')) - INTERVAL '1 month' * ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY DATE_TRUNC('month', TO_DATE(purcha", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "purchase" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_32", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH tab_with_cardid AS (\n select split(cardid, '-', 3)ivm_arr,\n\n type,\n last_refresh_date\n FROM db.scema.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 71.\n ma.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) \u001b[4mas\u001b[0m temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\n\n\nRequired keyword: 'this' missing for . Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\nalias does not support CTE. Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'table' does not exist in schema", + "taxonomy_category": "semantic", + "context": "table", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "table" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_33", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT player_api_id, MAX(date), FIRST(overall_rating) FROM Player_Attributes GROUP BY player_api_id ORDER BY date desc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_34", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT Age::numeric FROM users;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "users" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_35", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "begin insert into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.WebsiteUrl, '.', '-'), charindex('@', replace(new.WebsiteUrl, '.', '-')) - 1);return new;end;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 12.\n begin \u001b[4minsert\u001b[0m into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.Webs", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_36", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM cards WHERE availability = 'paper' AND bordercolor = 'black' AND rarity = 'uncommon' AND types = 'Creature';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.049, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_37", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "insert into event (event_id, event_name, event_date, type, notes, location, status) values ('recAlAwtBZ0Fqbr5K', 'Annual Gala', '2023-12-15T19:00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Unknown option DO. Line 1, Col: 251.\n :00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do \u001b[4minsert\u001b[0m into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');\n\nInvalid expression / Unexpected token. Line 1, Col: 244.\n :00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) \u001b[4mdo\u001b[0m insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_38", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION log_player_name_changes() RETURNS trigger AS $BODY$ BEGIN IF NEW.player_name <> OLD.player_name THEN INSERT INTO player_audits(player_id, old_player_name, changed_on) VALUES(OLD.id, OLD.player_name, now()); END IF; RETURN NEW; END; $BODY$ CREATE TRIGGER tr_change_playername AFTER UPDATE OF player_name ON player FOR EACH ROW EXECUTE PROCEDURE log_player_name_changes();", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_39", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT userid, tag\nFROM preference_tag\nWHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'tag' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "tag", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'tag' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "tag", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "preference_tag" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_40", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM account_info WHERE ((condition->0->>'conditions')::json->>'rootcompanyid')::json->>'$in' = '[5]';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "account_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_41", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE hero_power ADD CONSTRAINT unique_active_hero_power UNIQUE (hero_id, power_id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "hero_power" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_42", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT(user_id), email FROM orders o WHERE (o.segment = 'luxury' AND o.destination = 'New York') OR (o.segment = 'luxury' AND o.destination = 'London')", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.049, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_43", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT version FROM cars ORDER BY SUBSTRING(version, '^[0-9]+') DESC, SUBSTRING(version, '[0-9]+\\.[0-9]+\\.([0-9]+)-') DESC, CAST(SUBSTRING(version, '[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+)') AS INTEGER) DESC, SUBSTRING(version, '[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\.([0-9]+)') DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "cars" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_44", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.driverId, ((SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId) - (SELECT COALESCE(SUM(r.points), 0) FROM results r WHERE r.raceId = races.raceId)) AS total_points FROM results r GROUP BY r.driverId", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.15, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_45", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "select count(S.id), A.alignment, count(R.race), R.race from superhero S, alignment A, race R where S.alignment_id=A.id and S.race_id=R.id group by A.alignment, R.race;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "alignment", + "race", + "superhero" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_46", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "select driverId, points, lead(driverId) over (order by points asc) as \"lead(driverId) with order\", array_agg(driverId) over (order by points asc) as \"array_agg(driverId) with order\", lead(driverId) over () as \"lead(driverId) without order\", array_agg(driverId) over () as \"array_agg(driverId) without order\" from results where raceId = 19 order by driverId asc", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_47", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n raceId,\n MAX(time::time) AS end_time,\n MIN(time::time) AS start_time,\n (MAX(time::time) - MIN(time::time)) AS total_duration\nFROM pitStops\nWHERE raceId = 842\nGROUP BY raceId;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_48", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "select label, JSON_AGG(JSON_BUILD_OBJECT(atom.molecule_id, atom.atom_id)) AS groupedMolecules FROM molecule JOIN atom ON molecule.molecule_id = atom.molecule_id GROUP BY label", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_49", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT molecule_id, COALESCE(SUM(CASE WHEN element = 'na' THEN 1 ELSE 0 END), 0) na_atoms, COALESCE(SUM(CASE WHEN element = 'c' OR element = 'cl' THEN 1 ELSE 0 END), 0) c_atoms FROM atom GROUP BY molecule_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0333, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_50", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT home_team_api_id, AVG(home_team_goal) as avg_home_goals, AVG(away_team_goal) as avg_away_goals, SUM(home_team_goal) as total_home_goals, SUM(away_team_goal) as total_away_goals, MAX(home_team_goal) as max_home_goals, MIN(home_team_goal) as min_home_goals, COUNT(home_team_api_id) as count FROM Match GROUP BY home_team_api_id, date_part('hour', date);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_51", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transaction_date AS date, club_name, sum(amount) over (partition by club_name, sign(amount) order by transaction_date) from club_transactions", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "club_transactions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_52", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT array_to_json(array_agg(row_to_json(alias))) FROM (select * from modules ) alias", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "modules" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_53", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO customers (customerid, segment, currency) VALUES (3, 'SME', 'EUR'), (1, 'KAM', 'CZK'), (3, 'SME', 'EUR') ON CONFLICT (customerid, segment, currency) DO UPDATE SET Currency = customers.Currency RETURNING CustomerID;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT-RETURNING", + "clauses_present": [ + "INSERT", + "RETURNING", + "VALUES" + ], + "tables": [ + "customers" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_54", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT client.client_id, client.gender, disp.disp_id, address ->> 'PostCode' AS PostCode FROM client JOIN disp ON client.client_id = disp.client_id CROSS JOIN jsonb_array_elements(disp.addresses) AS address WHERE disp.client_id IN (100, 414);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'address' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "address", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'addresses' does not exist in table 'disp' (referenced as 'disp.addresses')", + "taxonomy_category": "semantic", + "context": "disp.addresses", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "SELECT", + "WHERE" + ], + "tables": [ + "client", + "disp" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_55", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO loan (\n loan_id,\n account_id,\n date,\n amount,\n duration,\n payments,\n status\n)\nVALUES (\n DEFAULT,\n 2,\n '1996-04-29',\n 30276,\n 12,\n 2523.0,\n 'B'\n)\nON CONFLICT (loan_id, account_id, date)\nDO UPDATE\n SET amount = loan.amount + 1000;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_56", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "DELETE FROM cards WHERE (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm1 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) AND (uuid, setCode, rarity, manaCost) NOT IN ( SELECT uuid, setCode, rarity, manaCost FROM norm2 WHERE uuid IS NOT NULL AND setCode IS NOT NULL AND rarity IS NOT NULL AND manaCost IS NOT NULL ) LIMIT 1000;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2385, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT-DELETE-SUBQUERY", + "clauses_present": [ + "DELETE", + "FROM", + "LIMIT", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "norm1", + "norm2" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_57", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION f_gap_fill_update(tbl text, id text, row_num text) RETURNS void LANGUAGE plpgsql AS $func$ DECLARE tmp text[]; col text; BEGIN select array ( select column_name from information_schema.columns c where table_name = tbl ) into tmp; foreach col in array tmp loop execute 'update '||tbl||' set '||col||' = gapfill('||col||') OVER w AS '||col||' where '||tbl||'.row_num = '||col||'.row_num window w as (PARTITION BY '||id||' ORDER BY '||row_num||') returning *;'; end loop; end ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "f_gap_fill_update" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_58", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET disp_id = 1 WHERE disp_id = 41;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_59", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION public.generate_series_monthly(a date, b date) RETURNS SETOF date LANGUAGE SQL IMMUTABLE PARALLEL SAFE ROWS 10 AS $function$ select generate_series(date_trunc('month', a), date_trunc('month', b), '1 month') $function$;EXPLAIN SELECT generate_series_monthly('2024-01-01', '2024-05-01');EXPLAIN SELECT * FROM generate_series_monthly('2024-01-01', '2024-05-01');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_60", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n m.id,\n m.date,\n CASE WHEN m.home_team_goal = m.away_team_goal THEN 1 ELSE 0 END AS invoiced,\n SUM(m.home_team_goal + m.away_team_goal)\n OVER (PARTITION BY (CASE WHEN m.home_team_goal = m.away_team_goal THEN 1 ELSE 0 END)\n ORDER BY m.id, m.date) AS amount\nFROM match AS m\nORDER BY m.id, m.date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_61", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH DataSource AS (\n SELECT\n *,\n MIN(CASE WHEN amount < 10 THEN gasstationid END)\n OVER (PARTITION BY customerid) AS first_issue_gasstation,\n ROW_NUMBER() OVER (PARTITION BY customerid ORDER BY gasstationid DESC) AS gasstation_id\n FROM transactions_1k\n WHERE gasstationid = (\n SELECT MAX(gasstationid)\n FROM transactions_1k\n WHERE customerid = transactions_1k.customerid\n )\n)\nSELECT\n customerid,\n transactionid,\n gasstationid,\n amount\nFROM DataSource\nWHERE\n (first_is", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.201, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "datasource", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_62", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT c1.user_id, COUNT(*) FROM user_actions c1 LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'LOGIN') c2 ON c1.user_id = c2.user_id AND c2.action_time > c1.action_time LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'BUY') c3 ON c1.user_id = c3.user_id AND c3.action_time > c1.action_time AND c3.action_time < c2.action_time WHERE c1.action = 'SEARCH' AND c2.user_id IS NOT NULL AND c3.user_id IS NULL GROUP BY 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action_time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action_time", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action_time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action_time", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2552, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "user_actions" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_63", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.id, c.name FROM cards c WHERE c.id IN (SELECT unnest(card_order) FROM decks WHERE id = 1);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'card_order' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "card_order", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'id' is ambiguous \u2014 exists in tables: cards, decks", + "taxonomy_category": "semantic", + "context": "id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1146, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_64", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ord.order_date, ord.order_id, ord.card_id, prd.price FROM order_cards ord LEFT JOIN (SELECT * FROM card_prices ORDER BY start_date ASC) AS prd ON ord.card_id = prd.card_id AND ord.order_date >= prd.start_date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1365, + "pattern_signature": "SELECT-FROM-JOIN-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "card_prices", + "order_cards" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_65", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "select player_id, stats_keys, stats_values from player_stats", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "player_stats" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_66", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE teams_config SET configurations = jsonb_set(configurations, '{settings}', (configurations->'id') - (SELECT DISTINCT position - 1 FROM teams_config, jsonb_array_elements(configurations) WITH ORDINALITY arr(elem, position) WHERE elem->>'id' = '101')::int);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "teams_config" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_67", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT begin_date, end_date, age(CASE WHEN end_date = date_trunc('month', end_date) + interval '1 month - 1 day' THEN end_date + interval '1 day' ELSE date_trunc('month', end_date) END::date, CASE WHEN begin_date = date_trunc('month', begin_date) THEN begin_date ELSE date_trunc('month', begin_date) + interval '1 month' END::date) AS calculated_months FROM race_dates;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "race_dates" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_68", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO new_attendance (link_to_event, link_to_member, date)\n VALUES ('reciRZdAqNIKuMC96', 'recL94zpn6Xh6kQii', NOW())\n ON CONFLICT\n WHERE link_to_member='recL94zpn6Xh6kQii' DO NOTHING;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES", + "WHERE" + ], + "tables": [ + "new_attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_69", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "pg_advisory_xact_lock(lkhndl);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_70", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n link_to_member,\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN CEIL(SUM(hours) / 10) * 10\n ELSE FLOOR(SUM(hours) / 10) * 10\n END AS rounded_hours,\n RANK() OVER (ORDER BY\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_71", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE INDEX ix_account ON account USING btree (district_id, frequency, date);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_72", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "create or replace view findcount(season, team_count) as\n select\n season,\n findteam(season) as team_count\n from (\n select distinct season\n from match\n where season >= '2008/2009'\n ) seasons;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "findcount", + "match" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_73", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "select posttypeid\n case when tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from posts", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 17.\n select posttypeid\n case \u001b[4mwhen\u001b[0m tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_74", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id last_update DESC;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 98.\n SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id \u001b[4mlast_update\u001b[0m DESC;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_75", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT entity_id, coalesce(change->'height', lag(change->'height', 1, null) over (partition by entity_id order by updated_at)) as height, coalesce(change->'weight', lag(change->'weight', 1, null) over (partition by entity_id order by updated_at)) as weight, updated_at FROM ( SELECT entity_id, json_object_agg(column_id, value) as change, updated_at FROM player_stats_changes GROUP BY entity_id, updated_at) as changes;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1083, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "player_stats_changes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_76", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "with qr1(item, subgroup) AS (SELECT id, subgroup1 FROM superhero_group WHERE subgroup1 IS NOT NULL), qr2(item, subgroup) AS (SELECT id, subgroup2 FROM superhero_group WHERE subgroup2 IS NOT NULL) select item, subgroup1, subgroup2, dense_rank() over (order by item) as group from (select qr1.item, qr1.subgroup as subgroup1, qr2.subgroup as subgroup2 from qr1 full outer join qr2 on qr1.item = qr2.item) as combined", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "qr1", + "qr2", + "superhero_group" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_77", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH r AS (SELECT id, date_of_visit, SUM(sessions) AS sessions, SUM(pageviews) AS pageviews, SUM(bounces) AS bounce, COALESCE(utm_campaign, '') AS utm_campaign, COALESCE(utm_source, '') AS utm_source, COALESCE(utm_medium, '') AS utm_medium, COALESCE(utm_content, '') AS utm_content, COALESCE(utm_term, '') AS utm_term FROM report GROUP BY id, date_of_visit, utm_campaign, utm_source, utm_medium, utm_content, utm_term UNION SELECT id, date_of_visit, SUM(sessions), SUM(pageviews), SUM(bounces), COALE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2771, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "r", + "report", + "utm" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 36 + } + }, + { + "instance_id": "PostgreSQL_78", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n id,\n text,\n REGEXP_MATCHES(\n text,\n '\\{.*?\\}',\n 'g'\n ) AS bracketed_tokens\nFROM cards;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_79", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT race_id, top(count(*), 5) as cnt FROM superhero group by gender_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_80", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT rulings.id, rulings.date, rulings.text, rulings.uuid FROM rulings WHERE rulings.uuid IN ('6d268c95-c176-5766-9a46-c14f739aba1c', '56f4935b-f6c5-59b9-88bf-9bcce20247ce', '8dfc67e9-8323-5d1f-9e25-9f9394abd5a0', '5ac794d2-4c66-5332-afb1-54b24bc11823', '60f49caf-3583-5f85-b4b3-08dca73a8628') GROUP BY rulings.id ORDER BY rulings.id LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "rulings" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_81", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select rank() over (order by total_points desc) as place, id, name, total_points, race_points, raceId from racers", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "racers" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_82", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT month_year, COUNT(DISTINCT customer_id) FROM orders GROUP BY month_year HAVING COUNT(order_id) > 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_83", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT player_name, event_date as join_date, (SELECT event_date FROM player_movements pm1 WHERE pm1.player_name = pm.player_name AND pm1.event = 'Leave' AND pm1.event_date > pm.event_date) as leave_date FROM player_movements pm WHERE event = 'Join'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.125, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "player_movements" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_84", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select account_id, date,\n sum(amount) OVER (PARTITION BY account_id, date) as total_amount,\n sum(balance) OVER (PARTITION BY account_id, date) as total_balance,\n count(trans_id) OVER (PARTITION BY account_id, date) as total_transactions\n from trans", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0292, + "pattern_signature": "SELECT-FROM-WINDOW", + "clauses_present": [ + "FROM", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_85", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE (Date, Time, Amount) < ('2012-08-24', '10:00:00', 20);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_86", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT client.gender, loan.amount, loan.duration, account.date FROM loan JOIN account ON loan.account_id = account.account_id JOIN client ON disp.client_id = client.client_id JOIN disp ON account.account_id = disp.account_id WHERE loan.date BETWEEN '1996-01-01' AND '1996-12-31';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "client", + "disp", + "loan" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_87", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "with cte as (select pv1.session_id, pv1.post_id, pv2.view_perc, pv1.ts as start_time, min(pv2.ts) as end_time from view_logs pv1 join view_logs pv2 on pv1.session_id = pv2.session_id and pv1.post_id = pv2.post_id and pv1.event_name <> pv2.event_name and pv1.ts < pv2.ts group by pv1.session_id, pv1.post_id, pv2.view_perc, pv1.ts) select session_id, post_id, start_time, end_time, case when (end_time - start_time > 3 and view_perc > 0.8 )then 'yes' else 'no' end as has_meaningful_view from cte;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WITH" + ], + "tables": [ + "cte", + "view_logs" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_88", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "delete from superhero where id = 999 returning 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-DELETE-RETURNING", + "clauses_present": [ + "DELETE", + "RETURNING", + "WHERE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_89", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION GapFillInternal(s anyelement, v anyelement) RETURNS anyelement AS $$ DECLARE temp alias for $0; BEGIN F v IS NULL AND s NOTNULL THEN temp := s; ELSIF s IS NULL AND v NOTNULL THEN temp := v; ELSIF s NOTNULL AND v NOTNULL THEN temp := v; ELSE temp := NULL; END;END; $$ LANGUAGE PLPGSQL;CREATE AGGREGATE GapFill(anyelement) (SFUNC=GapFillInternal, STYPE=anyelement);SELECT id, publisher_id, height_cm, weight_kg, GapFill(height_cm) OVER (PARTITION BY publisher_id ORDER BY id)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_90", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 1 THEN amount ELSE NULL END) AS yesterday_revenue, ROUND((SUM(CASE WHEN timestamp::date > '2022-01-27'::date - 1 THEN amount ELSE NULL END) - SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 8 THEN amount ELSE NULL END)) / SUM(CASE WHEN timestamp::date = '2022-01-27'::date - 8 THEN amount ELSE NULL END), 2) AS pct_change_week_ago, SUM(CASE WHEN date_trunc('month', timestamp) = date_trunc('month', '2022-01-27'::date - 1) THEN amount ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "transactions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 8 + } + }, + { + "instance_id": "PostgreSQL_91", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, convertedManaCost, avg(convertedManaCost) OVER(ORDER BY id ROWS BETWEEN 8 PRECEDING AND CURRENT ROW) AS nine_card_avg FROM cards WHERE name LIKE 'A%' ORDER BY id DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_92", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT hero_id, attribute_id, jsonb_array_length(a.ss) AS ss_cnt, jsonb_array_length(CASE WHEN a.ss -> 'approved' = 'true' THEN a.ss END) AS approved_cnt FROM hero_attribute a WHERE a.hero_id IN (1, 2);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_93", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT set_translations.language\n CASE WHEN set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'common'\n ELSE 'not common'\n END\n FROM set_translations", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 23.\n SELECT set_translations.language\n CASE \u001b[4mWHEN\u001b[0m set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'com", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_94", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$ DECLARE i integer; BEGIN\n FOREACH i IN ARRAY[11, 20]::integer[] LOOP\n RAISE NOTICE 'Value: %', i;\n UPDATE Player_Attributes SET overall_rating = i\n WHERE player_api_id = ANY (ARRAY[505942, 155782]::integer[])\n AND date = ANY (ARRAY['2016-02-18 00:00:00', '2015-10-16 00:00:00']::text[]);\n END LOOP;\n END $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_95", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT resultId FROM results WHERE to_tsvector(results.fastestLapTime) @@ to_tsquery('1:35.405');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_96", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT raceId, position, COUNT(*) as cnt FROM results GROUP BY raceId, position", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_97", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM Match WHERE (match_api_id, date, id) > (492473, '2008-08-17 00:00:00', 1) ORDER BY date, id ASC LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_98", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT School FROM schools GROUP BY School HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_99", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT MAX(date), raceid, name FROM races GROUP BY name, raceid HAVING MAX(date) = date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_100", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t.team_name, o.outcome FROM (VALUES('Team A'),('Team B')) AS t(team_name) JOIN (VALUES('win'),('lose'),('draw')) AS o(outcome);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.026, + "pattern_signature": "SELECT-FROM-JOIN-VALUES", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "VALUES" + ], + "tables": [], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_101", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (\"County Code\") * FROM frpm ORDER BY \"County Code\", \"Enrollment (K-12)\" DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'County Code' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "County Code", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'County Code' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "County Code", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Enrollment (K-12)' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Enrollment (K-12)", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_102", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(quantity) FROM race_materials WHERE price_per_unit * quantity <= 100;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "race_materials" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_103", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO historical_rating (player_fifa_api_id, player_api_id, grouped_rating) SELECT player_fifa_api_id, player_api_id AS grouped_rating FROM player_attributes GROUP BY player_fifa_api_id, player_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "SELECT-FROM-GROUP-INSERT", + "clauses_present": [ + "FROM", + "GROUP", + "INSERT", + "SELECT" + ], + "tables": [ + "historical_rating", + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_104", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT id, acceptedanswerid, posttypeid, score FROM posts WHERE score >= 20 OR acceptedanswerid IS NOT NULL AND score >= 20 GROUP BY id, acceptedanswerid;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0385, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_105", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH card_activity AS ( SELECT to_date(fe.start_date_key::text, 'YYYYMMDD') AS start_date, to_date(fe.end_date_key::text, 'YYYYMMDD') AS end_date, dp.set_name, dp.set_code FROM fact_collection fe INNER JOIN dim_set dp ON fe.set_key = dp.set_key ) SELECT date_trunc('month', month_series) AS month, COUNT(*) AS existing_cards, sa.set_name FROM ( SELECT generate_series( (SELECT MIN(to_date(start_date_key::text, 'YYYYMMDD')) FROM fact_collection), '2100-12-31', INTERVAL '1 month') AS month_series ) A", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date_key' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date_key", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.275, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WITH" + ], + "tables": [ + "card_activity", + "dim_set", + "fact_collection" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_106", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH mission_spans AS ( SELECT hero_id, mission_start, mission_end FROM superhero_missions ORDER BY hero_id, mission_start, mission_end ) SELECT hero_id, MIN(mission_start) OVER (PARTITION BY hero_id), MAX(mission_end) OVER (PARTITION BY hero_id) FROM mission_spans ORDER BY 1, 2, 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0792, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "mission_spans", + "superhero_missions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_107", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT percentile_cont(0.5) within group (ORDER by releasedate) FROM sets", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "sets" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_108", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE race_incidents ( incident_type VARCHAR(30) NOT NULL CHECK(incident_type = 'Engine failure' OR incident_type = 'Collision'), incident_description VARCHAR(30) NOT NULL);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "race_incidents" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_109", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "select * from trans t1 where (account_id, trans_id) in (select account_id, max(trans_id) from trans t1 group by account_id);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_110", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.league_id) SELECT * FROM recuree", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting (. Line 1, Col: 108.\n ITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE \u001b[4mrecuree\u001b[0m AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON \n\nRequired keyword: 'expressions' missing for . Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\nExpecting ). Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'recuree' does not exist in schema", + "taxonomy_category": "semantic", + "context": "recuree", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "league", + "recuree", + "tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_111", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "SELECT *\nFROM superhero.\"%_id\";", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table '%_id' does not exist in schema", + "taxonomy_category": "semantic", + "context": "%_id", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "%_id" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_112", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO races (raceid, year, round, circuitid, name, date, time, url)\nVALUES (\n 999,\n 2023,\n 1,\n 2,\n 'Test Grand Prix',\n '2023-04-01',\n '12:00:00',\n 'http://example.com'\n)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_113", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n sub.raceId,\n sub.t[1] AS \"Lap_Time_Race1\",\n sub.t[2] AS \"Lap_Time_Race2\",\n sub.t[3] AS \"Lap_Time_Race3\"\nFROM (\n SELECT\n driverId,\n raceId,\n ARRAY_AGG(milliseconds ORDER BY lap) AS t\n FROM lapTimes\n WHERE driverId = 1\n GROUP BY driverId\n) AS sub\nORDER BY sub.raceId;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "laptimes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_114", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM Examination AS e LEFT JOIN LATERAL (SELECT * FROM Laboratory WHERE ID = e.ID ORDER BY Date DESC LIMIT 2) AS lab ON true", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'ID' is ambiguous \u2014 exists in tables: laboratory, examination", + "taxonomy_category": "semantic", + "context": "ID", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-LATERAL-WHERE-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "examination", + "laboratory" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_115", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "select a.f as \"id\", count(a.f) as \"num\" from ( select atom_id as f from connected union all select atom_id2 as f from connected ) a group by a.f order by count(a.f) desc limit 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "connected" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_117", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceId, name, year, COUNT(*) AS same_year_races FROM races GROUP BY raceid, name, year", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_118", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "with hero_attribute_data (hero_id, attribute_id, max_score, year_1, year_2, year_3, year_4, year_5) as (values (1, 1, 80, 80, 80, 80, null, 80), (2, 2, 90, 90, 85, 90, 88, 90), (3, 3, 75, 75, 70, null, 75, 75), (4, 4, 60, null, 60, 60, 60, null)), score_check as (select *, case when (max_score <> year_1 or max_score <> year_2 or max_score <> year_3 or max_score <> year_4 or max_score <> year_5) then false else true end as is_a_match from hero_attribute_data) select * from score_check where is_a_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1156, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "VALUES", + "WHERE", + "WITH" + ], + "tables": [ + "hero_attribute_data", + "score_check" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_119", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "select item_id, item_price as retail_price, sum(coalesce(uses_item_price, 0) * quantity) + sum(coalesce(resource_price*quantity, 0)) as partial_craft_price FROM store GROUP BY item_id, retail_price;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "store" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_120", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET full_name = 'Superman' JOIN team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team_member_superhero.team_member_id = team_member.id WHERE team_id = 91;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n UPDATE superhero SET full_name = 'Superman' \u001b[4mJOIN\u001b[0m team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_121", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, CASE WHEN e.id = p.id AND e.diagnosis = 'SLE' THEN TRUE ELSE FALSE END AS SLE, CASE WHEN e.id = p.id AND e.diagnosis = 'PSS' THEN TRUE ELSE FALSE END AS PSS, CASE WHEN e.id = p.id AND e.diagnosis = 'RA susp.' THEN TRUE ELSE FALSE END AS RA_susp FROM patient p LEFT JOIN examination e ON p.id = e.id WHERE e.diagnosis IN ('SLE', 'PSS', 'RA susp.') ORDER BY p.id DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0854, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "examination", + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_122", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT hbi.id, hbi.hero_name, hbi.birthdate, hbialt.date_of_birth FROM hero_birth_info hbi LEFT JOIN hero_birth_info_alt hbialt ON hbi.id = hbialt.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "hero_birth_info", + "hero_birth_info_alt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_123", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION reindex_superhero_ids(IN BIGINT) RETURNS VOID LANGUAGE SQL AS $$ CREATE TEMPORARY SEQUENCE id_seq_temp MINVALUE 1 START WITH 1 INCREMENT BY 1; ALTER SEQUENCE id_seq_temp RESTART; UPDATE superhero SET hair_colour_id=hair_colour_id+2000 WHERE publisher_id=$1; UPDATE superhero SET hair_colour_id=nextval('id_seq_temp') WHERE publisher_id=$1; $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "reindex_superhero_ids" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_124", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card_versions SET seqnr=seqnr+1 WHERE defn_id = 100 AND attr_id = 100 AND seqnr >= 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0385, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "card_versions" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_126", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE atom_ancestors AS ( SELECT atom_id, parent_id, enabled FROM connection WHERE atom_id = 4 UNION ALL SELECT c.atom_id, c.parent_id, c.enabled FROM connection c INNER JOIN atom_ancestors aa ON c.atom_id = aa.parent_id) SELECT * FROM atom_ancestors", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom_ancestors", + "connection" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_127", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select customerid,\n (select jsonb_agg(t->>'dis') from jsonb_array_elements(preference::jsonb) as x(t) where t->>'dis' is not null) as sdata\nfrom card_preference where customerid='123.abc'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1042, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "card_preference" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_128", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT hero_id, 'attribute_value' AS Difference FROM hero_attribute\nGROUP BY hero_id HAVING COUNT(DISTINCT attribute_value) > 1\nOR (COUNT(attribute_value) != COUNT(*) AND COUNT(DISTINCT attribute_value) > 0)\nUNION ALL SELECT hero_id, 'attribute_id' AS Difference FROM hero_attribute GROUP BY hero_id\nHAVING COUNT(DISTINCT attribute_id) > 1 OR (COUNT(attribute_id) != COUNT(*)\nAND COUNT(DISTINCT attribute_id) > 0)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-UNION", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "UNION" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 8 + } + }, + { + "instance_id": "PostgreSQL_129", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO member(member_id, first_name, last_name) VALUES ('new_member_id', 'John', 'Doe','rec06DF6vZ1CyPKpc') ON CONFLICT (member_id) DO UPDATE SET first_name=excluded.first_name, last_name=excluded.last_name;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "member" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_130", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS streak_count, 'April Meeting' AS event_name, 'MST' AS timezone, MIN(event_date) AS start_date, MAX(event_date) AS end_date FROM attendance WHERE event_name = 'April Meeting' GROUP BY DATE_TRUNC('day', event_date AT TIME ZONE 'UTC' AT TIME ZONE 'MST') ORDER BY end_date DESC LIMIT 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_131", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DATE_TRUNC('day', to_timestamp(transaction_timestamp / 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC('day', transaction_timestamp)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'transaction_timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "transaction_timestamp", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'transaction_timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "transaction_timestamp", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_132", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "select a.id, a.date, a.got, a.gpt from laboratory as a inner join ( select id, max(date) as date from laboratory group by id ) as b on a.id = b.id and a.date = b.date order by id, date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "laboratory" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_133", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH constructor_roles AS ( SELECT 18 race_id, 1 constructor_id, false customer_billing, true commander, true agent UNION ALL SELECT 18, 2, true, false, false ) SELECT n.race_id, string_agg(distinct CASE WHEN n.customer_billing = TRUE THEN 'AR (Customer Billing)' WHEN n.commander = TRUE THEN 'AP (Commander)' WHEN n.agent = TRUE THEN 'AP (Agent)' ELSE NULL END, ', ') AS finance FROM constructor_roles n WHERE n.race_id = 18 AND (n.customer_billing = TRUE or n.commander = TRUE or n.agent = TRUE) GR", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "constructor_roles" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_134", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.firstName, jsonb_agg(DISTINCT jsonb_build_object('yearId', y.id, 'classes', (SELECT jsonb_agg(jsonb_build_object('classId', c.id)) FROM classes AS c WHERE y.id = cy.yearId AND c.id = cy.classId AND s.id = cys.studentId))) AS years FROM users3 AS s LEFT JOIN classYearStudents AS cys ON cys.studentId = s.id LEFT JOIN classYears AS cy ON cy.id = cys.classYearId LEFT JOIN years AS y ON y.id = cy.yearId GROUP BY s.id order by s.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2375, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "classes", + "classyears", + "classyearstudents", + "users3", + "years" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_135", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE EmpMgrCTE AS (SELECT id, bossid, salary, 0 as EmployeeLevel FROM staff WHERE bossid IS NULL UNION ALL SELECT emp.id, emp.bossid, emp.salary, mgr.EmployeeLevel + 1 as EmployeeLevel FROM staff emp INNER JOIN EmpMgrCTE mgr ON emp.bossid = mgr.id) SELECT * FROM EmpMgrCTE emp", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "empmgrcte", + "staff" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_136", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "select rarity, id from cards order by convertedmanacost desc nulls last, edhrecrank desc nulls last, multiverseid asc limit 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_137", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS card, account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, frequency TEXT NOT NULL, date DATE NOT NULL, disp_id INT NOT NULL, FOREIGN KEY (disp_id) REFERENCES disp(disp_id) ON UPDATE CASCADE ON DELETE CASCADE);CREATE TABLE disp (disp_id INT PRIMARY KEY NOT NULL, client_id INT NOT NULL, account_id INT NOT NULL, type TEXT NOT NULL, FOREIGN KEY (account_id) REFERENCES account(account_id) ON UPDATE CASCADE ON DELETE CASCADE);", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 26.\n DROP TABLE IF EXISTS card\u001b[4m,\u001b[0m account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_138", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COALESCE(json_agg(CASE WHEN client.client_id IS NULL THEN NULL ELSE json_build_object('client_id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS clients FROM client;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 207.\n _id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS \u001b[4mclients\u001b[0m FROM client;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_139", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "select * from transactions_1k e\nwhere exists\n ( select * from transactions_1k e2\n where e.date=e2.date and e.time=e2.time\n and e.cardid=e2.cardid\n and e.gasstationid=e2.gasstationid\n and e.productid='2' and e2.productid='5') order by e.date asc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0771, + "pattern_signature": "SELECT-FROM-WHERE-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_140", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, amount as cum_sum, 1 as bucket from transfer where id = 1 union all select transfer.id, (case when cum_sum + amount > 20 then amount else cum_sum + amount end), (case when cum_sum + amount > 20 then bucket + 1 else bucket end) from cte join transfer on transfer.id = cte.id + 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'cte' does not exist in schema", + "taxonomy_category": "semantic", + "context": "cte", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "cte", + "transfer" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_141", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceid mode() within group(order by laps) as modal_laps FROM results;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 19.\n SELECT raceid mode\u001b[4m(\u001b[0m) within group(order by laps) as modal_laps FROM results;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_143", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "update match set stage = stage + 1 where id = 'match1';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_144", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "with hero_attribute(hero_id, attribute_id, attribute_value) as ( values (1, 1, 80), (2, 1, 75), (3, 1, 95), (4, 1, 85), (5, 1, 90), (6, 1, 70) ) select sum(attribute_value) from hero_attribute group by (hero_id-1) / 2;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0625, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "VALUES", + "WITH" + ], + "tables": [ + "hero_attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_145", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, name, d ->> 'description' as skill from player_skills, json_array_elements(skills) as d;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'd' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "d", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'skills' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "skills", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "player_skills" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_146", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE when (t.events::json->0->'id')::varchar::int = 2 then (t.events::json->0)::varchar when (t.events::json->1->'id')::varchar::int = 2 then (t.events::json->1)::varchar when (t.events::json->2->'id')::varchar::int = 2 then (t.events::json->2)::varchar else null::varchar end as \"result\" FROM match_events as t;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "match_events" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_147", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(\"ANA Pattern\") AS c, \"ANA Pattern\", EXTRACT(YEAR FROM \"Examination Date\") AS examination_year FROM examination WHERE EXTRACT(YEAR FROM \"Examination Date\") BETWEEN 1993 AND 1996 GROUP BY EXTRACT(YEAR FROM \"Examination Date\"), \"ANA Pattern\" ORDER BY examination_year, c DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_148", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH player_names AS (SELECT 1 AS source, ROW_NUMBER() OVER (ORDER BY player_name) AS row_number, CONCAT(player_name, '(', LEFT(birthday, 4), ')') AS dest FROM player_table), birth_year_summary AS (SELECT 2 AS source, ROW_NUMBER() OVER (ORDER BY COUNT(*), LEFT(birthday, 4)) AS row_number, CONCAT('There are a total of ', COUNT(*), ' player', CASE WHEN COUNT(*) > 1 THEN 's' ELSE '' END, ' born in ', LEFT(birthday, 4), '.') AS dest FROM player_table GROUP BY LEFT(birthday, 4)) SELECT dest FROM (SEL", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1292, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "birth_year_summary", + "player_names", + "player_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_149", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT rs.raceId AS race_id, string_agg(constructorId::TEXT, ',' ORDER BY res.resultId) AS constructor_ids, string_agg(p.stop::TEXT, ', ' ORDER BY p.raceId) AS stops FROM races rs LEFT JOIN results res ON res.raceId = rs.raceId LEFT JOIN pitstops p ON rs.raceId = p.raceId GROUP BY rs.raceId", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "pitstops", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_150", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT r.id, r.start_day, r.end_day, de.point_of_delivery_plant_name, de.point_of_delivery_plant_number, de.visit_status FROM route r JOIN route_detail de ON de.route_id = r.id WHERE NOT EXISTS (SELECT 1 FROM route ro JOIN route_detail rd ON rd.route_id = ro.id JOIN route_event ev ON ev.route_detail_id = rd.id WHERE rd.route_id = r.id AND ev.event_type !=3 AND rd.visit_status = '5' AND rd.id = de.id) AND de.visit_status = '5' GROUP BY 1,2,3,4,5,6 ORDER BY r.id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1656, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "route", + "route_detail", + "route_event" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_151", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION update_team_attributes_eff_to() RETURNS TRIGGER AS $$ BEGIN UPDATE team_attributes SET eff_to = subquery.next_date FROM ( SELECT COALESCE( LEAD(TO_TIMESTAMP(date, 'YYYY-MM-DD HH24:MI:SS')::DATE, 1) OVER ( ORDER BY TO_TIMESTAMP(date, 'YYYY-MM-DD HH24:MI:SS')::DATE DESC), TO_DATE('6000-00-00', 'YYYY-MM-DD') ) - 1 AS next_date FROM team_attributes ) AS subquery; RETURN NULL; END; $$ LANGUAGE plpgsql;CREATE OR REPLACE TRIGGER after_insert_team_attributes AFTER INSERT ON te", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "update_team_attributes_eff_to" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_152", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "select position, array_agg(driverid) as driverids from results group by position having COUNT(*)>1 order by position", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_153", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "WITH RECURSIVE cte AS ( SELECT id, parent_id, color FROM superhero2 WHERE parent_id IS NULL UNION ALL SELECT s.id, s.parent_id, CASE WHEN c1.color IS NULL THEN c2.color WHEN c2.color IS NULL THEN c1.color WHEN c1.color = c2.color THEN c1.color ELSE 'gray' END AS color FROM superhero2 s LEFT JOIN cte c1 ON s.id = c1.parent_id LEFT JOIN cte c2 ON s.id = c2.parent_id ) UPDATE superhero2 SET color = cte.color FROM cte WHERE superhero2.id = cte.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-UPDATE", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "UPDATE", + "WHERE", + "WITH" + ], + "tables": [ + "cte", + "superhero2" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_154", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT artist, setcode, COUNT(setcode) AS counter FROM cards GROUP BY setcode, artist HAVING COUNT(setcode) > 1 ORDER BY counter DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_155", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\nFROM circuit_json;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 3, Col: 4.\n SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\n\u001b[4mFROM\u001b[0m circuit_json;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_156", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT y.district_id,\n CASE WHEN y.status IN ('A', 'B') THEN array_agg(loan_id) END AS type_A_B,\n CASE WHEN y.status = 'C' THEN array_agg(loan_id) END AS type_C\nFROM (\n SELECT x.district_id, l.loan_id, l.status\n FROM loan l\n JOIN account x ON l.account_id = x.account_id\n) y\nGROUP BY 1, y.status\nORDER BY 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1385, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "account", + "loan" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_157", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ts, superhero_id, activity_code, LEAD(ts) OVER (PARTITION BY superhero_id, activity_code ORDER BY ts) as next_ts FROM superhero_activities", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "superhero_activities" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_158", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT count(*) FROM card_matches INNER JOIN card_players ON card_matches.player1_id = card_players.id OR card_matches.player2_id = card_players.id WHERE card_players.type = 'Pro'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in table 'card_players' (referenced as 'card_players.type')", + "taxonomy_category": "semantic", + "context": "card_players.type", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'player1_id' does not exist in table 'card_matches' (referenced as 'card_matches.player1_id')", + "taxonomy_category": "semantic", + "context": "card_matches.player1_id", + "affected_clauses": [ + "JOIN" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'player2_id' does not exist in table 'card_matches' (referenced as 'card_matches.player2_id')", + "taxonomy_category": "semantic", + "context": "card_matches.player2_id", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "card_matches", + "card_players" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_159", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH all_dates AS (SELECT league_id, season, ARRAY_AGG(DISTINCT id order by id) as match_ids, date AS match_date FROM match WHERE season IS NOT NULL AND league_id IS NOT NULL AND id is not null AND date IS NOT NULL GROUP BY league_id, season, date) SELECT DISTINCT league_id, season, match_ids, ARRAY_AGG(DISTINCT all_dates.match_date ORDER BY match_date) AS dates FROM all_dates GROUP BY season, league_id, match_ids order by league_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1177, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "all_dates", + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_160", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "select * from crosstab ('select id, uuid, text from ruling order by 1,2') AS final_result(id int, uuid1 text, uuid2 text, uuid3 text);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_161", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.*\nFROM cards_info c\nWHERE NOT EXISTS (\n SELECT 1\n FROM card_choice cc\n WHERE cc.card_id = c.id\n AND c.id = ANY (cc.non_valid_cards)\n);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "card_choice", + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_162", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE nodes AS (\n SELECT\n uuid,\n card_name AS name,\n ARRAY[]::uuid[] AS parents\n FROM card_type\n WHERE parent_uuid IS NULL\n\n UNION ALL\n\n SELECT\n c.uuid,\n c.card_name AS name,\n nodes.parents || c.uuid\n FROM card_type c\n JOIN nodes ON nodes.uuid = c.parent_uuid\n)\nSELECT * FROM nodes;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "card_type", + "nodes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_163", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT d.the_day AS \"Date\", COUNT(e.event_id) AS \"Number of Events\", AVG(b.remaining) AS \"Avg Remaining Budget\" FROM (SELECT ts::date AS the_day FROM generate_series (timestamp '2020-01-01', timestamp '2020-03-31', interval '1 day'::interval) ts) d LEFT JOIN \"event\" e ON e.event_date::date = d.the_day LEFT JOIN budget b ON b.link_to_event = e.event_id GROUP BY d.the_day ORDER BY d.the_day;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'ts' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ts", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_164", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT LPAD(extract (month from trans.date)::text, 2, '0') as month, sum(trans.amount) as a1997 from trans WHERE trans.date >= '1997-01-01' and trans.date < '1998-01-01' group by month order by 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_165", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM circuits WHERE ST_DWithin(ST_SetSRID(ST_MakePoint(lng, lat), 4326)::geography, ST_ClosestPoint((ST_MakePoint(lng, lat), 4326)::geography, ST_Collect(Array[ST_SetSRID(ST_MakePoint(2.76083, 101.73800), 4326)::geography, ST_SetSRID(ST_MakePoint(26.03250, 50.51060), 4326)::geography])), 1000000, FALSE);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "circuits" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_167", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT driverid, points, (points * 100) as earnings, CASE WHEN (points * 100) > 5000 THEN (points * 100) * 0.2 WHEN (points * 100) > 3000 THEN (points * 100) * 0.15 ELSE null END AS bonus FROM driverstandings", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "driverstandings" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_168", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with dataset as (\n SELECT\n date,\n COUNT(*) as rows_added\n FROM\n team_attributes\n WHERE\n date between '2010-01-01 00:00:00'\n AND '2015-12-31 00:00:00'\n GROUP BY\n date\n )\nSELECT\n COUNT(*) as total_days_in_result_set,\n COUNT(DISTINCT rows_added) as total_days_w_distinct_record_counts,\n COUNT(*) - COUNT(DISTINCT rows_added) as toal_days_w_duplicate_record_counts\nFROM dataset", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1052, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "dataset", + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_169", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "insert into card_counters (card_name, counters) values ('Lightning Bolt', array[2,0,2,1]) on conflict (card_name) do update set counters = array_agg(unnest(card_counters.counters) + unnest(array[2,0,2,1]))", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'counters' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "counters" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'counters' does not exist in table 'card_counters' (referenced as 'card_counters.counters')", + "taxonomy_category": "semantic", + "context": "card_counters.counters" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "card_counters" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_170", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "select id, round(prev + event * sum(prev) over(order by id range between unbounded preceding and 1 preceding)::numeric(10, 6), 6) as not_quite_my_tempo from (select *, event*sum(trx) over(order by id) as prev from sales_transactions) t order by id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "sales_transactions" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_171", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH cte_funding_count AS (SELECT fundingtype, COUNT(*) AS count FROM schools GROUP BY fundingtype) SELECT fundingtype, count, ROUND(count*100/(SELECT SUM(count) FROM cte_funding_count),0) AS percent FROM cte_funding_count", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1125, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WITH" + ], + "tables": [ + "cte_funding_count", + "schools" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_172", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT lab.date AS firstActivity, pat.id FROM patient pat JOIN laboratory lab ON lab.id = pat.id AND lab.date <= pat.description AND lab.date > pat.\"First Date\" WHERE pat.sex='F' order by pat.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.075, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "laboratory", + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_173", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "select id, array_agg(elem) from cards, unnest(string_to_array(cards.keywords, ',')::text[]) elem where elem <> all(SELECT unnest(sq.RemoveKeywords) from SelectQuery sq) and id in (61, 65) group by id order by id;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'elem' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "elem", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'elem' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "elem", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "selectquery" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_174", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT date_trunc('week', \"TIMESTAMP\") AS week, count(*), AVG(\"CL\") AS cl, AVG(\"C\") AS c FROM \"Experiment\" WHERE \"TIMESTAMP\" >= '2021-01-07T00:00:00.000Z' AND \"TIMESTAMP\" <= '2022-01-06T23:59:59.999Z' GROUP BY week ORDER BY week ASC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "experiment" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_175", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE FUNCTION calculate_loan_status()\n RETURNS SETOF loan_last\n AS $$\n DECLARE temp_table TABLE (loan_id int, status text);\n BEGIN INSERT INTO temp_table\n SELECT loan_id, status FROM loan_first WHERE status = 'A';\n INSERT INTO loan_last SELECT loan_id, status FROM temp_table;\n RETURN;\n END;\n $$ LANGUAGE plpgsql;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_176", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET total_powers = (SELECT COUNT(power_id) FROM hero_power);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'total_powers' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "total_powers" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "SELECT-FROM-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE" + ], + "tables": [ + "hero_power", + "superhero" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_177", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ID, Date, GOT, GPT FROM Laboratory GROUP BY ID HAVING COUNT(ID) > 1 ORDER BY Date DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_178", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select (coalesce(circui_name_A1, '') || ' ' || coalesce(circui_name_A2,'') || ' ' || coalesce(circui_name_A3, '')) as A, (coalesce(circui_name_B1, '') || ' ' || coalesce(circui_name_B2,'') || ' ' || coalesce(circui_name_B3, '')) as B from race_info;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "race_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_179", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH s as ( SELECT DATE(date_value) as dt, date_value, card_id cid, price FROM card_prices ) SELECT cid, dt, date_value, s.price as second_price FROM s INNER JOIN ( SELECT q.card_id, DATE(q.date_value) as dat FROM card_prices q GROUP BY q.card_id, dat ORDER BY q.card_id ASC ) as end_price ON s.cid = end_price.card_id AND s.date_value = (SELECT date_value FROM s WHERE s.cid = end_price.card_id AND s.dt = end_price.dat LIMIT 1) + interval '15 minutes' ORDER BY cid, dt;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'date_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date_value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date_value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "card_prices", + "s" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_180", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.bond_id as current_bond, b2.bond_id as next_bond, b.bond_type as bond_type FROM bond b INNER JOIN bond b2 ON b.molecule_id = b2.molecule_id WHERE b.bond_id < b2.bond_id ORDER BY b.bond_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_181", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT timestamp, avg(strength) FROM bond_strength WHERE timestamp >= ('2023-10-01 02:30:00'::timestamp - INTERVAL '1 hour') GROUP BY timestamp, strength", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "strength", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "strength", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond_strength" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_182", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select jsonb_set(t.data, '{purchaseurls}', (select jsonb_agg(case when v.value::text ~ 'tcgplayer' or v.value::text ~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_array_elements(t.data -> 'purchaseurls') v)) from cards_info", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_183", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH RNG AS(SELECT date_num, product_id, sales_value FROM sales_data WHERE (date_num = 123 OR date_num=567) ORDER BY date_num) SELECT date_num, product_id, sales_value, SUM(sales_value) AS trend FROM RNG group by date_num, product_id, sales_value", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "rng", + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_185", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT count(*) FROM (SELECT DISTINCT molecule_id FROM bond GROUP BY molecule_id HAVING COUNT(CASE WHEN bond_type = '-' THEN 1 END) = 0) AS molecule_without_bond_type;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1094, + "pattern_signature": "SELECT-DISTINCT-FROM-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_186", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "create or replace function setup_vector_store(table_name text) returns void language plpgsql as $$ begin execute 'drop function if exists match_strategies(int, jsonb)'; execute format('create table %I ( id bigint primary key generated always as identity, description text, metadata jsonb )', table_name); execute format('create function match_strategies ( match_count int default null, filter jsonb default \"{}\"::jsonb ) returns table ( id bigint, description text, metadata jsonb, similarity float )", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_187", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH variables_array AS (SELECT datapoint_id, ARRAY_AGG(variablevalue_id) AS varvalues FROM datapoint_variablevalue GROUP BY datapoint_id) SELECT COALESCE(SUM(dp.value),0), sd.name AS sp_name, v.varvalues AS varvalues, td.years AS years FROM variables_array v CROSS JOIN spatial_dimension sd CROSS JOIN time_dimension td LEFT JOIN datapoints dp ON dp.id = v.datapoint_id AND dp.spatial_dimension_id = sd.id AND dp.time_dimension_id = td.id GROUP BY years, sp_name, varvalues ORDER BY years DESC", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2094, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "datapoint_variablevalue", + "datapoints", + "spatial_dimension", + "time_dimension", + "variables_array" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_188", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(*) AS exact_count FROM match;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_190", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT player_api_id, player_name FROM player WHERE player_name LIKE 'Ale%' AND player_fifa_api_id > 220000 AND id = (SELECT MAX(id) FROM player);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.124, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "player" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_191", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT match_id, match_date FROM detail WHERE match_details @@ '$.player_stats[*] ? (@.player_id == :player_id).goals > 0';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "detail" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_192", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.bond_id, jsonb_build_object('time', sum((b.bond_stat_->'time')::numeric)) FROM bond b GROUP BY bond_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_194", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "CREATE UNIQUE INDEX conditional_unique_index ON match_results (match_id, team_id) WHERE (SELECT COUNT(*) FROM match_results t2 WHERE t2.match_id = match_results.match_id AND t2.team_id = match_results.team_id) = 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "match_results" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_195", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CAST(time_bucket AS DATE) AS time_bucket, rate / DATE_PART('days', time_bucket + INTERVAL '1 month - 1 day') AS daily_rate FROM (SELECT DATE(generate_series(LOWER(time_span)::TIMESTAMP, COALESCE(UPPER(time_span),NOW())::TIMESTAMP, '1 day')) AS time_bucket, rate FROM budgets) AS daily_rates;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'rate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "rate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'rate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "rate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'time_span' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "time_span", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'time_span' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "time_span", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budgets" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_196", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT attribute_name, to_number(attribute_name) FROM attribute;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "attribute" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_197", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT molecule_id, COUNT(*) FILTER (WHERE COUNT(*) > 5) AS total_bonds FROM bond GROUP BY molecule_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-FILTER", + "clauses_present": [ + "FILTER", + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_198", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH range_values AS ( SELECT date_trunc('week', min(date)) as minval, date_trunc('week', max(date)) as maxval FROM laboratory ), week_range AS ( SELECT generate_series('1991-01-01', now(), '1 week') as week FROM range_values ), grouped_labs AS ( SELECT date_trunc('week', date) as week, count(id) as total_tests FROM laboratory WHERE date >= '1991-01-01' GROUP BY 1 ) SELECT week_range.week, COALESCE(sum(total_tests)::integer, 0) AS total_labs FROM week_range LEFT OUTER JOIN grouped_labs on week_r", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "grouped_labs", + "laboratory", + "range_values", + "week_range" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_199", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "DROP FUNCTION IF EXISTS update_school_inventory_after_supply() CASCADE;CREATE OR REPLACE FUNCTION update_school_inventory_after_supply() RETURNS TRIGGER LANGUAGE plpgsql AS $trigger$ BEGIN UPDATE school_inventory AS i SET NEW.quantity = school_supplies.quantity + OLD.quantity FROM school_supplies WHERE i.cdscode = school_supplies.cdscode; RETURN NEW; END; $trigger$;DROP TRIGGER IF EXISTS trigger_insert_supply ON school_supplies;CREATE TRIGGER trigger_insert_supply AFTER INSERT ON school_supplies", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'update_school_inventory_after_supply' does not exist in schema", + "taxonomy_category": "semantic", + "context": "update_school_inventory_after_supply", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "update_school_inventory_after_supply" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_200", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT county, AVG(avgscrread + avgscrmath + avgscrwrite) / 3 AS avg_total_sat FROM satscores GROUP BY county ORDER BY avg_total_sat DESC LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_201", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH vars AS ((select count(*) from laboratory) AS vars_id) select * from laboratory where id=vars.vars_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_202", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM match_location WHERE ST_INTERSECTS(location, CIRCLE(POINT(-73.935242, 40.730610), 2));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'location' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "location", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match_location" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_203", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "INSERT INTO learners\n (\"Age\", \"Gender\", \"Geographic_Location\", \"Socioeconomic_Background\",\n \"Education_Level\", \"Previous_Academic_Performance\", \"Language_Proficiency\",\n \"Preferred_Learning_Medium\", \"Learning_Pace\", \"Engagement_History\")\nVALUES\n (18,\n 'Male',\n 'Urban',\n 'Low',\n 'UndergraduateUndergraduateUndergraduate',\n 88.55,\n 'Intermediate',\n 'Video',\n 'Moderate',\n 6);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_204", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n x.curriculum_id,\n ARRAY_LENGTH(x.combined_array, 1) AS distinct_count\nFROM\n(\n\nSELECT\n c.curriculum_id,\n ARRAY[e.\"Content_Type\", e.\"Platform_Used\"] AS combined_array\n FROM curriculum_resources cr\n JOIN educational_resources e\n ON cr.resource_key = e.resource_key\n JOIN curricula c\n ON c.curriculum_id = cr.curriculum_id\n\n UNION\nSELECT\n c2.curriculum_id,\n ARRAY[cr2.recommended] AS combined_array\n FROM curriculum_resources cr2\n JOI", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1885, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-UNION-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "curricula", + "curriculum_resources", + "educational_resources" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_205", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE curricula\n ADD COLUMN status TEXT DEFAULT 'installed';\n\n\nWITH RECURSIVE curricula_to_upgrade AS (\n\nSELECT c.curriculum_id\n FROM curricula c\n WHERE c.status = 'installed'\n AND c.curriculum_id = 1\n\nUNION ALL\n\n\nSELECT c2.curriculum_id\n FROM curricula c2\n JOIN curricula_to_upgrade ctu\n ON c2.curriculum_id = ctu.curriculum_id\n)\nUPDATE curricula\nSET status = 'to upgrade'\nWHERE curriculum_id IN (\n SELECT curriculum_id\n FROM curricula_to_upgrade\n);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "curricula" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_206", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT learner_code, resource_key, SUM(duration) AS total_time_spent\nFROM event_usage\nWHERE start_timestamp BETWEEN '2024-10-01' AND '2024-10-09'\nGROUP BY learner_code, resource_key;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "event_usage" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_207", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n first_value(rating) OVER (\n PARTITION BY learner_code, resource_key\n ORDER BY usage_date\n ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW\n ) AS filled_rating,\n learner_code,\n resource_key\nFROM\n resource_usage_2\nORDER BY\n learner_code, usage_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "resource_usage_2" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_208", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT dd::date AS day_start, SUM(CASE WHEN T.incident_start <= dd AND T.incident_end >= dd THEN 1440 ELSE 0 END) AS incident_minutes FROM generate_series('2022-01-01'::timestamp, '2022-01-31'::timestamp, '1 day'::interval) dd LEFT JOIN race_incidents T ON dd::date BETWEEN T.incident_start AND T.incident_end GROUP BY dd::date ORDER BY dd::date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "race_incidents" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_209", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM CROSSTAB ('SELECT p.id, l.ldh, l.ldh, l.ldh FROM patient p JOIN laboratory l ON p.id = l.id ORDER BY 1,2;') AS (id INT, ldh_1 INT, ldh_2 INT, ldh_3 INT);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_210", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT tempId, pemId, time, rank, (CASE pointsno WHEN 1 THEN points ELSE points END ) AS points FROM (SELECT ROW_NUMBER() OVER(PARTITION BY points) AS pointsno, tempId, pemId, time, rank, points FROM (SELECT driverid AS tempId, driverid AS pemId, time, rank, points FROM results GROUP BY GROUPING SETS ((tempId, points), (tempId, pemId, time, rank))) AS b) AS s ORDER BY tempId, points ASC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "SELECT-DISTINCT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "results" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_211", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "select * from results r inner join drivers d on r.driverid = d.driverid where r.grid = 21 order by r.points desc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "drivers", + "results" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_212", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO customer_orders(name, title) SELECT COALESCE(uo.name, co.name), COALESCE(uo.title, co.title) FROM customer_orders co LEFT OUTER JOIN updated_orders uo ON uo.id = co.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-INSERT", + "clauses_present": [ + "FROM", + "INSERT", + "JOIN", + "SELECT" + ], + "tables": [ + "customer_orders", + "updated_orders" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_213", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result FOR attribute_name IN (Strength, Speed, Intelligence))", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expecting an aggregation function in PIVOT. Line 1, Col: 103.\n SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(\u001b[4mresult\u001b[0m FOR attribute_name IN (Strength, Speed, Intelligence))\n\nRequired keyword: 'this' missing for . Line 1, Col: 107.\n CT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result \u001b[4mFOR\u001b[0m attribute_name IN (Strength, Speed, Intelligence))", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero_performance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_214", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) FROM laboratory WHERE date_part('year', date) = date_part('year', CURRENT_DATE) AND date_part('month', date) = date_part('month', CURRENT_DATE) AND date [I don't know what to put here];", + "valid": false, + "errors": [ + { + "tag": "syntax_unterminated_string", + "message": "Unterminated quoted string", + "taxonomy_category": "syntax", + "context": "Error tokenizing 'NT_DATE) AND date [I don't know what to put here]'" + } + ], + "tags": [ + "syntax_unterminated_string" + ] + }, + { + "instance_id": "PostgreSQL_215", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH reporting_dates AS (SELECT generate_series('2000-01-01'::date, '2017-01-01'::date, '1 year'::interval) AS reporting_date) SELECT reporting_date, COUNT(CASE WHEN OpenDate > reporting_date AND (ClosedDate IS NULL OR ClosedDate <=reporting_date) THEN cdscode END) AS active_schools FROM reporting_dates LEFT JOIN schools ON true GROUP BY reporting_date ORDER BY reporting_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "reporting_dates", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_216", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT budget_id, category, amount, SUM(amount) OVER (PARTITION BY category ORDER BY amount) AS cum_amount FROM budget ORDER BY category DESC, amount;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_217", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT district_id FROM client WHERE district_id = 1 LIMIT 100;SELECT district_id FROM client WHERE district_id <> 1 LIMIT 900;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "WHERE" + ], + "tables": [ + "client" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_218", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET type = ( SELECT type, client_id FROM disp WHERE card.disp_id = disp.disp_id );", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'type' is ambiguous \u2014 exists in tables: card, disp", + "taxonomy_category": "semantic", + "context": "type" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'type' is ambiguous \u2014 exists in tables: card, disp", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "card", + "disp" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_219", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE card (card_id SERIAL PRIMARY KEY,loan_id INT UNIQUE,type TEXT NOT NULL,issued DATE NOT NULL,CONSTRAINT fk_loan_id FOREIGN KEY (loan_id) REFERENCES loan(loan_id) ON DELETE SET NULL);ALTER TABLE loan ADD CONSTRAINT fk_card_loan FOREIGN KEY (loan_id) REFERENCES card(loan_id) ON DELETE CASCADE;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card", + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_220", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$ DECLARE value RECORD[]; BEGIN SELECT t FROM transactions_1k t LIMIT 1 INTO value[1]; SELECT c FROM customers c LIMIT 1 INTO value[2]; RAISE NOTICE 'Transaction: %', value[1]; RAISE NOTICE 'Customer: %', value[2]; END $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_221", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE loan l SET status = 'updated_status', date = 'new_date', amount = 'new_amount' WHERE l.loan_id = 'loan_id_value' AND l.status = 'current_status';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_222", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS patients, (SELECT * FROM doctors) AS doctors, (SELECT * FROM appointments) AS appointments;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expected type. Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nRequired keyword: 'to' missing for . Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nExpected type. Line 1, Col: 84.\n SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::\u001b[4m)\u001b[0m as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS p\n\n... and 3 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.2292, + "pattern_signature": "SELECT-FROM-JOIN-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "appointments", + "doctors", + "patients" + ], + "num_joins": 2, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_223", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE patients_info\nSET general_info = jsonb_set(general_info, '{accept_appointments}', '\"false\"');", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'general_info' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "general_info" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'general_info' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "general_info" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "patients_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_224", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.molecule_id, b.date AS buy_date, s.date AS sell_date, s.molecules, b.usd_total AS buy_usd_total, s.usd_total AS sell_usd_total FROM transaction b JOIN transaction s ON b.molecule_id = s.molecule_id WHERE b.sell = 0 AND s.sell = 1 ORDER BY b.date, s.date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transaction" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_225", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE weekdays AS ( SELECT generate_series(0, 60) AS offset ), dates AS ( SELECT CURRENT_DATE + (w.offset || ' days')::interval AS date, EXTRACT(ISODOW FROM CURRENT_DATE + (w.offset || ' days')::interval) AS day_of_week FROM weekdays w WHERE EXTRACT(ISODOW FROM CURRENT_DATE + (w.offset || ' days')::interval) IN (1, 2, 3, 4, 5, 6, 7) ), schedule_blocks_with_dates AS ( SELECT sb.*, d.date AS block_date FROM schedule_blocks sb JOIN dates d ON sb.day_of_week ILIKE to_char(d.date, 'Day') WHE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "dates", + "schedule_blocks", + "schedule_blocks_with_dates", + "weekdays" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_226", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, (select sum(buildupplayspeed) over (ROWS UNBOUNDED PRECEDING) as a), sum(buildupplayspeed) over (ROWS UNBOUNDED PRECEDING) as b from team_attributes limit 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-WINDOW-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_227", + "db_id": "erolp", + "category": "Management", + "sql_index": 0, + "sql": "CREATE VIEW overview AS SELECT count(*) AS learners_count FROM learners, SELECT count(*) AS institutions_count FROM institutions, SELECT count(*) AS curricula_count FROM curricula", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1125, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "curricula", + "institutions", + "learners", + "overview" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_228", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT patients.patient_id, demographics.height, treatment_and_followup.primary_pathology_karnofsky_performance_score, MIN(primary_pathology_karnofsky_performance_score) AS min_performance_score FROM patients JOIN treatment_and_followup ON patients.patient_id = treatment_and_followup.patient_id JOIN demographics ON patients.patient_id = demographics.patient_id WHERE informed_consent_verified = TRUE GROUP BY patients.patient_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "demographics", + "patients", + "treatment_and_followup" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_229", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE A(GroupNum, n, RollingSum, id) AS (\n SELECT 1, Performance_Prediction, Performance_Prediction, prediction_code\n FROM performance_predictions\n ORDER BY prediction_code ASC\n LIMIT 1\n UNION ALL\n SELECT\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN GroupNum + 1\n ELSE GroupNum\n END,\n P.Performance_Prediction,\n CASE\n WHEN RollingSum + P.Performance_Prediction > 200\n THEN ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.099, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WINDOW-UNION-ORDER-LIMIT", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "a", + "performance_predictions" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_230", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT A.client_id AS child FROM client A, client B\nWHERE A.birth_date + INTERVAL '16 years' < B.birth_date;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "client" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_231", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT g.GasStationID FROM transactions_1k t JOIN gasstations g\nON t.GasStationID = g.GasStationID GROUP BY g.GasStationID\nHAVING SUM(t.Amount * t.Price) / SUM(t.Amount * t.Price) OVER (PARTITION BY t.CustomerID) >= 0.7", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0667, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-WINDOW", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "WINDOW" + ], + "tables": [ + "gasstations", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_232", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE WHEN c.type = 'gold' THEN 'Gold' ELSE 'Non-Gold'\nEND AS card_type_group, COUNT(l.loan_id) AS loan_count\nFROM loan l\nJOIN disp d ON l.account_id = d.account_id\nJOIN card c ON d.disp_id = c.disp_id\nGROUP BY c.type", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "card", + "disp", + "loan" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_233", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT link_to_member, link_to_event, count(1) AS total FROM attendance\nGROUP BY GROUPING SETS ((link_to_member), (link_to_member, link_to_event))\nORDER BY max(count(1)) over (partition by link_to_member) desc, max(count(1))\nover (partition by link_to_member,link_to_event) desc, count(1) desc;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0479, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_234", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (CustomerID) * FROM transactions_1k ORDER BY Date DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_235", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "MERGE INTO treatment_and_followup_backup b USING treatment_and_followup_latest a ON b.patient_id = a.patient_id WHEN MATCHED THEN UPDATE SET followup_no = a.followup_no, primary_pathology_karnofsky_performance_score = a.primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cancer_oncology_group = a.primary_pathology_eastern_cancer_oncology_group WHEN NOT MATCHED THEN INSERT (patient_id, followup_no, primary_pathology_karnofsky_performance_score, primary_pathology_eastern_cance", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "INSERT-UPDATE-MERGE", + "clauses_present": [ + "INSERT", + "MERGE", + "UPDATE" + ], + "tables": [ + "treatment_and_followup_backup", + "treatment_and_followup_latest" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_236", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, engagement_history FROM learners_array;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'engagement_history' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "engagement_history", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "learners_array" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_237", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT Engagement_Level, MAX(rating), MIN(rating) FROM resource_usage JOIN target_labels ON resource_usage.learner_code = target_labels.learner_code GROUP BY Engagement_Level;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0594, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "resource_usage", + "target_labels" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_238", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, rating, usage_date FROM resource_usage WHERE (learner_code, usage_date) = (SELECT learner_code, MAX(usage_date) FROM resource_usage GROUP BY learner_code) ORDER BY learner_code, usage_date DESC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "resource_usage" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_239", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, CASE WHEN Geographic_Location = 'Urban' THEN 1 WHEN Geographic_Location = 'Rural' THEN 2 ELSE 0 END AS location_id, AVG(Pre_Test_Score) AS average_pre_test_score FROM learners WHERE Engagement_History > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 318.\n tory > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN $\u001b[4m{\u001b[0msocio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' \n\nRequired keyword: 'this' missing for . Line 1, Col: 395.\n diate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN $\u001b[4m{\u001b[0msocio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Pre_Test_Score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Pre_Test_Score", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_keyword_misuse", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0552, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_240", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH src(id,geom) as (values (1, 'linestring(0 0, 0 10)'::geometry), (2, 'linestring(0 10, 0 11)'::geometry), (3, 'linestring(1 1, 0 5)'::geometry), (4, 'linestring(1 1, 2 2)'::geometry)) SELECT a.id, st_asText(st_intersection(a.geom, b.geom)) FROM src AS a WHERE NOT EXISTS (SELECT 1 FROM src as b WHERE a.id != b.id AND ST_Toches(a.geom, b.geom) AND ST_Equals(ST_EndPoint(b.geom), ST_Intersection(a.geom, b.geom)));", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0917, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "VALUES", + "WHERE", + "WITH" + ], + "tables": [ + "src" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_241", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "select device_info::json ->> 'SerialNumber' as SerialNumber, cto ->> 'ChannelId'::INT AS channelid, cto ->> 'ChannelName' AS ChannelName from device_details CROSS JOIN LATERAL json_array_elements(device_info::json ->'ChannelListDto') Channels(cto);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "device_details" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_242", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "WITH test AS ( SELECT EXTRACT(DAY FROM diff) || ' days ' || EXTRACT(HOUR FROM diff) || ' hours ' || EXTRACT(MINUTE FROM diff) || ' minutes ' || EXTRACT(SECOND FROM diff) || ' seconds ' AS time_diff FROM ( SELECT TIMESTAMP '2023-01-10 15:12:24' - TIMESTAMP '2023-01-01 10:34:36' AS diff ) AS diff_query JOIN ( SELECT generate_series( timestamp '2023-01-01', timestamp '2023-01-10', interval '1 day' ) AS the_day ) AS dates ON dates.the_day BETWEEN TIMESTAMP '2023-01-01 10:34:36' AND TIMESTAMP '2023-0", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2021, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "test" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_243", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH links AS (SELECT greatest(link.source_cluster, link.target_cluster) AS big, least(link.source_cluster, link.target_cluster) AS smol, link.type AS type FROM link AS link) SELECT l.cluster AS left_id, l.cluster_type AS left_type, l.cluster_label AS left_label, r.cluster AS right_id, r.cluster_type AS right_type, r.cluster_label AS right_label, count(distinct(l.article)) AS articles, array_agg(distinct(links.type)) AS link_types FROM tag AS r, tag AS l JOIN links ON l.cluster = links.big WHERE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "link", + "links", + "tag" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_244", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT i.country, o.name, o.city, o.established FROM public.ismember i INNER JOIN\npublic.organization o ON o.abbreviation = i.organization WHERE i.type = 'member'\nAND i.country = 'CI' ORDER BY o.established DESC LIMIT 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "ismember", + "organization" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_245", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS (select inst.\"Institution_Type\", outcm.\"Pre_Test_Score\", dense_rank()\nover (partition by \"Institution_Type\" order by \"Pre_Test_Score\" desc) as score_rank from outcomes as outcm\njoin enrollment as enrl on outcm.learner_code = enrl.learner_code join institutions as inst\non enrl.institution_key = inst.institution_key where inst.\"Institution_Type\" = 'Public' or\ninst.\"Institution_Type\" = 'Private') select (case when \"Institution_Type\" = 'Public' AND score_rank = 1\nTHEN \"Pre_Test_Score\" EN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1844, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "enrollment", + "institutions", + "outcomes" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_246", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT regexp_replace(\"Content_Type\", '^(.)|\\1', '', 'ig') FROM educational_resources", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "educational_resources" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_247", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "select regexp_replace((select regexp_replace(primary_pathology_histological_type, 'NOS$',\n'Not Otherwise Specified') from pathology_and_surgery), 'Adenocarcinoma', 'Adenoma Carcinoma')\nas transformed_histological_type from pathology_and_surgery;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "pathology_and_surgery" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_248", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "(SELECT COUNT(*) FROM sp_artists WHERE pop > 50) / (SELECT COUNT(*) FROM sp_artists);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_artists" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_249", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CASE WHEN COALESCE(primary_pathology_initial_pathologic_diagnosis_method,\nprimary_pathology_init_pathology_dx_method_other) LIKE 'Other method, specify:'\nTHEN NULL ELSE primary_pathology_neoplasm_histologic_grade END AS histologic_grade,\nCASE WHEN COALESCE(primary_pathology_initial_pathologic_diagnosis_method,\nprimary_pathology_init_pathology_dx_method_other) LIKE 'Other method, \nspecify:' THEN NULL ELSE primary_pathology_days_to_initial_pathologic_diagnosis END AS\ndays_to_initial_diagnos", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "pathology_and_surgery" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_250", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM sp_album_ctb WHERE (alb, art, feat_arts, start_date) IN (SELECT alb, art, feat_arts, end_date + INTERVAL '1 day' FROM sp_album_ctb);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_album_ctb" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_251", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT patients.patient_id, patients.patient_barcode, patient_addresses.address_id, patient_addresses.city_of_procurement FROM patients, patient_addresses WHERE patients.patient_id = 1 AND patient_addresses.patient_id = patients.patient_id ORDER BY patient_addresses.address_id DESC LIMIT 1;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "patient_addresses", + "patients" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_252", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT l.learner_code, l.gender, r.resource_key, 'Regular Feedback' as FeedbackType, r.feedback as UserFeedback FROM learners l INNER JOIN resource_usage r ON l.learner_code = r.learner_code WHERE UserFeedback = ANY(ARRAY['Negative']) UNION ALL SELECT l.learner_code, l.gender, 0 as resource_key, 'Synthetic Feedback' as FeedbackType, CASE WHEN o.learner_satisfaction_score < 3 THEN 'Negative' ELSE 'Positive' END as UserFeedback FROM learners l INNER JOIN outcomes o ON l.learner_code = o.learner_co", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "learners", + "outcomes", + "resource_usage" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_253", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM city ORDER BY COALESCE(SUBSTRING(name FROM '[A-Z]+'), ''), COALESCE(SUBSTRING(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 190.\n NG(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\u001b[4m\uff1b\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "city" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_254", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.name, c.code, array_agg(cn.othername) AS alternative_names FROM country c LEFT JOIN countryothername cn ON c.code = cn.country GROUP BY c.name, c.code ORDER BY c.name ASC;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "country", + "countryothername" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_255", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ST_Touches(ol.geom, l.geom)\nFROM institution_location ol, learner_institution_location l\nWHERE ST_Touches(ol.geom, l.geom)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "institution_location", + "learner_institution_location" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_256", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM\n (SELECT tissue_source_site, COUNT (*) AS total\n FROM (SELECT * FROM patients) AS _\n GROUP BY tissue_source_site) result_total\n INNER JOIN\n (SELECT tissue_source_site, COUNT (*) AS processed\n FROM (SELECT * FROM patients WHERE informed_consent_verified=true) AS _\n GROUP BY tissue_source_site) result_processed\n ON result_total.tissue_source_site = result_processed.tissue_source_site;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2813, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patients" + ], + "num_joins": 1, + "num_subqueries": 4, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_257", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH sales AS ( SELECT \"gasstationid\" AS \"GasstationId\", \"customerid\" AS \"CustomerId\", \"date\" AS \"SaleDate\", \"amount\" AS \"Amount\" FROM \"transactions_1k\" ), initial_purchase AS ( SELECT \"GasstationId\", \"CustomerId\", MIN(CAST(\"SaleDate\" AS date)) AS \"FirstPurchaseDate\" FROM sales GROUP BY \"GasstationId\", \"CustomerId\" ), customer_wages AS ( SELECT i.\"CustomerId\", s.* FROM sales s JOIN initial_purchase i ON s.\"CustomerId\" = i.\"CustomerId\" WHERE s.\"SaleDate\" >= i.\"FirstPurchaseDate\" ORDER BY i.\"Custo", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1271, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "customer_wages", + "initial_purchase", + "sales", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_258", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE (SELECT quote_ident(c.table_schema) || '.' || quote_ident(c.table_name) || ' RENAME \"' || c.column_name || '\" TO ' || quote_ident(lower(c.column_name)) || ';' As ddlsql FROM information_schema.columns As c WHERE c.table_schema NOT IN('information_schema', 'pg_catalog') AND c.column_name <> lower(c.column_name) ORDER BY c.table_schema, c.table_name, c.column_name);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_259", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT product_id FROM product WHERE product_id IN (101, 103) AND is_searchable = true", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "product" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_260", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM orders WHERE customer_id = 1 OR product_id = 'P202'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'customer_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "customer_id", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'product_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "product_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_261", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT transaction_date, salesperson_name FROM sales_log WHERE salesperson_name NOT IN (SELECT salesperson_name FROM sales_log GROUP BY transaction_date, salesperson_name)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sales_log" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_262", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT p.product_id, p.product_name FROM Product p JOIN ProductPrice pp ON p.product_id = pp.product_id WHERE pp.price < ( SELECT MAX(price) FROM ProductPrice WHERE product_id = p.product_id ) ORDER BY p.product_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1469, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "product", + "productprice" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_263", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CD.customer_id, COUNT(S.customer_id) AS total_sales, SUM(S.amount) AS total_amount, COUNT(C.customer_id) AS total_communications, COUNT(F.customer_id) AS total_feedback, COUNT(F.customer_id) FILTER (WHERE F.feedback_type='positive') AS total_positive_feedback, COUNT(F.customer_id) FILTER (WHERE F.feedback_type='negative') AS total_negative_feedback FROM customer_details CD JOIN sales S ON CD.customer_id = S.customer_id JOIN communications C ON CD.customer_id = C.customer_id JOIN feedback ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-FILTER", + "clauses_present": [ + "FILTER", + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "communications", + "customer_details", + "feedback", + "sales" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_265", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM orders WHERE '10015' = ANY(string_to_array(orders.delivery_zones, ','))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_266", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH t1 AS ( SELECT e.event_id FROM event e LEFT JOIN attendance a ON e.event_id = a.link_to_event ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event)", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Failed to parse any statement following CTE. Line 1, Col: 197.\n nt ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event\u001b[4m)\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_267", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.* FROM transactions_1k LEFT JOIN customers ON transactions_1k.customerid = customers.customerid LIMIT 5", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_268", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT bond_id FROM bond WHERE bond_id LIKE 'TR1%5' OR bond_id LIKE 'TR2%4'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_269", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(cost) AS total_cost, link_to_member FROM expense GROUP BY link_to_budget", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "expense" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_270", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT t.trans_id, a.district_id, t.amount FROM trans AS t JOIN account AS a ON t.account_id = a.account_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "account", + "trans" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_271", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT schools.cdscode, frpm.cdscode FROM schools LEFT JOIN frpm ON schools.cdscode = frpm.cdscode", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "frpm", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_272", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELEC Player.player_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_attributes ON Player.player_api_id = Player_Attributes.player_api_id WHERE Player_Attributes.overall_rating = 68", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 13.\n SELEC Player\u001b[4m.\u001b[0mplayer_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_att", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_273", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM attribute JOIN hero_attribute ON hero_attribute.attribute_id = attribute.id WHERE (attribute_name <> 'Speed' AND attribute_value <> 35)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0646, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attribute", + "hero_attribute" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_274", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cdscode, COUNT(cdscode) FROM schools WHERE district = 'Alameda County Office of Education' LIMIT 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_275", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.driverstandingsid, s.raceid, d.driverid FROM driverstandings AS s LEFT JOIN drivers AS d ON d.driverid = s.driverid AND s.raceid = 19", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0573, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "drivers", + "driverstandings" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_276", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT status, SUM(amount) AS total_amount, SUM(payments) AS total_payments, (total_amount + total_payments) AS s FROM loan GROUP BY status", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "loan" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_277", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(diagnosis), diagnosis FROM patient WHERE diagnosis = 'PSS' GROUP BY diagnosis HAVING COUNT(*) > 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0375, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_278", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, b.name AS BadgeName, b.date AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000 AND b.name = 'Teacher' UNION ALL SELECT DISTINCT u.id AS UserId, u.displayname, u.reputation, NULL AS BadgeName, NULL AS BadgeDate FROM users AS u LEFT JOIN badges AS b ON b.userid = u.id WHERE u.reputation >= 10000", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "DISTINCT", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "badges", + "users" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_279", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(expense.cost) AS total_expense, SUM(budget.amount) AS total_budget, budget.link_to_event FROM budget, expense WHERE budget.budget_id = expense.link_to_budget GROUP BY budget.link_to_event", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "budget", + "expense" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_280", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, LENGTH(superhero_name) FROM superhero WHERE LENGTH(superhero_name) = (SELECT MIN(LENGTH(superhero_name)) FROM superhero) OR LENGTH(superhero_name) = (SELECT MAX(LENGTH(superhero_name)) FROM superhero) ORDER BY LENGTH(superhero_name) ASC NULLS FIRST, superhero_name ASC NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1531, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_281", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT customerid, *, MAX(date) AS maxdate FROM transactions_1k", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-DISTINCT-FROM", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_282", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and power = '2') THEN coalesce(watermark, '998') watermark WHEN (colors = 'R' and power = '0') THEN coalesce(watermark, '999') watermark END) watermark FROM cards", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expected END after CASE. Line 1, Col: 84.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996'\u001b[4m)\u001b[0m watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (color\n\nExpecting ). Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow\n\nInvalid expression / Unexpected token. Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_283", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT posts.owneruserid, posts.tags, AVG(posts.score) AS AvgOfScore FROM posts WHERE posts.owneruserid = 183 AND posts.tags LIKE '%distribution%' AND EXISTS(SELECT creaiondate FROM posts AS pdates WHERE pdates.owneruserid = posts.owneruserid AND pdates.tags = posts.tags AND pdates.creaiondate = posts.creaiondate ORDER BY pdates.creaiondate DESC NULLS LAST LIMIT 5)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "posts" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_284", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT link_to_member, COUNT(DISTINCT DATE(event_date)) AS total_attendance_days FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] WITH cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link_to_member ORDER BY DATE(event_date)) AS rn FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AN", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 244.\n ent.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] \u001b[4mWITH\u001b[0m cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_285", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT member_id, first_name, last_name FROM member) AS A LEFT JOIN (SELECT link_to_member FROM attendance WHERE link_to_event = 'recEVTik3MlqbvLFi') AS B ON A.member_id = B.link_to_member", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "attendance", + "member" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_286", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT t.customerid, p.description, MAX(t.date) FROM transactions_1k AS t INNER JOIN products AS p ON t.productid = p.productid GROUP BY t.customerid", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "products", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_287", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.CustomerID AS Customer1, t2.CustomerID AS Customer2, COUNT(*) AS Count FROM (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t1, (SELECT CustomerID, CONCAT(Date, GasStationID) AS ConcatenatedValue, COUNT(*) FROM transactions_1k) AS t2 WHERE t1.ConcatenatedValue = t2.ConcatenatedValue GROUP BY Customer1, Customer2 ORDER BY Count DESC NULLS LAST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.175, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_288", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DAILY_REVENUE AS (SELECT date, SUM(amount) AS TotalAmount FROM transactions_1k GROUP BY date ORDER BY date ASC NULLS FIRST), MOVING_AVG AS (SELECT date, SUM(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS TotalAmount, CAST(AVG(TotalAmount) OVER (ORDER BY date ASC NULLS FIRST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS DECIMAL(10, 2)) AS AverageAmount FROM daily_revenue) SELECT * FROM moving_avg", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "daily_revenue", + "moving_avg", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_289", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.department, COUNT(e.expense_id) AS cnt, e.cost AS highest_cost FROM expense AS e INNER JOIN member AS mem ON e.link_to_member = mem.member_id INNER JOIN major AS m ON mem.link_to_major = m.major_id GROUP BY m.department ORDER BY cnt DESC NULLS LAST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "expense", + "major", + "member" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_290", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT country, segment, COUNT(*) AS count_segment, DENSE_RANK() OVER (PARTITION BY country ORDER BY (SELECT COUNT(*) AS count_segment FROM gasstations) NULLS FIRST) AS \"rnk\" FROM gasstations GROUP BY country, segment) AS segment_rank WHERE rnk = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1948, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "gasstations" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_291", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND ex.\"aCL IgG\" > 3.0)", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 59.\n SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM \u001b[4mpatient\u001b[0m pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND e", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_292", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(b.bond_id) AS total, b1.bond AS bond, b2.bond_type_dash AS bond_type_dash, b3.bond_type_equal AS bond_type_equal, b4.bond_type_hash AS bond_type_hash FROM bond AS b LEFT JOIN (SELECT bond_id, COUNT(*) AS bond FROM bond WHERE bond_id = 'TR000_1_2') AS b1 ON b1.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_dash FROM bond WHERE bond_type = '-') AS b2 ON b2.bond_id = b.bond_id LEFT JOIN (SELECT bond_id, COUNT(*) AS bond_type_equal FROM bond WHERE bond_type = '=') ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "bond" + ], + "num_joins": 4, + "num_subqueries": 4, + "num_ctes": 0, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_293", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id GROUP BY l.country_id HAVING l.country_id > 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 101.\n UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id \u001b[4mGROUP BY\u001b[0m l.country_id HAVING l.country_id > 1000;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + } + ], + "tags": [ + "syntax_invalid_token", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "FROM-WHERE-UPDATE", + "clauses_present": [ + "FROM", + "UPDATE", + "WHERE" + ], + "tables": [ + "country", + "league" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_294", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.*, rank := rank + 1 AS ranking FROM (SELECT 0 AS rank) AS init, results AS r JOIN drivers AS d ON r.driverid = d.driverid ORDER BY r.fastestlap ASC NULLS FIRST, d.dob ASC NULLS FIRST LIMIT 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1521, + "pattern_signature": "SELECT-FROM-JOIN-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "drivers", + "results" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_295", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM transactions_1k WHERE CONCAT(date, ' ', time) BETWEEN CAST('2012-08-22' AS DATE) AND CAST('2012-08-23' AS DATE) ORDER BY amount DESC NULLS LAST LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_296", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT state, MAX(county) AS County, MAX(city) AS City, MAX(cdscode) AS CDSCode FROM schools WHERE NOT state IS NULL GROUP BY state", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_297", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT account.account_id, loan.loan_id, SUM(loan.amount) AS total_amount FROM account JOIN loan ON account.account_id = loan.account_id JOIN trans ON loan.account_id = trans.account_id WHERE loan.status LIKE '%A%' AND trans.type LIKE '%PRIJEM%' AND trans.type LIKE '%VYDAJ%' GROUP BY loan.loan_id ORDER BY account.account_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1177, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "account", + "loan", + "trans" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_298", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT date, COUNT(*) FROM transactions_1k WHERE EXTRACT(DAY FROM date) IN (3, 24)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_299", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SELECT 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district WHERE A8 = 4 [split] SELECT 4 AS RATES, COUNT(A9) FROM district WHERE A9 = 4 [split] SELECT 3 AS RATES, COUNT(A8) FROM district WHERE A8 = 3 [split] SELECT 3 AS RATES, COUNT(A9) FROM district WHERE A9 = 3", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 70.\n SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] \u001b[4mSELECT\u001b[0m 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "district" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_300", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.id, s.code, s.parentcode AS ancestralCode FROM sets AS s WHERE NOT s.parentcode IS NULL", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "sets" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_301", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT event.event_id AS event_id, event.event_name AS event_name, MAX(attendance.link_to_member) AS largest_member, expense.cost FROM event LEFT JOIN attendance ON event.event_id = attendance.link_to_event LEFT JOIN expense ON attendance.link_to_member = expense.link_to_member WHERE event.event_id = 'rec2N69DMcrqN9PJC' GROUP BY event.event_id, expense.cost", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event", + "expense" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_302", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH Partitioned AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY CustomerID, Date ORDER BY CustomerID NULLS FIRST, Date NULLS FIRST) AS RowNumber FROM transactions_1k) SELECT *, CASE WHEN RowNumber > 1 THEN 0 ELSE COALESCE(CAST(AGE(CAST((SELECT MAX(Date) FROM transactions_1k WHERE Date < a.Date AND CustomerID = a.CustomerID) AS TIMESTAMP), CAST(a.Date AS TIMESTAMP)) AS BIGINT), 0) END AS Days_between FROM partitioned AS a", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.124, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "partitioned", + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_303", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT hp1.hero_id AS id1, hp2.hero_id AS id2 FROM hero_power AS hp1 INNER JOIN hero_power AS hp2 ON hp1.hero_id < hp2.hero_id WHERE hp1.power_id IN (SELECT DISTINCT hp2.power_id) GROUP BY id1, id2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "hero_power" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_304", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT transactions_1k.transactionid, transactions_1k.date, transactions_1k.customerid, STRING_AGG(gasstations.gasstationid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS gasstation_ids, STRING_AGG(products.productid::text, '|' ORDER BY transactions_1k.transactionid NULLS FIRST) AS product_ids FROM transactions_1k LEFT JOIN gasstations ON transactions_1k.gasstationid = gasstations.gasstationid LEFT JOIN products ON transactions_1k.productid = products.productid WHERE NOT trans", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_305", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM budget GROUP BY link_to_event WHEN event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN 'Open' WHEN event_status = 'Open' THEN 'Open' WHEN event_status = 'Planning' THEN 'Planning' ELSE 'Unknown' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n SELECT * FROM budget GROUP BY link_to_event \u001b[4mWHEN\u001b[0m event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_306", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.customerid, SUM(t.amount) FROM customers AS c INNER JOIN transactions_1k AS t ON c.customerid = t.customerid GROUP BY c.customerid", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "customers", + "transactions_1k" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_307", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Time\") FROM cards) NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'table_name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_schema' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_schema", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Update_Time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Update_Time", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "tables" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_308", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.* FROM match AS m WHERE m.league_id = '1' GROUP BY m.date ORDER BY m.date ASC NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_309", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n id,\n MAX(Max_v) AS Max_v,\n NULL AS MAX_attribute\nFROM (\n SELECT id, crossing AS Max_v, 'crossing' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, finishing AS Max_v, 'finishing' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, heading_accuracy AS Max_v, 'heading_accuracy' AS AttributeName FROM Player_Attributes\n UNION ALL\n SELECT id, short_passing AS Max_v, 'short_passing' AS AttributeName FROM Player_Attributes\n UNION ALL\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-GROUP-UNION-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "SELECT", + "SUBQUERY", + "UNION" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_310", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Expected table name but got . Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');\n\nInvalid expression / Unexpected token. Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_311", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE content (id serial PRIMARY KEY NOT NULL, item_id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_item_id <> id)", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Required keyword: 'expressions' missing for . Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)\n\nExpecting ). Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_312", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT cd.*, fd.* FROM cards cd INNER JOIN foreign_data fd ON cd.uuid = fd.uuid WHERE cd.availability = 'mtgo,paper' ORDER BY cd.releaseDate DESC, cd.uuid, fd.id LIMIT 100;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "foreign_data" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_313", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.col2, t.col3 FROM (SELECT '2023-01-01' AS col1, 'Some ruling text.' AS col2, (SELECT uuid FROM cards WHERE borderColor = 'black' AND layout = 'normal') AS col3 UNION ALL SELECT '2023-01-02' AS col1, 'Another ruling text.' AS col2, (SELECT uuid FROM cards WHERE isAlternative = 1) AS col3) t WHERE NOT EXISTS (SELECT 1 FROM rulings WHERE rulings.date = t.col1::date);", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2521, + "pattern_signature": "SELECT-FROM-WHERE-UNION-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "cards", + "rulings" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_314", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO constructorResults (constructorResultsId, raceId, constructorId, points, status)\nSELECT constructorResults.constructorResultsId, constructorResults.raceId, constructorResults.constructorId, constructorResults.points, constructorResults.status FROM constructors INNER JOIN constructorResults ON constructorResults.constructorResultsId = constructors.constructorId;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-INSERT", + "clauses_present": [ + "FROM", + "INSERT", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "constructorresults", + "constructors" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_315", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE Match SET date = TO_CHAR(make_timestamp(extract(year from date::timestamp)::int, extract(month from date::timestamp)::int, extract(day from date::timestamp)::int, 14, extract(minute from date::timestamp)::int, extract(second from date::timestamp)::double precision), 'YYYY-MM-DD HH24:MI:SS');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_316", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT element FROM atom LEFT JOIN molecule ON atom.molecule_id = molecule.molecule_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_317", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT humidity_level, (humidity_level - LAG(humidity_level, 1) OVER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_humidity WHERE diff = 0 OR diff > 10", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'warehouse_humidity' does not exist in schema", + "taxonomy_category": "semantic", + "context": "warehouse_humidity", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "warehouse_humidity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_318", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders@lpu.edu;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 95.\n SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders\u001b[4m@\u001b[0mlpu.edu;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'members' does not exist in schema", + "taxonomy_category": "semantic", + "context": "members", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "members" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_319", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, SUM(count) AS COUNT, SUM(excerptpostid) AS EXCERPTPOSTID FROM backup_colour", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "backup_colour" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_320", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id FROM cards JOIN decks ON cards.id = decks.card1_id WHERE decks.card1_id <> 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_321", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, COUNT(*) FROM races", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_322", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT team_list.t_id FROM team_list LEFT JOIN detail ON team_list.t_id = detail.t_id WHERE detail.type IN ('a', 'b') GROUP BY team_list.t_id HAVING COUNT(DISTINCT detail.type) = 2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0677, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "detail", + "team_list" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_323", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH MissingValues AS (SELECT a.id + 1 AS missing_value FROM worker1 AS a LEFT JOIN worker1 AS b ON a.id + 1 = b.id WHERE b.id IS NULL) SELECT MIN(missing_value) AS lowest_missing_value FROM missingvalues WHERE NOT missing_value IN (SELECT id FROM worker2)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "missingvalues", + "worker1", + "worker2" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_324", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT userid, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as view_rank, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as favorite_rank, RANK() OVER (ORDER BY viewcount, favoritecount, upvotecount DESC) as upvote_rank FROM user_record ORDER BY userid", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0292, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "user_record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_326", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SUM(t1.quantity) AS total FROM products AS t1 LEFT JOIN records AS t2 ON t1.order_id = t2.order_id WHERE t2.order_status = 'A'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "products", + "records" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_327", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT type, COUNT(*) AS type_count FROM card_type WHERE cardid IN (SELECT DISTINCT cardid FROM info) GROUP BY type ORDER BY type_count DESC NULLS LAST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "card_type", + "info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_328", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT results.score, scores.value, scores.segment FROM customer_scores AS scores JOIN customer_results AS results ON scores.segment = results.segment WHERE results.score >= scores.score GROUP BY scores.segment ORDER BY scores.customerid DESC NULLS LAST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "customer_results", + "customer_scores" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_329", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CHECK(id <> spouseid)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_330", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE log_content (\"log_id\" INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, \"content\" VARCHAR(32) NOT NULL, \"no_of_chars\" INT NULL DEFAULT CHAR_LENGTH(\"content\"), PRIMARY KEY (\"log_id\"))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "log_content" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_331", + "db_id": "debit_card_specializing", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE products SET description = 'Other' WHERE productid = 2", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "WHERE-UPDATE", + "clauses_present": [ + "UPDATE", + "WHERE" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_332", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CASE WHEN amount_sold < 1000 THEN 'Under 1000' WHEN amount_sold BETWEEN 1000 AND 9999 THEN '1000 to 9999' WHEN amount_sold BETWEEN 10000 AND 49999 THEN '10000 to 49999' WHEN amount_sold >= 50000 THEN '50000 and above' END AS range, AVG(Count) AS avg FROM sales_data GROUP BY range", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'sales_data' does not exist in schema", + "taxonomy_category": "semantic", + "context": "sales_data", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_333", + "db_id": "formula_1", + "category": "Management", + "sql_index": 0, + "sql": "DELETE FROM pitstops WHERE raceid = (SELECT MIN(raceid) FROM pitstops GROUP BY milliseconds HAVING COUNT(*) > 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING-DELETE-SUBQUERY", + "clauses_present": [ + "DELETE", + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_335", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT c.* FROM cards c WHERE c.setcode IN (SELECT setcode FROM cards WHERE isreprint = 1) OR c.id = (SELECT MAX(id) FROM cards WHERE setcode = c.setcode AND isreprint = 0)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_336", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < 40000);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'list' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "list" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_337", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "SELECT * FROM rules AS t1 WHERE t1.valid_from <= '2024-12-31' AND (t1.valid_to >= '2022-07-01' OR t1.valid_to IS NULL) AND NOT EXISTS(SELECT 1 FROM rules AS t2 WHERE t2.valid_from > t1.valid_from AND t2.valid_from <= '2024-12-31' AND (t2.valid_to IS NULL OR t2.valid_to > '2022-07-01') AND t2.valid_from <= COALESCE(t1.valid_to, '2024-12-31'))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0979, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "rules" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_338", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.product_code, t1.product_id, t1.assign_key, STRING_AGG(t2.value_name, ',') FROM products_sample AS t1 LEFT JOIN value_list AS t2 ON t2.value_id::text = ANY(string_to_array(t1.assign_key, ',')) GROUP BY t1.assign_key", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "products_sample", + "value_list" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_339", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, p.name, c.item, c.size FROM packages p LEFT JOIN contents c ON (c.packageid=p.id) WHERE (( p.id IN ( SELECT packageid FROM contents WHERE item='square' AND size='A' ) AND ( p.id IN ( SELECT packageid FROM contents WHERE item='circle' AND size='B' )) GROUP BY p.id HAVING ( SELECT COUNT(*) FROM contents WHERE packageid=p.id ) = 2;", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "2 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.2667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "contents", + "packages" + ], + "num_joins": 1, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_340", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ProductID, SPLIT_PART(Description, 'x', 1) AS count, SPLIT_PART(Description, 'x', 2) AS type FROM product", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "product" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_341", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH duplicates AS (SELECT product FROM promotions GROUP BY product HAVING COUNT(product) > 1) SELECT * FROM promotions INNER JOIN duplicates ON promotions.product = duplicates.product", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "duplicates", + "promotions" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_342", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team, MIN(source) AS source, MAX(destination) AS destination FROM source_destination_flight GROUP BY team", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "source_destination_flight" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_343", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)), u.displayname, COUNT(c.id) AS nbrOfComments FROM comments AS c INNER JOIN users AS u ON c.userid = u.id WHERE EXTRACT(YEAR FROM CAST(c.creationdate AS DATE)) = '2010' GROUP BY u.id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "comments", + "users" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_344", + "db_id": "debit_card_specializing", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT t1.transactionid, g.gasstationid, p.productid, COALESCE(t1.date, g.country, p.description) AS date, COALESCE(t1.amount, 0) AS amount, COALESCE(g.chainid, 0) AS chainid, COALESCE(p.description, '') AS description FROM transactions_1k AS t1 FULL OUTER JOIN gasstations AS g ON t1.gasstationid = g.gasstationid FULL OUTER JOIN products AS p ON COALESCE(t1.date, g.country) = p.productid WHERE t1.date IS NULL AND g.country IS NULL", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "gasstations", + "products", + "transactions_1k" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_345", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO account (\"account_id\", \"district_id\", \"frequency\", \"account_type\", \"date\") VALUES (12345, 18, 'POPLATEK MESICNE', 'Regular', '1970-12-13')", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_346", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE HierarchyCTE(entityid, parentid, emission, total_emission, percentage, level) AS (\n SELECT entityid, parentid, emission, emission AS total_emission, pctcontribution, 0\n FROM tree_table\n WHERE NOT entityid IN (SELECT DISTINCT parentid FROM tree_table WHERE NOT parentid IS NULL)\n UNION ALL\n SELECT h.entityid, h.parentid, h.emission, h.emission + cte.total_emission * (CAST(cte.pctcontribution AS DOUBLE PRECISION) / NULLIF(100, 0)) AS total_emission, h.pctcontribution, ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2323, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "hierarchycte", + "tree_table" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_348", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT j.* FROM event e, json_array_elements(e.event_schedule->'$.*[*]') AS j(element)\nCROSS JOIN LATERAL (\n SELECT\n (j.element->>'start')::TIME AS date_start,\n (j.element->>'end')::TIME AS date_end,\n (j.element->>'*')::VARCHAR(10) AS day\n) AS j\nWHERE e.event_id='rec0Si5cQ4rJRVzd6';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.149, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_349", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT\n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Expected ]. Line 5, Col: 79.\n \n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract \u001b[4mholidays\u001b[0m] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;\n\nInvalid expression / Unexpected token. Line 5, Col: 80.\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays\u001b[4m]\u001b[0m AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_350", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS count FROM duration AS d WHERE (TIMESTAMP '2011-12-19 12:00:00' >= d.start AND TIMESTAMP '2011-12-19 12:00:00' < d.\"end\") OR (TIMESTAMP '2011-12-19 15:00:00' > d.start AND TIMESTAMP '2011-12-19 15:00:00' <= d.\"end\") OR (d.start BETWEEN TIMESTAMP '2011-12-19 12:00:00' AND TIMESTAMP '2011-12-19 15:00:00' AND d.\"end\" BETWEEN TIMESTAMP '2011-12-19 12:00:00' AND TIMESTAMP '2011-12-19 15:00:00');", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.076, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "duration" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_351", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ct.c_id, bt.start_time::date AS date, trip_counts.trip_count, SUM(CASE WHEN tc.duration = 'Single' AND trip_counts.trip_count = 1 THEN tc.cost WHEN tc.duration = 'Single' AND trip_counts.trip_count = 2 THEN tc.cost * 2 ELSE 0 END) + SUM(CASE WHEN tc.duration = 'Day' AND trip_counts.trip_count >= 3 THEN tc.cost ELSE 0 END) AS total_cost FROM customertrip ct JOIN bustrip bt ON ct.b_id = bt.b_id JOIN ticketcosts tc ON tc.duration IN ('Single', 'Day') JOIN (SELECT b_id, start_time::date AS tr", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.249, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bustrip", + "customertrip", + "ticketcosts" + ], + "num_joins": 3, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_352", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CONCAT(EXTRACT(HOUR FROM description), ' hours, ', EXTRACT(MINUTE FROM description), ' minutes, ', EXTRACT(SECOND FROM description), ' seconds') FROM backup_colour", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "backup_colour" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_353", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE `lessonschedule` (`record_id` SMALLINT NOT NULL, `student_id` SMALLINT, `lesson_date_time` TIMESTAMP NOT NULL, PRIMARY KEY (`record_id`, `student_id`, `lesson_date_time`), CONSTRAINT `fk_record` FOREIGN KEY (`record_id`) REFERENCES `record`(`id`), CONSTRAINT `fk_student` FOREIGN KEY (`student_id`) REFERENCES `student`(`id`));", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_354", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE \"member_privileges\" ADD CONSTRAINT \"member_fk\" FOREIGN KEY REFERENCES \"member\"(\"member_id\");", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "member", + "member_privileges" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_355", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE hero_event (event_id SERIAL PRIMARY KEY, superhero TEXT NOT NULL, event_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIME);", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "hero_event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_356", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "ALTER TABLE superhero ALTER COLUMN description TYPE JSON SET NOT NULL SET DEFAULT '{}';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_357", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT REGEXP_REPLACE(first_name, '(\\w)\\w', '\\1*') AS masked_first_name, REGEXP_REPLACE(last_name, '(\\w)\\w', '\\1*') AS masked_last_name FROM member", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "member" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_358", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.\"event_id\", b.\"amount\", b.\"link_to_member\", \"link_to_event\" FROM event AS b JOIN budget AS b ON b.\"event_id\" = b.\"link_to_event\" LEFT JOIN attendance AS b ON b.\"event_id\" = b.\"link_to_event\" ORDER BY b.\"event_id\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'link_to_event' is ambiguous \u2014 exists in tables: budget, attendance", + "taxonomy_category": "semantic", + "context": "link_to_event", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0833, + "pattern_signature": "SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_359", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE FUNCTION check_alignment(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "Error tokenizing 'alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' EN'", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error" + ] + }, + { + "instance_id": "PostgreSQL_360", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE \"atom_hierarchy\" AS (SELECT \"atom_id\", \"atom_id2\", \"bond_id\", 1 AS \"level\" FROM connected WHERE \"atom_id\" = 'TR007_8' UNION ALL SELECT c.\"atom_id\", c.\"atom_id2\", c.\"bond_id\", ah.\"level\" + 1 FROM connected AS c JOIN atom_hierarchy AS ah ON c.\"atom_id\" = ah.\"atom_id2\") SELECT \"atom_id\", \"atom_id2\", \"bond_id\", \"level\" FROM atom_hierarchy ORDER BY \"level\" NULLS FIRST, \"atom_id\" NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom_hierarchy", + "connected" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_361", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MaxHeightCTE\" AS (SELECT \"alignment_id\", \"publisher_id\", MAX(\"height_cm\") AS \"max_height\" FROM superhero GROUP BY \"alignment_id\", \"publisher_id\"), \"JoinedCTE\" AS (SELECT s.\"id\", s.\"superhero_name\", s.\"alignment_id\", s.\"publisher_id\", s.\"height_cm\", s.\"hair_colour_id\" FROM superhero AS s JOIN maxheightcte AS m ON s.\"alignment_id\" = m.\"alignment_id\" AND s.\"publisher_id\" = m.\"publisher_id\" AND s.\"height_cm\" = m.\"max_height\") SELECT \"alignment_id\", \"publisher_id\", SUM(\"hair_colour_id\") AS \"tot", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "joinedcte", + "maxheightcte", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_362", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_bonds AS (\n SELECT a.\"atom_id\", a.\"molecule_id\", a.\"element\",\n STRING_AGG(c.\"bond_id\", ',' ORDER BY c.\"bond_id\" NULLS FIRST) AS connected_bonds\n FROM atom AS a\n LEFT JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n GROUP BY a.\"atom_id\", a.\"molecule_id\", a.\"element\"\n),\nmolecule_stats AS (\n SELECT m.\"molecule_id\", m.\"label\",\n COUNT(a.\"atom_id\") OVER (PARTITION BY m.\"molecule_id\") AS atom_count,\n ROW_NUMBER() OVER (PARTITION BY m.\"molecule_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_bonds", + "bond", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_363", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_year NUMERIC;\nv_week NUMERIC;\nv_home_team_wins NUMERIC;\nv_away_team_wins NUMERIC;\nv_draws NUMERIC;\nv_total_matches NUMERIC;\nBEGIN\nSELECT EXTRACT(YEAR\n FROM TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')),\n TO_CHAR(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'IW'),\n SUM(CASE\n WHEN \"home_team_goal\" > \"away_team_goal\" THEN 1\n ELSE 0\n END),\n SUM(CASE\n WHEN \"home_team_goal\" < \"away_team_goal\" THEN 1\n", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_364", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT molecule_id, COUNT(*) AS atom_count, string_agg(element, ',' ORDER BY atom_id NULLS FIRST) AS elements\n FROM atom\n GROUP BY molecule_id\n),\nbond_hierarchy AS (\n WITH RECURSIVE hierarchy AS (\n SELECT bond_id, molecule_id, bond_type, 1 AS bond_depth, '/' || bond_id AS bond_path\n FROM bond\n WHERE bond_id LIKE '%\\_2\\_%' ESCAPE '\\'\n UNION ALL\n SELECT b.bond_id, b.molecule_id, b.bond_type, h.bond_depth + 1, \n h.bo", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.5135, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "hierarchy", + "molecule", + "molecule_json" + ], + "num_joins": 7, + "num_subqueries": 2, + "num_ctes": 4, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_365", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", 1 AS level, CAST(m.\"molecule_id\" AS VARCHAR(4000)) AS path\n FROM molecule AS m\n JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n WHERE a.\"element\" = 'cl'\n\n UNION ALL\n\n\n SELECT m.\"molecule_id\", m.\"label\", a.\"atom_id\", a.\"element\", mh.level + 1, mh.path || '->' || m.\"molecule_id\"\n FROM molecule_hierarchy AS mh\n JOIN connected AS c ON mh.\"atom_id\" = c.\"atom_id\"\n JOIN ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy" + ], + "num_joins": 8, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_366", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_atoms AS (\n SELECT m.molecule_id, m.label, a.atom_id, a.element,\n ROW_NUMBER() OVER (PARTITION BY m.molecule_id ORDER BY a.atom_id NULLS FIRST) AS atom_seq\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.molecule_id = a.molecule_id\n),\nmolecule_bonds AS (\n SELECT b.molecule_id, b.bond_id, b.bond_type,\n c.atom_id AS source_atom, c.atom_id2 AS target_atom,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_ran", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'molecule_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2427, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_connections", + "bond", + "connected", + "molecule", + "molecule_atoms", + "molecule_bonds" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_367", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_stats AS (SELECT \"m\".\"date\" AS \"match_date\", \"l\".\"name\" AS \"league_name\", \"c\".\"name\" AS \"country_name\", \"ht\".\"team_long_name\" AS \"home_team\", \"at\".\"team_long_name\" AS \"away_team\", \"m\".\"home_team_goal\" AS \"home_team_goals\", \"m\".\"away_team_goal\" AS \"away_team_goals\", RANK() OVER (PARTITION BY \"m\".\"league_id\", \"m\".\"season\" ORDER BY \"m\".\"home_team_goal\" + \"m\".\"away_team_goal\" DESC NULLS LAST) AS \"high_scoring_rank\" FROM match AS \"m\" INNER JOIN league AS \"l\" ON \"m\".\"league_id\" = \"l\".\"id\" I", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.376, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "country", + "league", + "match", + "match_stats", + "team", + "team_performance" + ], + "num_joins": 6, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_368", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_elements AS (SELECT a.atom_id, a.molecule_id, a.element, RANK() OVER (PARTITION BY a.molecule_id ORDER BY a.atom_id NULLS FIRST) AS element_rank FROM atom AS a), bond_details AS (SELECT b.bond_id, b.molecule_id, b.bond_type, DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_rank FROM bond AS b) SELECT ae.atom_id, ae.molecule_id, ae.element, c.bond_id, CASE WHEN bd.bond_type IS NULL THEN 'Unknown' ELSE bd.bond_type END AS bond_type FROM atom_elements ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_elements", + "bond", + "bond_details", + "connected", + "molecule" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_369", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"m\".\"id\", \"m\".\"home_team_api_id\", \"m\".\"away_team_api_id\", \"m\".\"home_team_goal\", \"m\".\"away_team_goal\", SUM(CASE WHEN \"m\".\"home_team_api_id\" = \"t\".\"team_api_id\" THEN \"m\".\"home_team_goal\" - \"m\".\"away_team_goal\" ELSE \"m\".\"away_team_goal\" - \"m\".\"home_team_goal\" END) OVER (PARTITION BY \"t\".\"team_api_id\" ORDER BY \"m\".\"id\" NULLS FIRST) AS \"goal_difference\" FROM match AS \"m\" INNER JOIN team AS \"t\" ON \"m\".\"home_team_api_id\" = \"t\".\"team_api_id\" OR \"m\".\"away_team_api_id\" = \"t\".\"team_api_id\" WHERE \"m\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "match", + "team" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_370", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT a.molecule_id, COUNT(a.atom_id) AS atom_count,\n STRING_AGG(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements\n FROM atom AS a\n GROUP BY a.molecule_id\n),\nbond_hierarchy AS (\n SELECT bond_id, molecule_id, bond_type,\n SUBSTRING(bond_id FROM '^[^_]+') AS molecule_prefix,\n CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOUBLE PRECISION) AS first_atom_num,\n CAST(SUBSTRING(bond_id FROM '[^_]+$') AS DOUBLE PRECISION)", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'molecule_id' is ambiguous \u2014 exists in tables: atom, bond, molecule", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.4229, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "molecule", + "molecule_connectivity" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_371", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_molecule_id VARCHAR(512);\n v_label TEXT;\n v_atom_id VARCHAR(512);\n v_element TEXT;\n v_atom_id2 VARCHAR(512);\n v_bond_id VARCHAR(512);\n v_bond_type TEXT;\nBEGIN\n SELECT \"m\".\"molecule_id\",\n \"m\".\"label\",\n \"a\".\"atom_id\",\n \"a\".\"element\",\n \"c\".\"atom_id2\",\n \"b\".\"bond_id\",\n \"b\".\"bond_type\"\n FROM \"molecule\" \"m\"\n INNER JOIN \"atom\" \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\"\n INNER JOIN \"connected\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_372", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_elements AS (\n SELECT a.atom_id, a.molecule_id, a.element,\n RANK() OVER (PARTITION BY a.molecule_id ORDER BY a.atom_id NULLS FIRST) AS element_rank\n FROM atom AS a\n),\nbond_details AS (\n SELECT b.bond_id, b.molecule_id, b.bond_type,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_rank\n FROM bond AS b\n),\nmolecule_connections AS (\n SELECT c.atom_id, c.atom_id2, c.bond_id,\n STRING_AGG(c.atom_id2, ',' ORDER ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2677, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_elements", + "bond", + "bond_details", + "connected", + "molecule", + "molecule_connections" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_373", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result\nFROM \"molecule\" m\nINNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\nINNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" INTO :result_variable", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 7, Col: 29.\n a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" \u001b[4mINTO\u001b[0m :result_variable", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_374", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_data AS (SELECT a.atom_id, a.molecule_id, CASE WHEN a.element = 'cl' THEN UPPER(a.element) ELSE a.element END AS element FROM atom AS a), bond_data AS (SELECT b.bond_id, b.molecule_id, CASE WHEN b.bond_type = '-' THEN 'single' WHEN b.bond_type = '=' THEN 'double' WHEN b.bond_type = '#' THEN 'triple' ELSE b.bond_type END AS bond_type FROM bond AS b), molecule_elements AS (SELECT m.molecule_id, string_agg(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements FROM molecule AS m LEFT ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2417, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_data", + "bond", + "bond_data", + "molecule", + "molecule_elements" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_375", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS ( SELECT m.molecule_id, m.label, a.atom_id, a.element, CAST(NULL AS VARCHAR(512)) AS atom_id2, CAST(NULL AS VARCHAR(512)) AS bond_id, CAST(NULL AS TEXT) AS bond_type, 1 AS level, CAST(a.atom_id AS VARCHAR(4000)) AS path FROM molecule AS m JOIN atom AS a ON m.molecule_id = a.molecule_id UNION ALL SELECT h.molecule_id, h.label, h.atom_id, h.element, c.atom_id2, c.bond_id, b.bond_type, h.level + 1, h.path || '->' || c.atom_id2 FROM molecule_hierarchy AS h JOIN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.5208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "pivoted_elements" + ], + "num_joins": 8, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_376", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\", m.\"label\", COUNT(DISTINCT a.\"atom_id\") AS atom_count, COUNT(DISTINCT b.\"bond_id\") AS bond_count\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n LEFT JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n LEFT JOIN bond AS b ON c.\"bond_id\" = b.\"bond_id\" AND b.\"molecule_id\" = m.\"molecule_id\"\n GROUP BY m.\"molecule_id\", m.\"label\"\n),\natom_details AS (\n SELECT a.\"molecule_id\", a.\"atom_id\", a.\"element\",\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3542, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "atom_details", + "bond", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 7, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_377", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_pairs AS (\n SELECT\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM 1 FOR POSITION(',' IN pair_str) - 1))\n ELSE pair_str END AS mol_id1,\n CASE WHEN POSITION(',' IN pair_str) > 0\n THEN TRIM(SUBSTRING(pair_str FROM POSITION(',' IN pair_str) + 1))\n ELSE NULL END AS mol_id2\n FROM (\n SELECT 'TR427, TR430' AS pair_str\n UNION ALL\n SELECT 'TR427, TR431'\n UNION ALL\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3823, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pairs", + "molecule_stats" + ], + "num_joins": 5, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_378", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"m\".\"molecule_id\", \"m\".\"label\", \"a\".\"element\" FROM molecule AS \"m\" INNER JOIN atom AS \"a\" ON \"m\".\"molecule_id\" = \"a\".\"molecule_id\" ORDER BY \"m\".\"molecule_id\" NULLS FIRST, \"a\".\"atom_id2\" NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_379", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\",\n COUNT(DISTINCT a.\"atom_id\") AS atom_count,\n COUNT(DISTINCT b.\"bond_id\") AS bond_count,\n string_agg(DISTINCT CASE WHEN a.\"element\" IS NULL THEN NULL WHEN ',' IS NULL THEN NULL ELSE a.\"element\" END, ',') AS elements\n FROM molecule AS m\n LEFT OUTER JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n LEFT OUTER JOIN connected AS c ON a.\"atom_id\" = c.\"atom_id\"\n LEFT OUTER JOIN bond AS b ON c.\"bond_id\" = b", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.4594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_pivot", + "molecule_stats" + ], + "num_joins": 9, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_380", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\", COUNT(a.\"atom_id\") AS atom_count,\n STRING_AGG(a.\"element\", ',' ORDER BY a.\"atom_id\" NULLS FIRST) AS elements\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.\"molecule_id\" = a.\"molecule_id\"\n GROUP BY m.\"molecule_id\"\n),\nbond_stats AS (\n SELECT b.\"molecule_id\", COUNT(b.\"bond_id\") AS bond_count\n FROM bond AS b\n GROUP BY b.\"molecule_id\"\n)\nSELECT ms.\"molecule_id\", ms.atom_count AS \"total_atoms\", bs.bond_count,\n CASE W", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1896, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "bond_stats", + "molecule", + "molecule_stats" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_381", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"event_id\", e.\"event_name\", e.\"event_date\", e.\"type\",\n(SELECT MAX(CAST(column_value AS timestamp)) AS latest_event_date FROM (VALUES (e.\"event_date\")) AS value_table(column_value)\nWHERE column_value IS NOT NULL) AS latest_event_date FROM \"event\" e", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'column_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "column_value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'column_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "column_value", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-VALUES-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "VALUES", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_382", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n TO_CHAR(type) AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 END) -\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = oldest_year THEN 1 END) AS year_difference\nFROM event,\n (\n SELECT\n MAX(EXTRACT(YEAR FROM event_date::timestamp)) AS recent_year,\n MIN(EXTRACT(YEAR FROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type), recent_year, oldest_year;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'format' missing for . Line 2, Col: 17.\n SELECT\n TO_CHAR(type\u001b[4m)\u001b[0m AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 EN\n\nRequired keyword: 'format' missing for . Line 12, Col: 22.\n ROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type\u001b[4m)\u001b[0m, recent_year, oldest_year;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "event" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_383", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*)\nFROM match m1\nWHERE EXISTS (\n SELECT 1\n FROM match m2\n WHERE m2.home_team_api_id = m1.away_team_api_id\n AND m2.away_team_api_id = m1.home_team_api_id\n)\nAND m1.home_team_api_id < m1.away_team_api_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0521, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_384", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE v_match_id BIGINT;\nv_match_date TEXT;\nv_home_team_goals BIGINT;\nv_away_team_goals BIGINT;\nv_home_team_name TEXT;\nv_away_team_name TEXT;\nv_league_name TEXT;\n\nBEGIN\nSELECT \"match\".\"id\",\n \"match\".\"date\",\n \"match\".\"home_team_goal\",\n \"match\".\"away_team_goal\",\n \"HomeTeam\".\"team_long_name\",\n \"AwayTeam\".\"team_long_name\",\n \"league\".\"name\"\nFROM \"match\"\nINNER JOIN \"team\" \"HomeTeam\" ON \"match\".\"home_team_api_id\" = \"HomeTeam\".\"team_api_id\"\nINNER JOIN \"team\" \"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_385", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_years AS (\n SELECT\n M.league_id,\n EXTRACT(YEAR FROM TO_DATE(M.date, 'YYYY-MM-DD HH24:MI:SS')) AS match_year,\n COUNT(*) AS year_count\n FROM match M\n WHERE M.date IS NOT NULL\n GROUP BY M.league_id, EXTRACT(YEAR FROM TO_DATE(M.date, 'YYYY-MM-DD HH24:MI:SS'))\n),\nleague_stats AS (\n SELECT\n L.id AS league_id,\n L.name AS league_name,\n C.name AS country_name,\n COUNT(DISTINCT M.id) AS total_matches\n FROM league L\n JOIN count", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "country", + "league", + "league_stats", + "match", + "match_years" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_386", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH temp AS\n (SELECT a.\"atom_id\",\n a.\"molecule_id\",\n ROW_NUMBER() OVER (PARTITION BY a.\"molecule_id\"\n ORDER BY a.\"atom_id\") - TO_DATE(REGEXP_SUBSTR(a.\"atom_id\", '\\d+$'), 'DD') AS grp\n FROM \"atom\" a), temp2 AS\n (SELECT t.\"atom_id\",\n t.\"molecule_id\",\n COUNT(*) OVER (PARTITION BY t.\"molecule_id\", t.grp) AS cnt\n FROM temp t)\nSELECT t2.\"atom_id\",\n t2.\"molecule_id\"\nFROM temp2 t2\nWHERE t2.cnt >= 3\nORDER BY t2.\"molecule_id\",\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "temp", + "temp2" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_387", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n\n set_a (molecule_id, element_count) AS (\n SELECT molecule_id, COUNT(DISTINCT element)\n FROM atom\n GROUP BY molecule_id\n HAVING COUNT(DISTINCT element) > 1\n ),\n set_b (molecule_id, element_count) AS (\n SELECT m.molecule_id, COUNT(DISTINCT a.element)\n FROM molecule m\n JOIN atom a ON m.molecule_id = a.molecule_id\n WHERE m.label IS NOT NULL\n GROUP BY m.molecule_id\n ),\n\n unique_a (molecule_id, element_count, rn, densi", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'bond_id' is ambiguous \u2014 exists in tables: bond, connected", + "taxonomy_category": "semantic", + "context": "bond_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'element_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "element_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.5177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "set_a", + "set_b", + "unique_a", + "unique_b" + ], + "num_joins": 6, + "num_subqueries": 2, + "num_ctes": 5, + "num_aggregations": 12 + } + }, + { + "instance_id": "PostgreSQL_388", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule_id\",\n\n (SELECT \"element\"\n FROM \"atom\"\n WHERE \"molecule_id\" = \"atom\".\"molecule_id\") AS \"elements\"\nFROM \"atom\"\nGROUP BY \"molecule_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_389", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DISTINCT \"molecule_id\",\n STRING_AGG(DISTINCT \"atom_id\", ',') OVER (PARTITION BY \"molecule_id\" ORDER BY \"atom_id\") AS \"atom_ids\"\nFROM \"atom\"\nWHERE \"molecule_id\" = 'TR011'\nGROUP BY \"molecule_id\",\n \"atom_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "DISTINCT", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "atom" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_390", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS\n (SELECT \"id\",\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_date,\n TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'fmDay', 'English') AS day_of_week,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_start_time,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '2 HOUR' AS match_end_time\n FROM \"match\")\nSELECT m.*,\n ROUND(GREATEST(LEAST(m.match_end_time, m.match_date + INTERVAL '17:00:00' HOUR TO SECOND) - GREATEST(m.ma", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'DBA_VIEWS' does not exist in schema", + "taxonomy_category": "semantic", + "context": "DBA_VIEWS", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "dba_views", + "match", + "match_dates" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_391", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH tiers AS (SELECT 1 as tier_start, 4 as tier_end, 20 as rate UNION SELECT 5, 8, 50 UNION SELECT 10, 12, 100), input_qty AS (SELECT height_cm as quantity FROM superhero WHERE id = 1) SELECT SUM(CASE WHEN quantity >= tier_start THEN (LEAST(quantity, tier_end) - tier_start + 1) * rate ELSE 0 END) as total FROM tiers CROSS JOIN input_qty", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "input_qty", + "superhero", + "tiers" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_392", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"home_team_api_id\" AS \"team_api_id\",\n \"start_date\",\n \"end_date\",\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (consecutive_wins+) DEFINE consecutive_wins AS \"league_id\" = 'EUROPEAN_FOOTBALL_2')", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 6, Col: 38.\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n \u001b[4mORDER BY\u001b[0m \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\n\nInvalid expression / Unexpected token. Line 6, Col: 54.\n OM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" \u001b[4mMEASURES\u001b[0m FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (conse", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'match_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "match_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_393", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT\n molecule_id,\n COUNT(*) AS atom_count,\n (array_agg(element ORDER BY atom_id))[1] AS first_element,\n (array_agg(element ORDER BY atom_id DESC))[1] AS last_element\n FROM \"atom\"\n GROUP BY molecule_id\n),\nranked_atoms AS (\n SELECT\n a.\"atom_id\",\n a.\"molecule_id\",\n a.\"element\",\n DENSE_RANK() OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"atom_id\") AS atom_rank,\n stats.atom_count,\n stats.first_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1583, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "filtered_atoms", + "ranked_atoms" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_394", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE split_date AS (\n SELECT id,\n date,\n 1 AS level,\n SPLIT_PART(date, ' ', 1) AS date_part\n FROM team_attributes\n\n UNION ALL\n\n SELECT s.id,\n s.date,\n s.level + 1,\n SPLIT_PART(s.date, ' ', s.level + 1) AS date_part\n FROM split_date s\n WHERE s.level < regexp_count(s.date, ' ') + 1\n AND s.date_part != ''\n)\nSELECT id, date_part\nFROM split_date", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0844, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "split_date", + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_395", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT REGEXP_REPLACE(cdscode, '\\.[^.]*$', '') AS output\nFROM schools\nWHERE cdscode = '1110.400000.8001382'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_396", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_hierarchy AS (\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n m.\"molecule_id\" AS root_molecule_id,\n 1 AS hierarchy_level,\n '/' || m.\"molecule_id\" AS molecule_path\n FROM \"molecule\" m\n JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\n JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\n JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\n WHERE b.\"bond_type\" = '-'\n\n UNION ALL\n\n SELECT\n m.\"molecule_id\",\n m.\"label\",\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.4427, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "molecule_months", + "month_generator" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_397", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH tbl AS\n (SELECT TO_DATE('12.01.2023', 'dd.mm.yyyy') AS act_date\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('19.01.2023', 'dd.mm.yyyy')\n FROM (SELECT 1) AS dummy\n UNION ALL SELECT TO_DATE('12.02.2023', 'dd.mm.yyyy')\n FROM (S", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.4104, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "grid", + "molecule", + "molecule_activity", + "t2", + "tbl" + ], + "num_joins": 2, + "num_subqueries": 19, + "num_ctes": 4, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_398", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"credits\" AS (\n SELECT\n 5001 AS \"ID\",\n 12 AS \"ARTCRED\",\n 7.5 AS \"BIZCRED\",\n 12 AS \"HUMCRED\",\n 14 AS \"NATCRED\",\n 11 AS \"TEKCRED\",\n 9 AS \"GENCRED\",\n TO_DATE('01.01.2010', 'dd.mm.yyyy') AS \"EFFECTIVE_DATE\"\n UNION ALL\n SELECT\n 5001 AS \"ID\",\n 15 AS \"ARTCRED\",\n 9 AS \"BIZCRED\",\n 14 AS \"HUMCRED\",\n 16 AS \"NATCRED\",\n 13 AS \"TEKCRED\",\n 11 AS \"GENCRED\",\n TO_DATE('01.01.2020', 'dd.mm.", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "credits", + "grp_choices", + "latest_credits" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_399", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\"\nFROM\n (SELECT \"team_api_id\",\n \"buildupplayspeed\",\n \"date\",\n ROW_NUMBER() OVER (PARTITION BY \"team_api_id\"\n ORDER BY TO_NUMBER(\"date\") DESC) AS seq\n FROM \"team_attributes\")\nWHERE seq = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_400", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH player_data AS (\n SELECT\n p.player_api_id AS player_id,\n 'name' AS attribute_type,\n p.player_name AS attribute_value\n FROM player p\n WHERE p.player_api_id IS NOT NULL\n UNION ALL\n SELECT\n pa.player_api_id AS player_id,\n 'rating' AS attribute_type,\n CAST(pa.overall_rating AS TEXT) AS attribute_value\n FROM player_attributes pa\n WHERE pa.date = (\n SELECT MAX(date)\n FROM player_attributes\n WHERE player_api_id = p", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2698, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "player", + "player_attributes", + "player_data", + "player_stats" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_401", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"MY_TABLE\" AS\n (SELECT '1111' AS \"TECHNICAL_ID\",\n 'NOTIONALCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '1111' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n 'FWDNOTLCR' AS \"ASSET_TYPE\"\n UNION ALL SELECT '2222' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_ID\",\n '50000' AS \"ASSET_TYPE\"\n UNION ALL SELECT '3333' AS \"TECHNICAL_I", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.125, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "map_recrf_asset_type", + "my_table" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_402", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS (\n SELECT m.country_id,\n m.date,\n m.league_id,\n m.season,\n DENSE_RANK() OVER (PARTITION BY m.country_id ORDER BY m.date DESC) AS match_rank\n FROM \"match\" m\n WHERE m.date IS NOT NULL\n),\ncountry_stats AS (\n SELECT c.id AS country_id,\n c.name AS country_name,\n COUNT(DISTINCT m.league_id) AS league_count,\n COUNT(DISTINCT m.season) AS season_count\n FROM \"country\" c\n LEFT JOIN \"match\" m ON c.id ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2708, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "country", + "country_stats", + "league", + "match", + "match_dates", + "match_summary" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 10 + } + }, + { + "instance_id": "PostgreSQL_403", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT T.\"team_long_name\",\n T.\"team_short_name\",\n TA.\"buildUpPlaySpeed\",\n TA.\"buildUpPlaySpeedClass\",\n TA.\"chanceCreationShooting\",\n TA.\"chanceCreationShootingClass\",\n TA.\"defencePressure\",\n TA.\"defencePressureClass\"\nFROM \"team\" T\nINNER JOIN \"team_attributes\" TA ON T.\"team_api_id\" = TA.\"team_api_id\"\nWHERE TA.\"date\" = '2013-09-20 00:00:00'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_404", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"valid_from\",\n \"valid_until\",\n \"count\"\nFROM\n (SELECT \"dt\" AS \"valid_from\",\n LEAD(\"dt\") OVER (\n ORDER BY \"dt\") - INTERVAL '1' SECOND AS \"valid_until\",\n SUM(\"count\" * \"type\") OVER (\n ORDER BY \"dt\") AS \"count\"\n FROM\n (SELECT \"valid_from\",\n \"valid_until\" + INTERVAL '1 DAY' AS \"valid_until\",\n 1 AS \"count\"\n FROM\n (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2885, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_405", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH school_data AS (\n SELECT\n s.cdscode AS \"pk\",\n CASE\n WHEN s.charter = 1 THEN 'Charter'\n WHEN s.magnet = 1 THEN 'Magnet'\n ELSE 'Regular'\n END AS \"col2\",\n SUBSTRING(s.county FROM 1 FOR POSITION(' ' IN s.county) - 1) AS \"col3\",\n TO_TIMESTAMP(TO_CHAR(s.lastupdate, 'YYYY/MM/DD') || ' ' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode), 24) AS TEXT), 2, '0') || ':' ||\n LPAD(CAST(MOD(ROW_NUMBER() OVER (ORDER BY s.cdscode) * 7, 60) AS TEXT), ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "aggregated_data", + "filtered_data", + "school_data", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_406", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"data\" AS\n (SELECT 101 AS \"id\",\n 'A' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 10 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'B' AS \"type\",\n 20 AS \"part\"\n UNION ALL SELECT 101 AS \"id\",\n 'C' AS \"type\",\n 30 AS \"part\"\n UNION A", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1302, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-UNION", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "data", + "w_cnt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_407", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"columns\" (\"column_name\") AS\n (SELECT 'cdscode'\n UNION ALL SELECT 'statustype'\n UNION ALL SELECT 'school'),\n \"column_exists\" (\"column_name\",\n \"column_exists\") AS\n (SELECT c.\"column_name\",\n COALESCE(a.attname, 'NO')\n FROM \"columns\" c\n LEFT OUTER JOIN pg_attribute a ON (a.attrelid = 'schools'::regclass\n AND c.\"column_name\" = a.attname))\nSELECT *\nFROM \"column_exists\"\nPIVOT (MAX(\"column_exists\")\n FOR \"column_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1604, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "column_exists", + "columns", + "pg_attribute" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_408", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH string1_tab AS (\n SELECT REGEXP_SUBSTR('24,36,78,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('24,36,78,98') - LENGTH(REPLACE('24,36,78,98', ',', '')) + 1)\n),\nstring2_tab AS (\n SELECT REGEXP_SUBSTR('25,36,88,98', '[^,]+', 1, generate_series) AS value,\n generate_series AS position\n FROM generate_series(1, LENGTH('25,36,88,98') - LENGTH(REPLACE('25,36,88,98', ',', '')) + 1)\n),\nstring1_parsed AS (\n S", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-HAVING-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "common_values", + "string1_parsed", + "string1_tab", + "string2_parsed", + "string2_tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 5, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_409", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH t AS\n (SELECT \"date\",\n \"match_api_id\" AS code,\n CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')) AS duration,\n COUNT(*) OVER (PARTITION BY DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')), \"match_api_id\", CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'))) AS cnt,\n MIN(CURRENT_DATE - DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS'))) OVER (PARTITION BY DATE(TO_TIMESTAMP(\"date\", 'YYYY-MM-DD HH24:MI:SS')), \"match_api_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "t" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_410", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n GREATEST(DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 day') + INTERVAL '1 day' + (m.months * INTERVAL '1 month'), CURRENT_DATE) AS bond_formation_date\nFROM \"bond\" b\nJOIN\n (SELECT generate_series(0, 5) AS months) m\nGROUP BY b.\"bond_id\",\n b.\"molecule_id\",\n b.\"bond_type\",\n m.months\nHAVING b.\"molecule_id\" = 'TR011'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1229, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "bond" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_411", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH team_speed_stats AS (\n SELECT\n team_api_id,\n date,\n buildupplayspeed,\n ROW_NUMBER() OVER (PARTITION BY team_api_id ORDER BY date DESC) as rn,\n AVG(buildupplayspeed) OVER (PARTITION BY buildupplayspeedclass) as class_avg_speed\n FROM team_attributes\n),\nmatch_details AS (\n SELECT\n m.id,\n m.date,\n m.home_team_api_id,\n m.away_team_api_id,\n m.home_team_goal,\n m.away_team_goal,\n t.team_long_name as home_te", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.499, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "match_details", + "team", + "team_attributes", + "team_speed_stats" + ], + "num_joins": 5, + "num_subqueries": 4, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_412", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with lose_agg as\n (select team_api_id,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2011 then defencepressure\n end) as lose_5,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2012 then defencepressure\n end) as lose_10\n from team_attributes\n group by team_api_id),\n profit_agg as\n (select team_api_id,\n sum(case\n when extract(ye", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 29, Col: 6.\n join profit_agg p on l.team_api_id = p.team_api_id\norder by coalesce(p.team_api_id, l.team_api_id)\n\u001b[4mselect\u001b[0m extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) as year\nfrom team_attributes\nwhere date =", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "lose_agg", + "profit_agg", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_413", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT \"id\", \"date\", \"home_team_goal\", LAG(\"home_team_goal\") OVER (ORDER BY \"date\" DESC) AS prev_home_goal FROM \"match\" WHERE \"date\" <= '2024-02-26'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_414", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT \"atom_id\",\n \"bond_id_1\",\n \"bond_id_2\",\n \"bond_id_3\"\nFROM (\n SELECT \"atom_id\", \"bond_id\",\n CASE WHEN \"bond_id\" = 1 THEN \"bond_id\" END AS \"bond_id_1\",\n CASE WHEN \"bond_id\" = 2 THEN \"bond_id\" END AS \"bond_id_2\",\n CASE WHEN \"bond_id\" = 3 THEN \"bond_id\" END AS \"bond_id_3\"\n FROM \"connected\"\n) AS pivoted_data\nORDER BY \"atom_id\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "connected" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_415", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH OrderedCategories AS (\n SELECT\n SUM(spent) AS category_total,\n category\n FROM budget\n GROUP BY category\n ORDER BY category DESC\n),\nCumulative AS (\n SELECT category_total, category,\n SUM(category_total) OVER (ORDER BY category DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_sum\n FROM OrderedCategories\n)\nSELECT category_total, category\nFROM Cumulative\nWHERE cumulative_sum <= 800\nAND (cumulative_sum - category_total) < 800", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "budget", + "cumulative", + "orderedcategories" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_416", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT player_id,\n MAX(overall_rating) AS overall_rating,\n potential,\n preferred_foot,\n attacking_work_rate\nFROM (SELECT player_api_id AS player_id, overall_rating, potential, preferred_foot, attacking_work_rate, row_number() OVER (PARTITION BY player_api_id ORDER BY date DESC) as rn FROM player_attributes WHERE date <= '2015-12-31') subquery\nWHERE rn = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_417", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_name\"))\n ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZE = 2) AS result\nFROM \"team\"\nWHERE \"id\" IN\n (SELECT \"id\"\n FROM \"team_attributes\"\n WHERE \"date\" IS NULL)", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 1, Col: 39.\n SELECT XMLSERIALIZE(DOCUMENT \u001b[4mXMLELEMENT\u001b[0m(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long\n\nInvalid expression / Unexpected token. Line 1, Col: 40.\n SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT\u001b[4m(\u001b[0mNAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_418", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_times AS (\n SELECT\n \"date\",\n \"match_api_id\",\n EXTRACT(HOUR FROM CAST(\"date\" AS TIMESTAMP)) +\n EXTRACT(MINUTE FROM CAST(\"date\" AS TIMESTAMP))/60 AS hour_of_day,\n TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'YYYY-MM-DD') AS match_date_str\n FROM \"match\"\n),\ntarget_times AS (\n SELECT 8 AS target_hour\n UNION ALL\n SELECT 20 AS target_hour\n),\ndistance_calc AS (\n SELECT\n mt.\"date\",\n mt.\"match_api_id\",\n mt.match_date_str,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1438, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distance_calc", + "match", + "match_times", + "target_times" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_419", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT REPLACE(SUBSTR(date, 1, INSTR(date, '.', -1) - 1), '.') || SUBSTR(date, INSTR(date, '.', -1)) AS \"updated_value\"\nFROM team_attributes\nWHERE date LIKE '%.%'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "team_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_420", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_stats AS (\n SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") AS atom_count,\n MIN(a.\"element\") AS first_element\n FROM \"molecule\" m\n LEFT JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\n GROUP BY m.\"molecule_id\"\n),\natom_details AS (\n SELECT a.\"molecule_id\",\n a.\"atom_id\",\n ROW_NUMBER() OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"atom_id\") AS atom_seq,\n LEAD(a.\"atom_id\") OVER (PARTITION BY a.\"molecule_id\" ORDER BY a.\"ato", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_details", + "connected", + "molecule", + "molecule_stats" + ], + "num_joins": 5, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_421", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"my_table\" AS\n (SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A1' AS \"file_\",\n 5 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A2' AS \"file_\",\n 3 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A3' AS \"file_\",\n 2 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A4' AS \"file_\",\n ", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 38, Col: 46.\n ize\"\n FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n \u001b[4mORDER BY\u001b[0m \"rn\" MEASURES MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((\n\nInvalid expression / Unexpected token. Line 38, Col: 60.\n my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n ORDER BY \"rn\" \u001b[4mMEASURES\u001b[0m MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((same_nif* nif)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "my_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_422", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE \"a\" (\"test\") AS\n (SELECT 'Jack|Sparrow|17-09-16|DY7009|Address at some where|details '\n UNION ALL SELECT 'Jack|Sparrow|17-09-16|DY7009|'\n UNION ALL SELECT 'Jack|Sparrow|17-09-16'\n UNION ALL SELECT \"test\" || '|MoreData'\n FROM \"a\")\nSELECT \"test\",\n REGEXP_SUBSTR(\"test\", '([^|]+\\|?){1,5}') AS \"res\"\nFROM \"a\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "a" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_423", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM \"event\"\n WHERE \"status\"::text <> 'Closed'\n ORDER BY \"event_date\"\n OFFSET 10 ROWS FETCH FIRST 5 ROWS ONLY\n FOR UPDATE SKIP LOCKED;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-OFFSET-LOCKING", + "clauses_present": [ + "FROM", + "LOCKING", + "OFFSET", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_424", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n \"molecule\".\"molecule_id\",\n MIN(\"atom\".\"atom_id\") AS \"first_atom_id\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\";", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "molecule" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_425", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule\".\"molecule_id\",\n \"molecule\".\"label\",\n \"atom\".\"atom_id\",\n \"atom\".\"element\",\n \"bond\".\"bond_id\",\n \"bond\".\"bond_type\",\n \"connected\".\"atom_id2\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\"\nINNER JOIN \"connected\" ON \"atom\".\"atom_id\" = \"connected\".\"atom_id\"\nINNER JOIN \"bond\" ON \"connected\".\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \"connected\".\"atom_id2\";", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 14, Col: 20.\n .\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \u001b[4m\"connected\"\u001b[0m.\"atom_id2\";", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_426", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE \"frpm\" AS target\n \"Charter School (Y/N)\" = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Eligible Free (K-12)\" >= 0.5\n ) AS source\n WHERE target.\"cdscode\" = source.\"cdscode\";", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 26.\n UPDATE \"frpm\" AS target\n \u001b[4m\"Charter School (Y/N)\"\u001b[0m = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Elig", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_427", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n player_fifa_api_id as id,\n MIN(date::date) AS first_date,\n MAX(date::date) AS last_date\n FROM player_attributes\n GROUP BY player_fifa_api_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_428", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.molecule_id AS ID, COUNT(a.atom_id) AS QTY, COUNT(b.bond_id) AS VALUE FROM molecule m LEFT JOIN atom a ON m.molecule_id = a.molecule_id LEFT JOIN bond b ON m.molecule_id = b.molecule_id GROUP BY m.molecule_id;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "SELECT-FROM-JOIN-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "molecule" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_429", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE molecule_atoms_recursive AS (\n SELECT \"molecule_id\", 1 AS atom_number, atom_count\n FROM (\n SELECT \"molecule_id\", COUNT(\"atom_id\") AS atom_count\n FROM \"atom\"\n GROUP BY \"molecule_id\"\n ) base\n UNION ALL\n SELECT mar.\"molecule_id\", mar.atom_number + 1, mar.atom_count\n FROM molecule_atoms_recursive mar\n\n)\nSELECT \"molecule_id\", atom_number\nFROM molecule_atoms_recursive;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1521, + "pattern_signature": "WITH-CTE-SELECT-FROM-GROUP-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "SELECT", + "SUBQUERY", + "UNION", + "WITH" + ], + "tables": [ + "atom", + "molecule_atoms_recursive" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_430", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE replacements (molecule_id, current_label, current_spos) AS (\n SELECT molecule_id,\n label::text,\n strpos(label::text, '+')\n FROM molecule\n UNION ALL\n SELECT r.molecule_id,\n overlay(r.current_label placing '-' from r.current_spos for 1),\n strpos(overlay(r.current_label placing '-' from r.current_spos for 1), '+')\n FROM replacements r\n WHERE r.current_spos > 0\nSELECT molecule_id,\n current_label AS label\nFROM replacements\n\nWHERE current_spos", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "molecule", + "replacements" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_431", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT s.\"cds\",\n s.\"sname\"::text,\n (SELECT json_agg(json_build_object(\n 'enroll12', t.\"enroll12\"::text,\n 'NumTstTakr', t.\"numtsttakr\"::text,\n 'AvgScrRead', t.\"avgscrread\"::text,\n 'AvgScrMath', t.\"avgscrmath\"::text,\n 'AvgScrWrite', t.\"avgscrwrite\"::text\n ) ORDER BY t.\"enroll12\" DESC)\n\n WHERE t.\"rtype\"::text = 'S'\n AND t.\"cds\" = s.\"cds\"\n )\nFROM \"satscores\" s\nWHERE s.\"rtype\"::text = 'S';", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_432", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE Match_Recursive AS (\n SELECT id, country_id, date, home_team_goal, away_team_goal, 1 as lvl\n FROM match\n UNION ALL\n SELECT m.id, m.country_id, m.date, m.home_team_goal, m.away_team_goal, mr.lvl + 1\n FROM match m\n JOIN Match_Recursive mr ON m.country_id = mr.country_id\n WHERE mr.lvl < 2\n)\nSELECT\n json_build_object(\n 'country_id' || mr.country_id,\n json_agg(\n json_build_object(\n 'date', mr.date,\n 'home_team_goal', mr.home_team_goal,\n 'away_tea", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "match", + "match_recursive" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_433", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT M.\"id\", MAX(M.\"date\"), M.\"overall_rating\" FROM player_rate AS M GROUP BY M.\"id\", MAX(M.\"date\"), M.\"overall_rating\"", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "player_rate" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_434", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "SELECT guid FROM login WHERE (login, name) IN (SELECT login, name FROM login GROUP BY login, name HAVING COUNT(*) > 1) AND NOT guid IN (SELECT room_guid FROM groups)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "groups", + "login" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_435", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "select \"element\", \"record\"\n from \"frpm_record\"\n union all\n\n select\n substring(\"element\", 1, position('_' in \"element\") - 1) ||'_rate' as element,\n max(case when substring(\"element\", -1) = '2' then \"record\" end) /\n max(case when substring(\"element\", -1) = '1' then \"record\" end) as \"record\"\n from \"frpm_record\"\n group by substring(\"element\", 1, position('_' in \"element\") - 1)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-GROUP-UNION", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "UNION" + ], + "tables": [ + "frpm_record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_436", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH member_data AS (\n SELECT\n member_id,\n member_name,\n ROW_NUMBER() OVER (PARTITION BY member_id ORDER BY member_name) AS rn\n FROM \"member_trunc\"\n),\ntokenized_members AS (\n SELECT\n a.\"link_to_event\",\n generate_series(1, length(a.\"link_to_member\") - length(replace(a.\"link_to_member\", '|', '')) + 1) AS position,\n split_part(a.\"link_to_member\", '|', generate_series(1, length(a.\"link_to_member\") - length(replace(a.\"link_to_member\", '|', '')) + 1))", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1615, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance_trunc", + "member_data", + "member_names", + "member_trunc", + "tokenized_members" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_437", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT a.atom_id, COUNT(c.atom_id2) as connection_count FROM atom a LEFT JOIN connected c ON a.atom_id = c.atom_id WHERE a.atom_id IN (SELECT atom_id FROM test WHERE atom_id LIKE 'TR%') GROUP BY a.atom_id", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'atom_id' is ambiguous \u2014 exists in tables: atom, connected", + "taxonomy_category": "semantic", + "context": "atom_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'atom_id' is ambiguous \u2014 exists in tables: atom, connected", + "taxonomy_category": "semantic", + "context": "atom_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "atom", + "connected", + "test" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_438", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT EXTRACT(YEAR FROM bl.transact_dt_tm) as year, bl.bond_type, COUNT(*) as bond_count FROM bond_list bl RIGHT JOIN bond_ref br ON bl.bond_type = br.bond_type GROUP BY EXTRACT(YEAR FROM bl.transact_dt_tm), bl.bond_type ORDER BY year, br.bond_seq", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0531, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "bond_list", + "bond_ref" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_439", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT header || ': ' || name AS grouped_countries\nFROM (\n SELECT\n MAX(CASE WHEN name LIKE 'Country Group%' THEN name END)\n OVER (ORDER BY id) AS header,\n id,\n name\n FROM country\n)\nWHERE name NOT LIKE 'Country Group%'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [ + "country" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_440", + "db_id": "toxicology", + "category": "Management", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";UPDATE record SET r1 = uuid_generate_v4(), r2 = uuid_generate_v4();", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "record" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_441", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS pgcrypto;\nSELECT digest(product_id::bytea, 'sha1') AS hash_value, length(digest(product_id::bytea, 'sha1')) AS hash_length\nFROM products;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_442", + "db_id": "toxicology", + "category": "Management", + "sql_index": 0, + "sql": "CREATE OR REPLACE FUNCTION FIND_TEST_TABLE_COLUMN(\n IN_COLUMN1 VARCHAR,\n IN_COLUMN2 VARCHAR,\n IN_COLUMN3 VARCHAR,\n IN_COLUMN4 VARCHAR,\n IN_REQUESTED_COLUMN VARCHAR\n) RETURNS VARCHAR AS $$\nDECLARE\n C_TEST_TABLE REFCURSOR;\n C_TEST_TABLE_REC RECORD;\n RESULT VARCHAR(255);\n query TEXT;\nBEGIN\n query := 'SELECT * FROM test_table WHERE column1 = $1 AND column2 = $2 AND column3 = $3';\n IF IN_COLUMN4 IS NULL THEN\n query := query || ';';\n OPEN C_TEST_TABLE F", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "find_test_table_column" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_443", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE EXTENSION IF NOT EXISTS pgcrypto;\nSELECT digest(product_id::bytea, 'sha1') AS hash_value, length(digest(product_id::bytea, 'sha1')) AS hash_length\nFROM products;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "products" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_444", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT event_id, notes, CASE WHEN notes IS NULL THEN LEAD(notes) OVER (ORDER BY event_id ASC NULLS FIRST) ELSE notes END AS imputed_notes FROM event ORDER BY event_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_445", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH MemberEventDates AS (SELECT a.link_to_member, TO_TIMESTAMP(e.event_date, 'YYYY-MM-DD HH24:MI:SS') AS event_date, DENSE_RANK() OVER (PARTITION BY a.link_to_member ORDER BY TO_TIMESTAMP(e.event_date, 'YYYY-MM-DD HH24:MI:SS') DESC NULLS LAST) AS date_rank FROM attendance AS a LEFT JOIN event AS e ON a.link_to_event = e.event_id WHERE e.status = 'Open' OR e.status IS NULL), LatestEvents AS (SELECT link_to_member, MAX(CASE WHEN date_rank = 1 THEN event_date END) AS Latest_Event_Date FROM membere", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance", + "event", + "latestevents", + "member", + "membereventdates" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_446", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT trans_id, account_id, date, CASE WHEN CAST(EXTRACT(epoch FROM CAST(CAST(date AS TIMESTAMP) AS TIMESTAMP) - CAST(CAST(MIN(date) OVER (PARTITION BY account_id) AS TIMESTAMP) AS TIMESTAMP)) / 86400 AS BIGINT) <= 30 THEN 'Followup' ELSE 'New' END AS Category FROM trans ORDER BY trans_id NULLS FIRST LIMIT 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_447", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH cte AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY m1.member_id, m2.member_id ORDER BY e.event_date DESC NULLS LAST) AS rn FROM attendance AS a1 JOIN attendance AS a2 ON a1.link_to_event = a2.link_to_event AND a1.link_to_member < a2.link_to_member JOIN member AS m1 ON a1.link_to_member = m1.member_id JOIN member AS m2 ON a2.link_to_member = m2.member_id JOIN event AS e ON a1.link_to_event = e.event_id) SELECT * FROM cte WHERE rn = 1 ORDER BY event_date NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2094, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "attendance", + "cte", + "event", + "member" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_448", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CardLegalities AS (\n SELECT C.uuid, COUNT(L.id) AS LegalityCount, STRING_AGG(L.format, ', ' ORDER BY L.format NULLS FIRST) AS Formats\n FROM cards AS C\n LEFT JOIN legalities AS L ON L.uuid = C.uuid\n GROUP BY C.uuid\n),\nCardDetails AS (\n SELECT C.name, C.manacost, CL.LegalityCount, CL.Formats\n FROM cards AS C\n INNER JOIN cardlegalities AS CL ON CL.uuid = C.uuid\n)\nSELECT name, manacost\nFROM carddetails\nWHERE LegalityCount > 0 AND NOT Formats LIKE '%commander%'\nEXCEPT\nSELECT", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1771, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-EXCEPT-ORDER", + "clauses_present": [ + "CTE", + "EXCEPT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "carddetails", + "cardlegalities", + "cards", + "legalities" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_449", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER (ORDER BY T.transactionid NULLS FIRST) AS Row, CAST(EXTRACT(epoch FROM CAST(CAST(LEAD(T.date, 1, 0) OVER (ORDER BY T.date NULLS FIRST) AS TIMESTAMP) AS TIMESTAMP) - CAST(CAST(T.date AS TIMESTAMP) AS TIMESTAMP)) AS BIGINT) AS TimeDifference FROM transactions_1k AS T LIMIT 100", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_450", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH CardIssuanceDays AS ( SELECT c.card_id, c.issued, TO_CHAR(CAST(CAST(TO_CHAR(c.issued, 'MM/DD/YYYY') AS VARCHAR(10)) AS TIMESTAMP), 'TMDay') AS day_of_week , ROW_NUMBER() OVER (PARTITION BY TO_CHAR(CAST(c.issued AS TIMESTAMP), '%W') ORDER BY c.issued NULLS FIRST) AS rank_in_day FROM card AS c INNER JOIN disp AS d ON c.disp_id = d.disp_id AND d.type = 'OWNER' WHERE c.issued BETWEEN CURRENT_TIMESTAMP + INTERVAL '-5 YEAR' AND 0 + INTERVAL MONTH + INTERVAL '-1 DAY'), WeekdayReference AS ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2156, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "card", + "cardissuancedays", + "disp", + "weekdayreference" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_451", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT full_name, STRPOS(SUBSTR(full_name, 2), ' ') + 2 - 1 FROM superhero", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_452", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT date, account_id, CASE WHEN EXISTS(type = 'PRIJEM' AND 'VYDAJ' AND 'SLUZBY') THEN 1 ELSE 0 END FROM trans GROUP BY \"date\", account_id", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0313, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_453", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH ClientAccountSummary AS (\n SELECT\n cl.client_id,\n cl.gender,\n cl.birth_date,\n d.account_id,\n d.type,\n ROW_NUMBER() OVER (PARTITION BY cl.client_id ORDER BY d.account_id DESC NULLS LAST) AS account_rank\n FROM\n client AS cl\n LEFT JOIN\n disp AS d ON d.client_id = cl.client_id\n WHERE\n d.type = 'OWNER' OR d.type IS NULL\n),\nBabyBoomerFlag AS (\n SELECT\n client_id,\n gender,\n CASE\n WHEN TO_C", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1885, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "babyboomerflag", + "client", + "clientaccountsummary", + "disp" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_454", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT event.event_id, event.event_name, STRING_AGG(attendance.link_to_member, ';') AS attendances, STRING_AGG(budget.category, ';') AS budget_category FROM event LEFT JOIN attendance ON event.event_id = attendance.link_to_event LEFT JOIN budget ON event.event_id = budget.link_to_event WHERE event.event_id = 'reczhS8wix6Kzbp9P' GROUP BY event.event_id, event.event_name", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_455", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 36.\n T \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) \u001b[4mPIVOT\u001b[0m(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_456", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH BudgetCategories AS (SELECT budget_id, category, spent, remaining, amount, event_status, link_to_event, DENSE_RANK() OVER (PARTITION BY link_to_event ORDER BY category NULLS FIRST) AS category_rank FROM budget WHERE link_to_event = 'recggMW2eyCYceNcy'), CategoryRanges AS (SELECT 'Food' AS min_category, 'Speaker Gifts' AS max_category, (SELECT category_rank FROM budgetcategories WHERE category = 'Food' AND link_to_event = 'recggMW2eyCYceNcy') AS min_rank, (SELECT category_rank FROM budgetcat", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "budget", + "budgetcategories", + "categoryranges" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_457", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ???, s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE s.id IN (1, 2, 3)", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 11.\n SELECT ???\u001b[4m,\u001b[0m s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "publisher", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_458", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CircuitFilters AS (SELECT c.circuitid, CASE WHEN c.country LIKE 'M%' THEN 1 ELSE 0 END AS IsCountryStartingWithM, CASE WHEN c.name LIKE '%International%' THEN 1 ELSE 0 END AS HasInternationalInName FROM circuits AS c) SELECT r.raceid FROM races AS r INNER JOIN circuitfilters AS cf ON cf.circuitid = r.circuitid WHERE cf.IsCountryStartingWithM = 1 EXCEPT SELECT r.raceid FROM races AS r INNER JOIN circuits AS c ON c.circuitid = r.circuitid WHERE c.name LIKE '%International%' HAVING COUNT(DISTI", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-HAVING-EXCEPT", + "clauses_present": [ + "CTE", + "EXCEPT", + "FROM", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "circuitfilters", + "circuits", + "races" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_459", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT name, COUNT(printings) AS Prints FROM cards GROUP BY name ORDER BY Prints DESC NULLS LAST LIMIT 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_460", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT atom_id FROM ( SELECT CASE WHEN element = 'cl' AND lead(element) OVER\n(ORDER BY atom_id) = 'c' THEN REPLACE(CONCAT(atom_id, lead(atom_id) OVER (ORDER BY atom_id)), ' ', '')\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expected END after CASE. Line 4, Col: 82.\n _id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN \u001b[4matom_id\u001b[0m, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_461", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (SELECT r.raceId, r.name AS raceName, c.name AS circuitName, d.forename || ' ' || d.surname AS driverName, DENSE_RANK() OVER (PARTITION BY r.year ORDER BY res.points DESC NULLS LAST) AS seasonRanking, res.driverId, res.constructorId, res.position AS finishPosition, res.points, ROW_NUMBER() OVER (PARTITION BY r.raceId, res.constructorId ORDER BY res.points DESC NULLS LAST) AS constructorDriverRank FROM races AS r INNER JOIN circuits AS c ON r.circuitId = c.circuitId INNER JOIN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3219, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "circuits", + "constructorperformance", + "constructors", + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 6, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_462", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT a1.atom_id AS atom_id1, a2.atom_id AS atom_id2, b.bond_id, b.bond_type FROM atom AS a1 CROSS JOIN atom AS a2 LEFT JOIN connected AS c ON a1.atom_id = c.atom_id LEFT JOIN bond AS b ON c.bond_id = b.bond_id WHERE a1.molecule_id = a2.molecule_id ORDER BY a1.atom_id NULLS FIRST, a2.atom_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1167, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-WHERE-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "atom", + "bond", + "connected" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_463", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ID, DATE, GOT, LAST_VALUE(GOT) OVER (PARTITION BY ID ORDER BY DATE NULLS FIRST) AS NEW_GOT FROM laboratory", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_464", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientExamData AS (SELECT P.ID AS PATIENTID, P.SEX, P.BIRTHDAY, E.\"Examination Date\", E.DIAGNOSIS, E.THROMBOSIS, ROW_NUMBER() OVER (PARTITION BY P.ID ORDER BY E.\"Examination Date\" NULLS FIRST) AS ExamRank FROM patient AS P LEFT JOIN examination AS E ON P.ID = E.ID), LatestLabResults AS (SELECT L.ID, L.PLT, L.WBC, ROW_NUMBER() OVER (PARTITION BY L.ID ORDER BY L.\"date\" DESC NULLS LAST) AS LabRank FROM laboratory AS L WHERE L.\"date\" <= CURRENT_TIMESTAMP), PatientRiskProfile AS (SELECT PED.PAT", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.251, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "latestlabresults", + "patient", + "patientexamdata", + "patientriskprofile" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_465", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH data AS (SELECT county, cdscode, ROW_NUMBER() OVER (PARTITION BY county ORDER BY cdscode ASC NULLS FIRST) AS rnk, DENSE_RANK() OVER (PARTITION BY county ORDER BY cdscode ASC NULLS FIRST) AS dense_rnk FROM schools), county_pairs AS (SELECT a.cdscode AS cdscode1, a.county AS county1, b.cdscode AS cdscode2, b.county AS county2, a.rnk AS rnk1, b.rnk AS rnk2, a.dense_rnk AS dense_rnk1, b.dense_rnk AS dense_rnk2 FROM data AS a LEFT JOIN data AS b ON a.county = b.county AND b.dense_rnk = a.dense_r", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1625, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "county_pairs", + "data", + "filtered_pairs", + "schools" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_466", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH MoleculeAtomCounts AS (SELECT molecule_id, COUNT(*) AS atom_count FROM atom GROUP BY molecule_id), BondDetails AS (SELECT b.bond_id, b.molecule_id, b.bond_type, SUBSTRING(b.bond_id FROM 1 FOR POSITION('_' IN b.bond_id) - 1) AS derived_molecule_id, SUBSTRING(b.bond_id FROM POSITION('_' IN b.bond_id) + 1 FOR POSITION('_' IN SUBSTRING(b.bond_id FROM POSITION('_' IN b.bond_id) + 1)) - 1) AS first_atom_suffix, SUBSTRING(b.bond_id FROM POSITION('_' IN SUBSTRING(b.bond_id FROM POSITION('_' IN b.bo", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2781, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "atom", + "bond", + "bonddetails", + "connected", + "moleculeatomcounts" + ], + "num_joins": 4, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_467", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH AtomBondMapping AS (\n SELECT\n a.atom_id,\n SUBSTRING(a.atom_id FROM 1 FOR POSITION('_' IN a.atom_id) - 1) || '_' ||\n SUBSTRING(a.atom_id FROM POSITION('_' IN a.atom_id) + 1 FOR LENGTH(a.atom_id)) || '_' ||\n CAST(CAST(SUBSTRING(c.atom_id2 FROM POSITION('_' IN c.atom_id2) + 1 FOR LENGTH(c.atom_id2)) AS INTEGER) AS VARCHAR) AS derived_bond_id\n FROM atom AS a\n INNER JOIN connected AS c ON a.atom_id = c.atom_id\n WHERE a.element = 'c'\n),\nMoleculeStats AS (\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2958, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atombondmapping", + "bond", + "connected", + "molecule", + "moleculestats" + ], + "num_joins": 6, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_468", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM molecule WHERE NOT molecule_id IN ('TR000', 'TR001', 'TR002', NULL)", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "molecule" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_469", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH MonthlyRulings AS ( SELECT EXTRACT(YEAR FROM \"date\") AS ruling_year, EXTRACT(MONTH FROM \"date\") AS ruling_month, \"date\", \"text\", \"uuid\" FROM rulings), DailyRulingsWithRank AS ( SELECT ruling_year, ruling_month, TO_CHAR(DATE_TRUNC('month', \"date\"), 'YYYY-MM') AS month_format, \"date\", DENSE_RANK() OVER (PARTITION BY ruling_year, ruling_month ORDER BY \"date\" NULLS FIRST) AS date_rank, COUNT(*) OVER (PARTITION BY \"date\") AS rulings_per_day FROM monthlyrulings), DistinctDaysPerMonth AS ( SELECT ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2125, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "dailyrulingswithrank", + "distinctdayspermonth", + "monthlyrulings", + "rulings" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 3, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_470", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH SuperheroGenderCTE AS (SELECT s.id AS superhero_id, s.superhero_name, g.gender, ROW_NUMBER() OVER (PARTITION BY s.superhero_name ORDER BY g.id NULLS FIRST) AS rn FROM superhero AS s LEFT JOIN gender AS g ON CASE WHEN s.gender_id = g.id THEN 1 WHEN s.gender_id IS NULL AND g.id = 3 THEN 1 ELSE 0 END = 1) SELECT superhero_name, gender FROM superherogendercte WHERE rn = 1 ORDER BY superhero_id NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "gender", + "superhero", + "superherogendercte" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_471", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientExamHistory AS (SELECT p.id, p.sex, p.birthday, p.description, p.\"First Date\", p.admission, p.diagnosis AS PatientDiagnosis, e.\"Examination Date\", e.\"aCL IgG\", e.\"aCL IgM\", e.ana, e.\"ANA Pattern\", e.\"aCL IgA\", e.diagnosis AS ExamDiagnosis, e.kct, e.rvvt, e.lac, e.symptoms, e.thrombosis, ROW_NUMBER() OVER (PARTITION BY p.id ORDER BY e.\"Examination Date\" DESC NULLS LAST) AS ExamRank, COUNT(*) OVER (PARTITION BY p.id) AS ExamCount FROM patient AS p LEFT JOIN examination AS e ON e.id = p", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2385, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "latestlabresults", + "patient", + "patientexamhistory" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_472", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH LabResults AS (\n SELECT l.id, l.date, l.got, l.gpt, l.ldh, l.alp, l.tp, l.alb, l.ua, l.un, l.cre, l.\"T-BIL\", l.\"T-CHO\", l.tg, l.cpk, l.glu, l.wbc, l.rbc, l.hgb, l.hct, l.plt, l.pt, l.aptt, l.fg, l.\"U-PRO\", l.igg, l.iga, l.igm, l.crp, l.ra, l.rf, l.c3, l.c4, l.rnp, l.sm, l.sc170, l.ssa, l.ssb, l.centromea, l.dna, l.\"DNA-II\",\n ROW_NUMBER() OVER (PARTITION BY l.id ORDER BY l.date DESC NULLS LAST) AS LatestRank,\n CASE\n WHEN l.crp IS NULL THEN 0\n WHEN l.crp IN ('Positive',", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2365, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "latestlabwithrank", + "patient", + "patientdiagnosis" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_473", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH LabResults AS (\n SELECT l.id, l.date, l.got, l.gpt, l.ldh, l.alp, l.tp, l.alb, l.ua, l.un, l.cre, l.\"T-BIL\", l.\"T-CHO\", l.tg, l.cpk, l.glu, l.wbc, l.rbc, l.hgb, l.hct, l.plt, l.pt, l.aptt, l.fg, l.\"U-PRO\", l.igg, l.iga, l.igm, l.crp, l.ra, l.rf, l.c3, l.c4, l.rnp, l.sm, l.sc170, l.ssa, l.ssb, l.centromea, l.dna, l.\"DNA-II\",\n ROW_NUMBER() OVER (PARTITION BY l.id ORDER BY l.date DESC NULLS LAST) AS LatestRank,\n CASE\n WHEN l.crp IS NULL THEN 0\n WHEN l.crp IN ('Positive',", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2365, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "latestlabwithrank", + "patient", + "patientdiagnosis" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_474", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (SELECT r.raceId, r.year, r.name AS raceName, res.positionText, d.forename || ' ' || d.surname AS driverName, res.driverId, ROW_NUMBER() OVER (PARTITION BY r.raceId, res.positionText ORDER BY res.resultId NULLS FIRST) AS position_rank FROM results AS res INNER JOIN races AS r ON res.raceId = r.raceId INNER JOIN drivers AS d ON res.driverId = d.driverId WHERE CAST(res.positionText AS INT) <= 3) SELECT rr.raceId, MAX(rr.year) AS year, MAX(rr.raceName) AS raceName, MAX(CASE WHEN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_475", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH x AS (SELECT driverid, statusid, ROW_NUMBER() OVER (PARTITION BY driverid ORDER BY COUNT(*) DESC NULLS LAST) AS rn FROM results GROUP BY driverid, statusid) INSERT INTO results (resultid, raceid, driverid, constructorid, number, grid, position, positiontext, positionorder, points, laps, time, milliseconds, fastestlap, rank, fastestlaptime, fastestlapspeed, statusid) SELECT driverid, 1, driverid, 1, 1, 1, position, positiontext, positionorder, points, 1, '00:00:00', 0, 1, 1, '00:00:00', '000", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-WINDOW-ORDER-INSERT", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "INSERT", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "results", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_476", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DriverGroups AS (SELECT CASE WHEN nationality IS NULL THEN 'Unknown' ELSE nationality END AS driver_group, code FROM drivers WHERE NOT code IS NULL), GroupedCodes AS (SELECT driver_group, MIN(code) AS min_code, MAX(code) AS max_code, COUNT(DISTINCT code) AS distinct_code_count FROM drivergroups GROUP BY driver_group) SELECT driver_group, CASE WHEN distinct_code_count > 1 THEN MIN(min_code) || '-' || MAX(max_code) ELSE MAX(max_code) END AS concat_codes FROM groupedcodes GROUP BY driver", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "drivergroups", + "drivers", + "groupedcodes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_477", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH DriverGroups AS (SELECT CASE WHEN nationality IS NULL THEN 'Unknown' ELSE nationality END AS driver_group, code FROM drivers WHERE NOT code IS NULL), GroupedCodes AS (SELECT driver_group, MIN(code) AS min_code, MAX(code) AS max_code, COUNT(DISTINCT code) AS distinct_code_count FROM drivergroups GROUP BY driver_group) SELECT driver_group, CASE WHEN distinct_code_count > 1 THEN MIN(min_code) || '-' || MAX(max_code) ELSE MAX(max_code) END AS concat_codes FROM groupedcodes GROUP BY driver", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1219, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "drivergroups", + "drivers", + "groupedcodes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_478", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH TeamAverages AS (\n SELECT\n AVG(CAST(buildupplayspeed AS DECIMAL(10, 2))) AS AvgBuildupplaySpeed,\n AVG(CAST(defenceteamwidth AS DECIMAL(10, 2))) AS AvgDefenceTeamWidth\n FROM team_attributes\n WHERE buildupplayspeed IS NOT NULL AND defenceteamwidth IS NOT NULL\n),\nFilteredTeams AS (\n SELECT\n TA.id,\n TA.buildupplayspeed,\n TA.buildupplaypassing,\n TA.chancecreationpassing,\n TA.chancecreationcrossing,\n TA.chancecreationshooting,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "filteredteams", + "team_attributes", + "teamaverages" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_479", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH TeamAverages AS (\n SELECT\n AVG(CAST(buildupplayspeed AS DECIMAL(10, 2))) AS AvgBuildupplaySpeed,\n AVG(CAST(defenceteamwidth AS DECIMAL(10, 2))) AS AvgDefenceTeamWidth\n FROM team_attributes\n WHERE buildupplayspeed IS NOT NULL AND defenceteamwidth IS NOT NULL\n),\nFilteredTeams AS (\n SELECT\n TA.id,\n TA.buildupplayspeed,\n TA.buildupplaypassing,\n TA.chancecreationpassing,\n TA.chancecreationcrossing,\n TA.chancecreationshooting,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.151, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "filteredteams", + "team_attributes", + "teamaverages" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_480", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientTestDates AS (SELECT p.ID, p.SEX, p.Diagnosis, l.Date, ROW_NUMBER() OVER (PARTITION BY p.ID ORDER BY l.Date NULLS FIRST) AS RowNum FROM patient AS p LEFT JOIN laboratory AS l ON p.ID = l.ID WHERE l.Date >= p.\"First Date\" OR p.\"First Date\" IS NULL), ExaminationDates AS (SELECT p.ID, MIN(e.\"Examination Date\") AS earliest_exam_date FROM patient AS p LEFT JOIN examination AS e ON p.ID = e.ID GROUP BY p.ID) SELECT ptd.ID, ptd.SEX, ptd.Diagnosis, CASE WHEN ptd.Date < ed.earliest_exam_date ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "examinationdates", + "laboratory", + "patient", + "patienttestdates" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_481", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH x AS (SELECT FLOOR(COALESCE(LENGTH(CAST(label AS TEXT)), 0) / 100) AS labellength FROM molecule) SELECT labellength * 100 AS labellengthstart, (labellength + 1) * 100 - 1 AS labellengthend, COUNT(*) AS moleculecount FROM x ORDER BY labellength NULLS FIRST", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0729, + "pattern_signature": "WITH-CTE-SELECT-FROM-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "molecule", + "x" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_482", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM (SELECT id, name, ROW_NUMBER() OVER (PARTITION BY id ORDER BY label NULLS FIRST) AS item, CONCAT(label, ' (', tag1, ')') AS value FROM (SELECT id, name, 'Colors' AS label, colors AS tag1 FROM cards UNION ALL SELECT id, name, 'ManaCost' AS label, manacost AS tag1 FROM cards) AS src) AS src WHERE id = '1'", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_483", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientThrombosisHistory AS (SELECT e.ID, e.Thrombosis, ROW_NUMBER() OVER (PARTITION BY e.ID ORDER BY e.\"Examination Date\" DESC NULLS LAST) AS RecencyRank, COUNT(*) OVER (PARTITION BY e.ID) AS ExamCount FROM examination AS e WHERE NOT e.Thrombosis IS NULL), LabResults AS (SELECT l.ID, AVG(l.PLT) AS AvgPlateletCount, MAX(CASE WHEN l.PLT < 150 THEN 1 ELSE 0 END) AS HasLowPlatelets FROM laboratory AS l WHERE l.Date >= CURRENT_TIMESTAMP + INTERVAL '-1 YEAR' GROUP BY l.ID) SELECT p.ID AS Patient", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'ID' is ambiguous \u2014 exists in tables: patient, examination", + "taxonomy_category": "semantic", + "context": "ID", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2448, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "patient", + "patientthrombosishistory" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_484", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TEAMATTRS AS (SELECT BUILDUPPLAYSPEED AS VALUE, 'Team_Attributes' AS IDENTIFIER, ROW_NUMBER() OVER (ORDER BY BUILDUPPLAYSPEED NULLS FIRST) AS RN FROM team_attributes) SELECT PLAYERATTRS.VALUE, PLAYERATTRS.IDENTIFIER, TEAMATTRS.VALUE, TEAMATTRS.IDENTIFIER FROM (SELECT OVERALL_RATING AS VALUE, 'Player_Attributes' AS IDENTIFIER, ROW_NUMBER() OVER (ORDER BY OVERALL_RATING NULLS FIRST) AS RN FROM player_attributes) AS PLAYERATTRS FULL OUTER JOIN teamattrs ON PLAYERATTRS.RN = TEAMATTRS.RN WHERE P", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1438, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "player_attributes", + "team_attributes", + "teamattrs" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_485", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"date\", home_team_api_id AS group_1, away_team_api_id AS group_2, home_team_goal AS daily_profits, SUM(home_team_goal) OVER (PARTITION BY CAST(\"date\" AS INT), home_team_api_id, away_team_api_id ORDER BY \"date\" NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS mtd, SUM(home_team_goal) OVER (PARTITION BY TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'YYYY'), TO_CHAR(CAST(\"date\" AS TIMESTAMP), 'quarter'), home_team_api_id, away_team_api_id ORDER BY \"date\" NULLS FIRST ROWS BETWEEN UNBOUND", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0354, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_486", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH CardLegalities AS (\n SELECT c.name AS card_name, l.format, l.status, l.id,\n DENSE_RANK() OVER (PARTITION BY c.uuid, l.format ORDER BY CASE WHEN l.status = 'Legal' THEN 0 ELSE 1 END NULLS FIRST) AS status_priority\n FROM cards AS c\n LEFT JOIN legalities AS l ON c.uuid = l.uuid\n WHERE l.format IN ('commander', 'duel', 'legacy')\n),\nLegalityStats AS (\n SELECT card_name, format,\n MAX(CASE WHEN status = 'Legal' THEN id END) AS legal_id,\n MAX(CASE WHEN status = 'Banned' THEN", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1938, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cardlegalities", + "cards", + "legalities", + "legalitystats" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_487", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH a AS (SELECT id, date AS applicationid, ROW_NUMBER() OVER (PARTITION BY id ORDER BY date NULLS FIRST) AS rn, LAG(date) OVER (PARTITION BY id ORDER BY date NULLS FIRST) AS prev FROM laboratory) SELECT id AS usercode, prev AS data_1, rn AS id_2, applicationid AS data_2, rn - 1 AS id_1 FROM a WHERE NOT prev IS NULL AND id = 27654", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "a", + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_488", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT RACEID, NAME, \"date\", LAG(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS PREVRACEID, LEAD(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS NEXTRACEID FROM races ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_existent_column\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'non_existent_column' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "non_existent_column", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_489", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH pages AS (SELECT 1 AS page_id, 1 AS power_id UNION ALL SELECT 1, 7 UNION ALL SELECT 2, 1 UNION ALL SELECT 3, 1 UNION ALL SELECT 3, 7 UNION ALL SELECT 3, 89 UNION ALL SELECT 4, 20 UNION ALL SELECT 5, 55 UNION ALL SELECT 5, 1 UNION ALL SELECT 6, 1 UNION ALL SELECT 6, 13), items AS (SELECT 10 AS hero_id, 1 AS power_id UNION ALL SELECT 10, 7 UNION ALL SELECT 10, 20 UNION ALL SELECT 12, 1 UNION ALL SELECT 12, 55) SELECT p.page_id, i.hero_id FROM (SELECT p.page_id, p.power_id, COUNT(*) OVER (PART", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1458, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-HAVING-WINDOW-UNION-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "items", + "pages" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_490", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH data AS (SELECT p.id, p.\"First Date\" AS as_of_date, p.diagnosis AS current_diagnosis, LAG(p.diagnosis) OVER (PARTITION BY p.id ORDER BY p.\"First Date\" NULLS FIRST) AS prev_diagnosis, CASE WHEN p.diagnosis IN ('RA susp.', 'PSS', 'SLE') THEN 1 ELSE 0 END AS output_flag FROM patient AS p) SELECT as_of_date, id, current_diagnosis, prev_diagnosis, CASE WHEN output_flag = 1 THEN MIN(as_of_date) OVER (PARTITION BY id, output_flag ORDER BY as_of_date NULLS FIRST) END AS desired_output FROM data WHE", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "data", + "patient" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_491", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH ATOMRNS AS (SELECT MOLECULE_ID, ELEMENT, ROW_NUMBER() OVER (PARTITION BY MOLECULE_ID ORDER BY ATOM_ID NULLS FIRST) AS RN FROM atom) SELECT MOLECULE_ID, MAX(CASE WHEN RN = 1 THEN ELEMENT END) AS ELEMENT1, MAX(CASE WHEN RN = 2 THEN ELEMENT END) AS ELEMENT2, MAX(CASE WHEN RN = 3 THEN ELEMENT END) AS ELEMENT3 FROM atomrns JOIN atom ON ATOMRNS.MOLECULE_ID = ATOM.MOLECULE_ID GROUP BY MOLECULE_ID", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1115, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atomrns" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_492", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH SUPERHEROLIST AS (SELECT ID, SUPERHERO_NAME, FULL_NAME, ROW_NUMBER() OVER (PARTITION BY PUBLISHER_ID ORDER BY ID NULLS FIRST) AS PUBLISHER_RANK, DENSE_RANK() OVER (ORDER BY ALIGNMENT_ID NULLS FIRST, ID NULLS FIRST) AS GLOBAL_RANK FROM superhero WHERE NOT HEIGHT_CM IS NULL), SUPERHERO_POWERS AS (SELECT S.ID, S.SUPERHERO_NAME, COUNT(HP.POWER_ID) AS POWER_COUNT, STRING_AGG(SP.POWER_NAME, ', ' ORDER BY SP.POWER_NAME NULLS FIRST) AS POWERS FROM superhero AS S LEFT JOIN hero_power AS HP ON S.ID =", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2719, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "hero_power", + "superhero", + "superhero_powers", + "superherolist", + "superpower" + ], + "num_joins": 5, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_493", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT num FROM (SELECT number AS num, ROW_NUMBER() OVER (ORDER BY id NULLS FIRST) - ROW_NUMBER() OVER (PARTITION BY CAST(number AS INT) ORDER BY id NULLS FIRST) AS grp FROM cards) AS a GROUP BY grp, num HAVING COUNT(*) >= 3", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "cards" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_494", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH BondTypeRanking AS (SELECT bond_id, molecule_id, bond_type, CASE WHEN bond_type = '-' THEN 1 WHEN bond_type = '=' THEN 2 WHEN bond_type = '#' THEN 3 ELSE CAST(bond_type AS INT) END AS bond_type_rank FROM bond), MoleculeWithMultipleBondTypes AS (SELECT molecule_id FROM bond GROUP BY molecule_id HAVING COUNT(DISTINCT CASE WHEN bond_type = '-' THEN 'single' WHEN bond_type = '=' THEN 'double' WHEN bond_type = '#' THEN 'triple' ELSE bond_type END) > 1) SELECT b.molecule_id, b.bond_type FROM (S", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "bond", + "bondtyperanking", + "moleculewithmultiplebondtypes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_495", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH SchoolScores AS (\n SELECT\n s.school,\n sa.avgscrread,\n sa.avgscrmath,\n sa.avgscrwrite,\n DENSE_RANK() OVER (PARTITION BY sa.rtype ORDER BY sa.avgscrread DESC) AS ReadingRank\n FROM\n schools AS s\n INNER JOIN\n satscores AS sa ON s.cdscode = sa.cds\n WHERE\n s.county = 'Alameda'\n AND sa.rtype = 'S'\n),\nMaxReadingScore AS (\n SELECT MAX(avgscrread) AS MaxRead\n FROM satscores\n WHERE rtype = 'S'\n)\nSELECT\n ss.school,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1948, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-JOIN_CROSS-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_CROSS", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "maxreadingscore", + "satscores", + "schools", + "schoolscores" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_497", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n xml_result xml;\nBEGIN\n -- First attempt to build the XML structure with nested XML queries\n WITH SchemaInfo AS (\n SELECT\n COLUMN_NAME,\n DATA_TYPE,\n ORDINAL_POSITION\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'schools' AND TABLE_SCHEMA = current_schema()\n ),\n SATData AS (\n SELECT\n cds,\n rtype,\n ROW_NUMBER() OVER(PARTITION BY cds ORDER BY NumTstTakr DESC) AS RowRank", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_498", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CustomerID, Consumption, MIN(Date) AS MinDate, MAX(Date) AS MaxDate\nFROM yearmonth WHERE Consumption = 0 GROUP BY CustomerID, Consumption;\n\nUPDATE yearmonth TGT SET DenseRankTest = SRC.NewRank\nFROM (SELECT Row_ID, DENSE_RANK() OVER (PARTITION BY CustomerID ORDER BY Consumption ASC) AS NewRank\n FROM yearmonth) AS SRC\nWHERE SRC.Row_ID = TGT.Row_ID;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0302, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "yearmonth" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_499", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n c.customerid,\n (\n SELECT\n CAST(t.transactionid AS TEXT) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n FOR JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.customerid\nWHERE segment = 'SME'\nFOR JSON PATH, WITHOUT_ARRAY_WRAPPER;", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c\n\nInvalid expression / Unexpected token. Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_500", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT r.name,\nCOALESCE(STRING_AGG(tmp.name, ', '), '')\nFROM races r\nLEFT JOIN\n(\n SELECT c.name, cr.raceid FROM constructors c\n JOIN constructorresults cr ON c.constructorid = cr.constructorid\n) tmp ON tmp.raceid = r.raceid\nGROUP BY r.name", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1688, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "constructorresults", + "constructors", + "races" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_501", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ROW_NUMBER() OVER () AS rownum, id_column, decimal_column, nvarchar_column\nFROM json_table(\n '[\n {\"id_column\": 1234, \"decimal_column\": 12.34, \"nvarchar_column\": \"asdf\"},\n {\"id_column\": 5678, \"decimal_column\": 56.78, \"nvarchar_column\": \"fdsa\"}\n ]',\n '$[*]' COLUMNS (\n id_column BIGINT PATH '$.id_column',\n decimal_column DECIMAL(28,8) PATH '$.decimal_column',\n nvarchar_column VARCHAR(30) PATH '$.nvarchar_column'\n )\n) AS data", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM-WINDOW", + "clauses_present": [ + "FROM", + "SELECT", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_502", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, value FROM races CROSS JOIN LATERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GROUPING(name) as name FOR value in ('name1','name2','name3','name4')) piv;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_503", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n v_id bigint;\n v_date date;\n db_update_cursor CURSOR FOR\n SELECT id, date\n FROM laboratory\n ORDER BY id, date\n LIMIT 2;\nBEGIN\n OPEN db_update_cursor;\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n WHILE FOUND LOOP\n INSERT INTO destinationTable(testRow)\n VALUES ((SELECT v_id, v_date FOR JSON AUTO));\n\n FETCH NEXT FROM db_update_cursor INTO v_id, v_date;\n END LOOP;\n\n CLOSE db_update_cursor;\nEND $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_504", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "WITH hero_activity AS\n (SELECT id,\n activity_date,\n activity_value,\n hero_id\n FROM (\n VALUES (1,\n '2023-01-01',\n 10,\n 1), (2,\n '2023-01-02',\n 20,\n 1), (3,\n '2023-02-01',\n 15,\n 1), (4,\n '2023-02-02',\n 25,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1052, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-VALUES", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "VALUES", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "activity_totals", + "hero_activity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_505", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (\n\n SELECT\n r.raceId,\n r.year,\n r.date,\n res.driverId,\n res.points,\n\n DENSE_RANK() OVER (PARTITION BY res.driverId, r.year ORDER BY r.date) AS SeasonRaceNumber,\n\n ROW_NUMBER() OVER (PARTITION BY res.driverId ORDER BY r.year, r.date) AS CareerRaceNumber\n FROM results res\n JOIN races r ON res.raceId = r.raceId\n WHERE res.position IS NOT NULL\n),\nDriverFirstFiveRaces AS (\n\n SELECT\n driverId,\n year,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2021, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "driverfirstfiveraces", + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_506", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH cte AS\n (SELECT id,\n \"Examination Date\",\n thrombosis,\n risklag = LAG(thrombosis, 1, thrombosis) OVER (PARTITION BY id\n ORDER BY \"Examination Date\"),\n rn = ROW_NUMBER() OVER (PARTITION BY id,\n EXTRACT(YEAR FROM \"Examination Date\"),\n EXTRACT(MONTH FROM \"Examination Date\")\n ORDER", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0906, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_507", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH MoleculeList AS (\n SELECT unnest(string_to_array('TR000,TR001,TR002', ',')) AS molecule_id\n),\nMoleculeStats AS (\n SELECT\n m.molecule_id,\n m.label,\n COUNT(a.atom_id) AS atom_count,\n COUNT(DISTINCT b.bond_type) AS unique_bond_types,\n DENSE_RANK() OVER (ORDER BY COUNT(a.atom_id) DESC) AS size_rank\n FROM molecule m\n LEFT JOIN atom a ON m.molecule_id = a.molecule_id\n LEFT JOIN bond b ON m.molecule_id = b.molecule_id\n GROUP BY m.molecule_id, m.", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2917, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "molecule", + "moleculelist", + "moleculestats" + ], + "num_joins": 3, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_508", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH KEYWORDMATCHES AS\n (SELECT P.ID,\n CASE\n WHEN POSITION(LOWER('Aaron') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Aaron'\n END AS COLAKEYWORD,\n CASE\n WHEN POSITION(LOWER('Cresswell') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Cresswell'\n END AS COLBKEYWORD,\n CASE\n WHEN POSITION(LOWER('Doran') IN LOWER(P.PLAYER_NAME)) > 0 THEN 'Doran'\n END AS COLCKEYWORD\n FROM PLAYER AS P),\n KEYWORDSCORES AS\n (SELECT ID,\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1625, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-FILTER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FILTER", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "keywordmatches", + "keywordscores", + "player" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_509", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "WITH ChangeHistory AS (\n\n SELECT\n s.cdscode,\n s.school,\n s.fundingtype,\n s.lastupdate,\n\n DENSE_RANK() OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) AS ChangeSequence,\n\n CASE WHEN LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) IS NULL\n OR LAG(s.school) OVER (PARTITION BY s.cdscode ORDER BY s.lastupdate) <> s.school\n THEN 1 ELSE 0 END AS SchoolChanged,\n CASE WHEN LAG(s.fundingtype) OVER (PARTITION ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.3083, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "changehistory", + "changesonly", + "schools" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 9 + } + }, + { + "instance_id": "PostgreSQL_510", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' || pa.player_api_id::text || ','\n LIKE '%,' || p.player_api_id::text || ',%'\n)\nSELECT\n id,\n name,\n player_api_id = xpath('text()', col)::VARCHAR(100)\nFROM CTE\nCROSS JOIN LATERAL XMLTABLE('/t' PASSING xml_val COLUMNS col XML PATH '.') AS CA\nLI", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\nExpecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\ndpipe does not support CTE. Line 5, Col: 101.\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''\u001b[4m)\u001b[0m,\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' |\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "WITH-CTE-SELECT", + "clauses_present": [ + "CTE", + "SELECT", + "WITH" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_511", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH t AS\n (SELECT e.*,\n ROW_NUMBER() OVER (PARTITION BY e.id\n ORDER BY e.\"Examination Date\") AS seqnum\n FROM examination AS e),\n cte AS\n (SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n 'N' AS isrehire,\n t.\"Examination Date\" AS anchordate\n FROM t\n WHERE t.seqnum = 1\n UNION ALL SELECT t.id,\n t.\"Examination Date\" AS startdate,\n t.seqnum,\n CAS", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1104, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "examination", + "t" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_512", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE T_period_futur AS\n (SELECT 1 AS Tpf_period_id,\n CAST('2021-10-25' AS DATE) AS Tpf_start_period\n UNION ALL SELECT Tpf_period_id + 1 AS Tpf_period_id,\n Tpf_start_period + INTERVAL '1 week'\n FROM T_period_futur\n WHERE Tpf_period_id < 12 )\nSELECT Tpf_period_id,\n Tpf_start_period,\n EXTRACT(YEAR FROM Tpf_start_period) AS Tpf_year,\n CAST(EXTRACT(YEAR FROM Tpf_start_period) AS VARCHAR) || '.' || RIGHT('00' || CAST(EXTRACT(WEEK FROM Tpf_", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0635, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "t_period_futur" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_515", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 1) as value1, SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 2) as value2, SPLIT_PART(CAST(amount AS TEXT) || ',' || CAST(balance AS TEXT) || ',' || CAST(account AS TEXT), ',', 3) as value3 FROM trans WHERE trans_id = 1", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "trans" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_516", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ID, value FROM PATIENT CROSS JOIN LATERAL string_to_table(DIAGNOSIS, ',') AS s(value) WHERE DIAGNOSIS = 'SLE' || '; DROP TABLE PATIENT; --';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_517", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH data1 AS ( SELECT originalreleasedate, (date_trunc('week', to_date(originalreleasedate, 'YYYY-MM-DD') + interval '1 day') - interval '1 day')::date AS start_of_week_mon, floor((to_date(originalreleasedate, 'YYYY-MM-DD') - DATE '2007-01-01') / 7)::int + 1 AS week_number FROM cards WHERE originalreleasedate IS NOT NULL AND to_date(originalreleasedate, 'YYYY-MM-DD') >= DATE '2007-01-01' ), weekly_data AS ( SELECT start_of_week_mon, week_number FROM data1 ) SELECT start_of_week_mon AS actual_st", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.101, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "cards", + "data1", + "weekly_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_518", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"first_name\" || ' ' || e.\"last_name\" AS email_full_name, e.email, p.position FROM member_email AS e INNER JOIN member_position AS p ON email_full_name = p.full_name", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0469, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "member_email", + "member_position" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_519", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(motherGroups.Mothers) AS UniqueMotherGroups FROM\n(SELECT STRING_AGG(CAST(c.id AS VARCHAR), '') WITHIN GROUP (ORDER BY c.id) AS Mothers FROM laboratory c GROUP BY c.id) AS motherGroups", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1021, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "laboratory" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_520", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n StartDate timestamp;\n EndDate timestamp;\nBEGIN\n StartDate := '2010-02-22 00:00:00';\n EndDate := '2010-02-22 23:59:59';\n\n SELECT *\n FROM team_attributes\n WHERE date BETWEEN StartDate AND EndDate;\nEND $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_521", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH PaymentRanks AS (SELECT payments, ROW_NUMBER() OVER (ORDER BY payments DESC NULLS LAST) AS row_num, DENSE_RANK() OVER (ORDER BY payments DESC NULLS LAST) AS dense_rank_num, COUNT(*) OVER () AS total_count FROM loan), DistinctPayments AS (SELECT COUNT( payments) AS distinct_payment_count FROM loan) SELECT CASE WHEN (SELECT COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM payme", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'expression' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nRequired keyword: 'true' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nExpected END after CASE. Line 1, Col: 430.\n T COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 \u001b[4mAND\u001b[0m WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END\n\n... and 1 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distinctpayments", + "loan" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_523", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 'budget_seq' FROM budget LIMIT 10", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-LIMIT", + "clauses_present": [ + "FROM", + "LIMIT", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_524", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n spell_starts AS (\n SELECT start_date, end_date\n FROM blackout_periods s1\n WHERE NOT EXISTS (\n SELECT 1\n FROM blackout_periods s2\n WHERE s2.start_date < s1.start_date\n AND s1.start_date <= s2.end_date\n )\n ),\n spell_ends AS (\n SELECT start_date, end_date\n FROM blackout_periods t1\n WHERE NOT EXISTS (\n SELECT 1\n ", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1594, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE", + "WITH" + ], + "tables": [ + "blackout_periods", + "spell_ends", + "spell_starts" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_525", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "DO $$\nDECLARE\n batch INT := 10000;\nBEGIN\n WHILE batch > 0 LOOP\n BEGIN\n START TRANSACTION;\n INSERT INTO player_stats\n SELECT * FROM player_stats_temp\n LIMIT batch;\n GET DIAGNOSTICS batch = ROW_COUNT;\n COMMIT;\n END;\n END LOOP;\nEND $$;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_526", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DriverId, MIN(StartDate) AS StartDate, MAX(EndDate) AS EndDate\nFROM (SELECT *,\nSUM(CASE WHEN a.EndDate = a.StartDate THEN 0 ELSE 1 END) OVER (ORDER BY DriverId, StartDate) sm\nFROM (SELECT DriverId, StartDate, EndDate,\nLAG(EndDate, 1, NULL) OVER (PARTITION BY DriverId ORDER BY DriverId, EndDate) prev_EndDate\nFROM driverContracts) a\n) b\nGROUP BY DriverId, sm;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1938, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "SUBQUERY", + "WINDOW" + ], + "tables": [ + "drivercontracts" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_527", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE ExpCTE AS (\nSELECT\nDENSE_RANK() OVER (ORDER BY exp_id) AS ExpRN\n, exp_id\n, mid\n, qty\nFROM\nExperiment WHERE mid = 2\n)\n, CTE AS\n(\nSELECT\ne.exp_id\n, e.mid\n, e.qty\n, i.qty - e.qty AS QtyAvailable\n, e.ExpRN\nFROM\nExpCTE e\nINNER JOIN\nInventory i ON i.mid = e.mid\nWHERE\ne.exp_id IN (SELECT e_sub.exp_id\nFROM Experiment e_sub\nWHERE NOT EXISTS (SELECT 1 FROM Inventory i_sub\nWHERE i_sub.mid = e_sub.mid AND i_sub.qty < e_sub.qty)\nORDER BY e_sub.exp_id\nLIMIT 1)\nAND e.mid = 2\nUNION ALL\nSELECT\ne.e", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.2927, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-WINDOW-UNION-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "expcte", + "experiment", + "inventory" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_528", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE vt as (\nselect t.*, row_number() over (partition by CustomerID order by StartDate) as seqnum\nfrom transactions_1k t\n),\ncte as (\nselect vt.TransactionID, vt.CustomerID, vt.StartDate, vt.EndDate, vt.StartDate as first_begin_date, seqnum\nfrom vt\nwhere seqnum = 1\nunion all\nselect vt.TransactionID, vt.CustomerID, vt.StartDate, vt.EndDate,\n(case when vt.StartDate > (cte.EndDate + interval '90 days') then vt.StartDate else cte.EndDate end),\nvt.seqnum\nfrom cte join\nvt\non vt.seqnum = cte.s", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1208, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "cte", + "transactions_1k", + "vt" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_529", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH RECURSIVE cte AS (\nSELECT ID, ParentID\nFROM LaboratoryLink\nWHERE ID IN (657266, 115562)\nUNION ALL\nSELECT t.ID, t.ParentID\nFROM LaboratoryLink t\nJOIN cte c ON t.ID = c.ParentID\nWHERE t.ParentID IS NOT NULL\n)\nSELECT *\nFROM cte;", + "valid": true, + "errors": [], + "tags": [], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "cte", + "laboratorylink" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + } + ] +} \ No newline at end of file diff --git a/tests/output/validator_benchmark_results_errors_only.json b/tests/output/validator_benchmark_results_errors_only.json new file mode 100644 index 0000000..7bef498 --- /dev/null +++ b/tests/output/validator_benchmark_results_errors_only.json @@ -0,0 +1,4595 @@ +[ + { + "instance_id": "PostgreSQL_10", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE account\n SET date__timestamp = date__bigint::timestamp;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'date__timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__timestamp" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date__bigint' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date__bigint" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "account" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_16", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT to_char(generate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') FROM loan;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 123.\n rate_series, 'YYYY') FROM generate_series(MIN(date)::timestamptz, MAX(date)::timestamptz, '1 year') \u001b[4mFROM\u001b[0m loan;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0125, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_24", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\\n a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) as referencing_table,\\n UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as referencing_col,\\n pg_get_constraintdef(c.oid) contraint_sql FROM pg_constraint c join pg_attribute a on c.confrelid=a.attrelid and a.attnum = ANY(confkey)\\n WHERE c.", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 83.\n SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,\u001b[4m\\\u001b[0mn a.attname as base_col,\\n (select r.relname from pg_class r where r.oid = c.conrelid) a", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "pg_class" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_26", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT team_api_id, team_short_name FROM Team as data FULL OUTER JOIN (SELECT buildUpPlaySpeed, team_api_id FROM Team_Attributes ta WHERE team_api_id = data.team_api_id) AS subquery_alias ON data.team_api_id = subquery_alias.team_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'team_api_id' is ambiguous \u2014 exists in tables: team, team_attributes", + "taxonomy_category": "semantic", + "context": "team_api_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "team", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_27", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH one AS ( SELECT date_trunc('year', date) as timeOne, COUNT(*) as trans_count FROM trans ORDER BY timeOne ), two AS ( SELECT date_trunc('year', date) as timeTwo, COUNT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count) as count FROM one, two ORDER BY 1;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "The number of provided arguments (2) is greater than the maximum number of supported arguments (1). Line 1, Col: 270.\n NT(*) as loan_count FROM loan ORDER BY timeTwo ) SELECT timeOne as year, SUM(trans_count, loan_count\u001b[4m)\u001b[0m as count FROM one, two ORDER BY 1;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "loan", + "one", + "trans", + "two" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_32", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH tab_with_cardid AS (\n select split(cardid, '-', 3)ivm_arr,\n\n type,\n last_refresh_date\n FROM db.scema.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 71.\n ma.table\n), ranked_visits AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) \u001b[4mas\u001b[0m temp ORDER BY type) AS rn\n FROM tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\n\n\nRequired keyword: 'this' missing for . Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\nalias does not support CTE. Line 9, Col: 8.\n SELECT *, ROW_NUMBER() OVER(PARTITION BY CONCAT(ivm_arr[2],item) as temp ORDER BY type) AS rn\n \u001b[4mFROM\u001b[0m tab_with_cardid\n)\nSELECT cardid, pure_cardid\nFROM ranked_visits\nWHERE rn = 1\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'table' does not exist in schema", + "taxonomy_category": "semantic", + "context": "table", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0563, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "WINDOW", + "WITH" + ], + "tables": [ + "table" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_35", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "begin insert into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.WebsiteUrl, '.', '-'), charindex('@', replace(new.WebsiteUrl, '.', '-')) - 1);return new;end;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 12.\n begin \u001b[4minsert\u001b[0m into profiles (Id, CreationDate, WebsiteUrl) select new.Id, new.CreationDate, left(replace(new.Webs", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_37", + "db_id": "student_club", + "category": "Management", + "sql_index": 0, + "sql": "insert into event (event_id, event_name, event_date, type, notes, location, status) values ('recAlAwtBZ0Fqbr5K', 'Annual Gala', '2023-12-15T19:00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Unknown option DO. Line 1, Col: 251.\n :00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) do \u001b[4minsert\u001b[0m into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');\n\nInvalid expression / Unexpected token. Line 1, Col: 244.\n :00:00', 'Social', 'Annual Gala for club members', 'Grand Ballroom', 'Open') on conflict (event_id) \u001b[4mdo\u001b[0m insert into failure (event, member) values ('recAlAwtBZ0Fqbr5K', 'rec280Sk7o31iG0Tx');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_39", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT userid, tag\nFROM preference_tag\nWHERE tag @> (ARRAY['friend', 'cat']::VARCHAR[]);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'tag' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "tag", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'tag' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "tag", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-DISTINCT-FROM-WHERE", + "clauses_present": [ + "DISTINCT", + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "preference_tag" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_54", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "SELECT client.client_id, client.gender, disp.disp_id, address ->> 'PostCode' AS PostCode FROM client JOIN disp ON client.client_id = disp.client_id CROSS JOIN jsonb_array_elements(disp.addresses) AS address WHERE disp.client_id IN (100, 414);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'address' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "address", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'addresses' does not exist in table 'disp' (referenced as 'disp.addresses')", + "taxonomy_category": "semantic", + "context": "disp.addresses", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0802, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "SELECT", + "WHERE" + ], + "tables": [ + "client", + "disp" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_62", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT c1.user_id, COUNT(*) FROM user_actions c1 LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'LOGIN') c2 ON c1.user_id = c2.user_id AND c2.action_time > c1.action_time LEFT JOIN (SELECT user_id, action, action_time FROM user_actions WHERE action = 'BUY') c3 ON c1.user_id = c3.user_id AND c3.action_time > c1.action_time AND c3.action_time < c2.action_time WHERE c1.action = 'SEARCH' AND c2.user_id IS NOT NULL AND c3.user_id IS NULL GROUP BY 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action_time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action_time", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action_time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action_time", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'action' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "action", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2552, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "user_actions" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_63", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT c.id, c.name FROM cards c WHERE c.id IN (SELECT unnest(card_order) FROM decks WHERE id = 1);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'card_order' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "card_order", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'id' is ambiguous \u2014 exists in tables: cards, decks", + "taxonomy_category": "semantic", + "context": "id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1146, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "decks" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_70", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n link_to_member,\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN CEIL(SUM(hours) / 10) * 10\n ELSE FLOOR(SUM(hours) / 10) * 10\n END AS rounded_hours,\n RANK() OVER (ORDER BY\n CASE\n WHEN (SUBSTRING(ROUND(SUM(hours)::NUMERIC, 0)::TEXT FROM '.{1}$') IN ('5', '6', '7', '8', '9', '0'))\n THEN", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'hours' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "hours", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-GROUP-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 7 + } + }, + { + "instance_id": "PostgreSQL_73", + "db_id": "codebase_community", + "category": "Personalization", + "sql_index": 0, + "sql": "select posttypeid\n case when tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from posts", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 17.\n select posttypeid\n case \u001b[4mwhen\u001b[0m tags like ('%bayesian%','%distributions%')\n then 1 else 0 end as keyword_count\n from ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_74", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id last_update DESC;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 98.\n SELECT count(bond_id), molecule_id FROM bond GROUP BY molecule_id ORDER BY molecule_id \u001b[4mlast_update\u001b[0m DESC;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT" + ], + "tables": [ + "bond" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_93", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT set_translations.language\n CASE WHEN set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'common'\n ELSE 'not common'\n END\n FROM set_translations", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 23.\n SELECT set_translations.language\n CASE \u001b[4mWHEN\u001b[0m set_translations.language IN (SELECT foreign_data.language in foreign_data)\n THEN 'com", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_101", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT DISTINCT ON (\"County Code\") * FROM frpm ORDER BY \"County Code\", \"Enrollment (K-12)\" DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'County Code' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "County Code", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'County Code' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "County Code", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Enrollment (K-12)' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Enrollment (K-12)", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-DISTINCT-DISTINCT_ON-FROM-ORDER", + "clauses_present": [ + "DISTINCT", + "DISTINCT_ON", + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_103", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO historical_rating (player_fifa_api_id, player_api_id, grouped_rating) SELECT player_fifa_api_id, player_api_id AS grouped_rating FROM player_attributes GROUP BY player_fifa_api_id, player_api_id;", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_fifa_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_fifa_api_id", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'player_api_id' is ambiguous \u2014 exists in tables: player_attributes, historical_rating", + "taxonomy_category": "semantic", + "context": "player_api_id", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0208, + "pattern_signature": "SELECT-FROM-GROUP-INSERT", + "clauses_present": [ + "FROM", + "GROUP", + "INSERT", + "SELECT" + ], + "tables": [ + "historical_rating", + "player_attributes" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_105", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH card_activity AS ( SELECT to_date(fe.start_date_key::text, 'YYYYMMDD') AS start_date, to_date(fe.end_date_key::text, 'YYYYMMDD') AS end_date, dp.set_name, dp.set_code FROM fact_collection fe INNER JOIN dim_set dp ON fe.set_key = dp.set_key ) SELECT date_trunc('month', month_series) AS month, COUNT(*) AS existing_cards, sa.set_name FROM ( SELECT generate_series( (SELECT MIN(to_date(start_date_key::text, 'YYYYMMDD')) FROM fact_collection), '2100-12-31', INTERVAL '1 month') AS month_series ) A", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date_key' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date_key", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.275, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-GROUP-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT", + "SUBQUERY", + "WITH" + ], + "tables": [ + "card_activity", + "dim_set", + "fact_collection" + ], + "num_joins": 2, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_110", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.league_id) SELECT * FROM recuree", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting (. Line 1, Col: 108.\n ITH TAB AS (SELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE \u001b[4mrecuree\u001b[0m AS ( SELECT league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON \n\nRequired keyword: 'expressions' missing for . Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\nExpecting ). Line 1, Col: 120.\n ELECT id as league_id, name FROM League UNION SELECT id, name FROM League) , RECURSIVE recuree AS ( \u001b[4mSELECT\u001b[0m league_id, name FROM TAB UNION SELECT E.league_id, E.name FROM TAB E JOIN recuree S ON E.id = S.lea\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'recuree' does not exist in schema", + "taxonomy_category": "semantic", + "context": "recuree", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-UNION", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "SELECT", + "UNION", + "WITH" + ], + "tables": [ + "league", + "recuree", + "tab" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_111", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "SELECT *\nFROM superhero.\"%_id\";", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table '%_id' does not exist in schema", + "taxonomy_category": "semantic", + "context": "%_id", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "%_id" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_114", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM Examination AS e LEFT JOIN LATERAL (SELECT * FROM Laboratory WHERE ID = e.ID ORDER BY Date DESC LIMIT 2) AS lab ON true", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'ID' is ambiguous \u2014 exists in tables: laboratory, examination", + "taxonomy_category": "semantic", + "context": "ID", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1333, + "pattern_signature": "SELECT-FROM-JOIN-LATERAL-WHERE-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "LATERAL", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "examination", + "laboratory" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_120", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET full_name = 'Superman' JOIN team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team_member_superhero.team_member_id = team_member.id WHERE team_id = 91;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n UPDATE superhero SET full_name = 'Superman' \u001b[4mJOIN\u001b[0m team_member_superhero ON superhero.id = team_member_superhero.superhero_id JOIN team_member ON team", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "superhero" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_130", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(*) AS streak_count, 'April Meeting' AS event_name, 'MST' AS timezone, MIN(event_date) AS start_date, MAX(event_date) AS end_date FROM attendance WHERE event_name = 'April Meeting' GROUP BY DATE_TRUNC('day', event_date AT TIME ZONE 'UTC' AT TIME ZONE 'MST') ORDER BY end_date DESC LIMIT 1;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'event_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "event_date", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_131", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT DATE_TRUNC('day', to_timestamp(transaction_timestamp / 1000000000.0)), COUNT(*) FROM pitstops GROUP BY DATE_TRUNC('day', transaction_timestamp)", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'transaction_timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "transaction_timestamp", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'transaction_timestamp' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "transaction_timestamp", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "pitstops" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_137", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "DROP TABLE IF EXISTS card, account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, frequency TEXT NOT NULL, date DATE NOT NULL, disp_id INT NOT NULL, FOREIGN KEY (disp_id) REFERENCES disp(disp_id) ON UPDATE CASCADE ON DELETE CASCADE);CREATE TABLE disp (disp_id INT PRIMARY KEY NOT NULL, client_id INT NOT NULL, account_id INT NOT NULL, type TEXT NOT NULL, FOREIGN KEY (account_id) REFERENCES account(account_id) ON UPDATE CASCADE ON DELETE CASCADE);", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 26.\n DROP TABLE IF EXISTS card\u001b[4m,\u001b[0m account, disp;CREATE TABLE account (account_id INT PRIMARY KEY NOT NULL, district_id INT NOT NULL, ", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "card" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_138", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COALESCE(json_agg(CASE WHEN client.client_id IS NULL THEN NULL ELSE json_build_object('client_id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS clients FROM client;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 207.\n _id', client.client_id, 'gender', client.gender, 'birth_date', client.birth_date) END), '[]') AS AS \u001b[4mclients\u001b[0m FROM client;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_140", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, amount as cum_sum, 1 as bucket from transfer where id = 1 union all select transfer.id, (case when cum_sum + amount > 20 then amount else cum_sum + amount end), (case when cum_sum + amount > 20 then bucket + 1 else bucket end) from cte join transfer on transfer.id = cte.id + 1", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'cte' does not exist in schema", + "taxonomy_category": "semantic", + "context": "cte", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-UNION", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "UNION", + "WHERE" + ], + "tables": [ + "cte", + "transfer" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_141", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT raceid mode() within group(order by laps) as modal_laps FROM results;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 19.\n SELECT raceid mode\u001b[4m(\u001b[0m) within group(order by laps) as modal_laps FROM results;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_145", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "select id, name, d ->> 'description' as skill from player_skills, json_array_elements(skills) as d;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'd' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "d", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'skills' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "skills", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0365, + "pattern_signature": "SELECT-FROM-JOIN", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT" + ], + "tables": [ + "player_skills" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_147", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT COUNT(\"ANA Pattern\") AS c, \"ANA Pattern\", EXTRACT(YEAR FROM \"Examination Date\") AS examination_year FROM examination WHERE EXTRACT(YEAR FROM \"Examination Date\") BETWEEN 1993 AND 1996 GROUP BY EXTRACT(YEAR FROM \"Examination Date\"), \"ANA Pattern\" ORDER BY examination_year, c DESC;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'ANA Pattern' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ANA Pattern", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "examination" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_155", + "db_id": "formula_1", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\nFROM circuit_json;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 3, Col: 4.\n SELECT *\nFROM jsonb_to_record(circuit_id_name) AS x(circuitid int, name text)\n\u001b[4mFROM\u001b[0m circuit_json;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_158", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT count(*) FROM card_matches INNER JOIN card_players ON card_matches.player1_id = card_players.id OR card_matches.player2_id = card_players.id WHERE card_players.type = 'Pro'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in table 'card_players' (referenced as 'card_players.type')", + "taxonomy_category": "semantic", + "context": "card_players.type", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'player1_id' does not exist in table 'card_matches' (referenced as 'card_matches.player1_id')", + "taxonomy_category": "semantic", + "context": "card_matches.player1_id", + "affected_clauses": [ + "JOIN" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'player2_id' does not exist in table 'card_matches' (referenced as 'card_matches.player2_id')", + "taxonomy_category": "semantic", + "context": "card_matches.player2_id", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WHERE" + ], + "tables": [ + "card_matches", + "card_players" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_163", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT d.the_day AS \"Date\", COUNT(e.event_id) AS \"Number of Events\", AVG(b.remaining) AS \"Avg Remaining Budget\" FROM (SELECT ts::date AS the_day FROM generate_series (timestamp '2020-01-01', timestamp '2020-03-31', interval '1 day'::interval) ts) d LEFT JOIN \"event\" e ON e.event_date::date = d.the_day LEFT JOIN budget b ON b.link_to_event = e.event_id GROUP BY d.the_day ORDER BY d.the_day;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'ts' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "ts", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1646, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_169", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "insert into card_counters (card_name, counters) values ('Lightning Bolt', array[2,0,2,1]) on conflict (card_name) do update set counters = array_agg(unnest(card_counters.counters) + unnest(array[2,0,2,1]))", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'counters' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "counters" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'counters' does not exist in table 'card_counters' (referenced as 'card_counters.counters')", + "taxonomy_category": "semantic", + "context": "card_counters.counters" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "VALUES-INSERT", + "clauses_present": [ + "INSERT", + "VALUES" + ], + "tables": [ + "card_counters" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_173", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "select id, array_agg(elem) from cards, unnest(string_to_array(cards.keywords, ',')::text[]) elem where elem <> all(SELECT unnest(sq.RemoveKeywords) from SelectQuery sq) and id in (61, 65) group by id order by id;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'elem' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "elem", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'elem' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "elem", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0708, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-ORDER", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE" + ], + "tables": [ + "cards", + "selectquery" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_176", + "db_id": "superhero", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE superhero SET total_powers = (SELECT COUNT(power_id) FROM hero_power);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'total_powers' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "total_powers" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1063, + "pattern_signature": "SELECT-FROM-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE" + ], + "tables": [ + "hero_power", + "superhero" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_179", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "WITH s as ( SELECT DATE(date_value) as dt, date_value, card_id cid, price FROM card_prices ) SELECT cid, dt, date_value, s.price as second_price FROM s INNER JOIN ( SELECT q.card_id, DATE(q.date_value) as dat FROM card_prices q GROUP BY q.card_id, dat ORDER BY q.card_id ASC ) as end_price ON s.cid = end_price.card_id AND s.date_value = (SELECT date_value FROM s WHERE s.cid = end_price.card_id AND s.dt = end_price.dat LIMIT 1) + interval '15 minutes' ORDER BY cid, dt;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'date_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date_value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'date_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "date_value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1875, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "card_prices", + "s" + ], + "num_joins": 1, + "num_subqueries": 2, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_181", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT timestamp, avg(strength) FROM bond_strength WHERE timestamp >= ('2023-10-01 02:30:00'::timestamp - INTERVAL '1 hour') GROUP BY timestamp, strength", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "strength", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'strength' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "strength", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT", + "WHERE" + ], + "tables": [ + "bond_strength" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_182", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "select jsonb_set(t.data, '{purchaseurls}', (select jsonb_agg(case when v.value::text ~ 'tcgplayer' or v.value::text ~ 'cardKingdom' then md5(substring(v.value::text)), jsonb_array_elements(t.data -> 'purchaseurls') v)) from cards_info", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.1, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "cards_info" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_195", + "db_id": "california_schools", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT CAST(time_bucket AS DATE) AS time_bucket, rate / DATE_PART('days', time_bucket + INTERVAL '1 month - 1 day') AS daily_rate FROM (SELECT DATE(generate_series(LOWER(time_span)::TIMESTAMP, COALESCE(UPPER(time_span),NOW())::TIMESTAMP, '1 day')) AS time_bucket, rate FROM budgets) AS daily_rates;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'rate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "rate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'rate' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "rate", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'time_span' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "time_span", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'time_span' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "time_span", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0896, + "pattern_signature": "SELECT-FROM-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "budgets" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_199", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "DROP FUNCTION IF EXISTS update_school_inventory_after_supply() CASCADE;CREATE OR REPLACE FUNCTION update_school_inventory_after_supply() RETURNS TRIGGER LANGUAGE plpgsql AS $trigger$ BEGIN UPDATE school_inventory AS i SET NEW.quantity = school_supplies.quantity + OLD.quantity FROM school_supplies WHERE i.cdscode = school_supplies.cdscode; RETURN NEW; END; $trigger$;DROP TRIGGER IF EXISTS trigger_insert_supply ON school_supplies;CREATE TRIGGER trigger_insert_supply AFTER INSERT ON school_supplies", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'update_school_inventory_after_supply' does not exist in schema", + "taxonomy_category": "semantic", + "context": "update_school_inventory_after_supply", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [ + "update_school_inventory_after_supply" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_200", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT county, AVG(avgscrread + avgscrmath + avgscrwrite) / 3 AS avg_total_sat FROM satscores GROUP BY county ORDER BY avg_total_sat DESC LIMIT 5;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'county' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "county", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP-ORDER-LIMIT", + "clauses_present": [ + "FROM", + "GROUP", + "LIMIT", + "ORDER", + "SELECT" + ], + "tables": [ + "satscores" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_202", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM match_location WHERE ST_INTERSECTS(location, CIRCLE(POINT(-73.935242, 40.730610), 2));", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'location' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "location", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "match_location" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_213", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result FOR attribute_name IN (Strength, Speed, Intelligence))", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expecting an aggregation function in PIVOT. Line 1, Col: 103.\n SELECT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(\u001b[4mresult\u001b[0m FOR attribute_name IN (Strength, Speed, Intelligence))\n\nRequired keyword: 'this' missing for . Line 1, Col: 107.\n CT superhero_name, performance_date, attribute_name, result FROM superhero_performance PIVOT(result \u001b[4mFOR\u001b[0m attribute_name IN (Strength, Speed, Intelligence))", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "superhero_performance" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_214", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT COUNT(*) FROM laboratory WHERE date_part('year', date) = date_part('year', CURRENT_DATE) AND date_part('month', date) = date_part('month', CURRENT_DATE) AND date [I don't know what to put here];", + "valid": false, + "errors": [ + { + "tag": "syntax_unterminated_string", + "message": "Unterminated quoted string", + "taxonomy_category": "syntax", + "context": "Error tokenizing 'NT_DATE) AND date [I don't know what to put here]'" + } + ], + "tags": [ + "syntax_unterminated_string" + ] + }, + { + "instance_id": "PostgreSQL_218", + "db_id": "financial", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE card SET type = ( SELECT type, client_id FROM disp WHERE card.disp_id = disp.disp_id );", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'type' is ambiguous \u2014 exists in tables: card, disp", + "taxonomy_category": "semantic", + "context": "type" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'type' is ambiguous \u2014 exists in tables: card, disp", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-UPDATE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "UPDATE", + "WHERE" + ], + "tables": [ + "card", + "disp" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_222", + "db_id": "esophageal", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS patients, (SELECT * FROM doctors) AS doctors, (SELECT * FROM appointments) AS appointments;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expected type. Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nRequired keyword: 'to' missing for . Line 1, Col: 39.\n SELECT coalesce(_agg(patients), '[]'::\u001b[4m)\u001b[0m as patients, coalesce(_agg(doctors), '[]'::) as doctors, coalesce(_agg(appointments), '[]'::) as ap\n\nExpected type. Line 1, Col: 84.\n SELECT coalesce(_agg(patients), '[]'::) as patients, coalesce(_agg(doctors), '[]'::\u001b[4m)\u001b[0m as doctors, coalesce(_agg(appointments), '[]'::) as appointments FROM (SELECT * FROM patients) AS p\n\n... and 3 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.2292, + "pattern_signature": "SELECT-FROM-JOIN-SUBQUERY", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "appointments", + "doctors", + "patients" + ], + "num_joins": 2, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_223", + "db_id": "esophageal", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE patients_info\nSET general_info = jsonb_set(general_info, '{accept_appointments}', '\"false\"');", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'general_info' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "general_info" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'general_info' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "general_info" + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "patients_info" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_236", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, engagement_history FROM learners_array;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'engagement_history' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "engagement_history", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM", + "clauses_present": [ + "FROM", + "SELECT" + ], + "tables": [ + "learners_array" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_239", + "db_id": "erolp", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT learner_code, CASE WHEN Geographic_Location = 'Urban' THEN 1 WHEN Geographic_Location = 'Rural' THEN 2 ELSE 0 END AS location_id, AVG(Pre_Test_Score) AS average_pre_test_score FROM learners WHERE Engagement_History > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 318.\n tory > 5 AND Gender = 'Female' AND Language_Proficiency IN ('Basic', 'Intermediate') AND CASE WHEN $\u001b[4m{\u001b[0msocio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN ${socio_status} = 'High' \n\nRequired keyword: 'this' missing for . Line 1, Col: 395.\n diate') AND CASE WHEN ${socio_status} IN ('Low', 'Middle') THEN Geographic_Location = 'Urban' WHEN $\u001b[4m{\u001b[0msocio_status} = 'High' THEN Geographic_Location = 'Rural' END;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Pre_Test_Score' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Pre_Test_Score", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_keyword_misuse", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0552, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "learners" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_250", + "db_id": "spotify", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM sp_album_ctb WHERE (alb, art, feat_arts, start_date) IN (SELECT alb, art, feat_arts, end_date + INTERVAL '1 day' FROM sp_album_ctb);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "sp_album_ctb" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_253", + "db_id": "global_atlas", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT * FROM city ORDER BY COALESCE(SUBSTRING(name FROM '[A-Z]+'), ''), COALESCE(SUBSTRING(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\uff1b", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 190.\n NG(name FROM '(?<=-)[0-9]+')::INTEGER, 0), COALESCE(SUBSTRING(name FROM '(?<=\\()[0-9]+')::BIGINT, 0)\u001b[4m\uff1b\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "city" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_260", + "db_id": "erolp", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM orders WHERE customer_id = 1 OR product_id = 'P202'", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'customer_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "customer_id", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'product_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "product_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "orders" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_266", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "WITH t1 AS ( SELECT e.event_id FROM event e LEFT JOIN attendance a ON e.event_id = a.link_to_event ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event)", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Failed to parse any statement following CTE. Line 1, Col: 197.\n nt ), t2 AS ( SELECT e.event_id FROM event e INNEr JOIN attendance a ON e.event_id = a.link_to_event\u001b[4m)\u001b[0m", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1188, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-JOIN_INNER", + "clauses_present": [ + "CTE", + "FROM", + "JOIN", + "JOIN_INNER", + "SELECT", + "WITH" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_272", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELEC Player.player_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_attributes ON Player.player_api_id = Player_Attributes.player_api_id WHERE Player_Attributes.overall_rating = 68", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 13.\n SELEC Player\u001b[4m.\u001b[0mplayer_api_id, Player.player_name, Player_Attributes.overall_rating FROM player LEFT JOIN player_att", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_282", + "db_id": "card_games", + "category": "Query", + "sql_index": 0, + "sql": "SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and power = '2') THEN coalesce(watermark, '998') watermark WHEN (colors = 'R' and power = '0') THEN coalesce(watermark, '999') watermark END) watermark FROM cards", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expected END after CASE. Line 1, Col: 84.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996'\u001b[4m)\u001b[0m watermark WHEN (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (color\n\nExpecting ). Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow\n\nInvalid expression / Unexpected token. Line 1, Col: 99.\n SELECT id, (CASE WHEN (colors = 'W' and power = '4') THEN coalesce(watermark, '996') watermark \u001b[4mWHEN\u001b[0m (colors = 'B' and power = '3') THEN coalesce(watermark, '997') watermark WHEN (colors = 'U' and pow", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_284", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT link_to_member, COUNT(DISTINCT DATE(event_date)) AS total_attendance_days FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] WITH cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link_to_member ORDER BY DATE(event_date)) AS rn FROM attendance JOIN event ON attendance.link_to_event = event.event_id WHERE event_date BETWEEN '2019-01-01' AN", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 244.\n ent.event_id WHERE event_date BETWEEN '2019-01-01' AND '2023-12-31' GROUP BY link_to_member [split] \u001b[4mWITH\u001b[0m cte AS ( SELECT link_to_member, DATE(event_date) AS event_day, ROW_NUMBER() OVER (PARTITION BY link", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "GROUP BY" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0604, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "attendance", + "event" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_291", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM patient pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND ex.\"aCL IgG\" > 3.0)", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 59.\n SELECT pt.id, pt.sex, pt.birthday, ex.diagnosis FRM \u001b[4mpatient\u001b[0m pt, examination ex WHERE pt.id = (SELECT ex.id FROM examination ex WHERE ex.diagnosis = 'SLE' AND e", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_293", + "db_id": "european_football_2", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id GROUP BY l.country_id HAVING l.country_id > 1000;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 101.\n UPDATE league l SET name = concat('abc', ',', name) FROM country c WHERE l.country_id = c.id \u001b[4mGROUP BY\u001b[0m l.country_id HAVING l.country_id > 1000;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'name' is ambiguous \u2014 exists in tables: league, country", + "taxonomy_category": "semantic", + "context": "name" + } + ], + "tags": [ + "syntax_invalid_token", + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "FROM-WHERE-UPDATE", + "clauses_present": [ + "FROM", + "UPDATE", + "WHERE" + ], + "tables": [ + "country", + "league" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_299", + "db_id": "financial", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] SELECT 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district WHERE A8 = 4 [split] SELECT 4 AS RATES, COUNT(A9) FROM district WHERE A9 = 4 [split] SELECT 3 AS RATES, COUNT(A8) FROM district WHERE A8 = 3 [split] SELECT 3 AS RATES, COUNT(A9) FROM district WHERE A9 = 3", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 70.\n SELECT 5 AS RATES, COUNT(A8) FROM district WHERE A8 = 5 [split] \u001b[4mSELECT\u001b[0m 5 AS RATES, COUNT(A9) FROM district WHERE A9 = 5 [split] SELECT 4 AS RATES, COUNT(A8) FROM district", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'split' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "split", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.024, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "district" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_305", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT * FROM budget GROUP BY link_to_event WHEN event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN 'Open' WHEN event_status = 'Open' THEN 'Open' WHEN event_status = 'Planning' THEN 'Planning' ELSE 'Unknown' END;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 48.\n SELECT * FROM budget GROUP BY link_to_event \u001b[4mWHEN\u001b[0m event_status = 'Closed' THEN 'Closed' WHEN event_status = 'Open' AND event_status = 'Planning' THEN", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "budget" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_307", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY (SELECT MAX(\"Update_Time\") FROM cards) NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'table_name' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_name", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'table_schema' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "table_schema", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Update_Time' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Update_Time", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1135, + "pattern_signature": "SELECT-FROM-WHERE-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "cards", + "tables" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_310", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE ?? = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Expected table name but got . Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');\n\nInvalid expression / Unexpected token. Line 1, Col: 9.\n UPDATE \u001b[4m??\u001b[0m = REPLACE(??, 'http://stackoverflow.com', 'https://stackoverflow.com');", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_311", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "CREATE TABLE content (id serial PRIMARY KEY NOT NULL, item_id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent CHECK nested_item_id <> id)", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Required keyword: 'expressions' missing for . Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)\n\nExpecting ). Line 1, Col: 163.\n _id int NOT NULL, nested_item_id int, block_id int, \"order\" int NOT NULL, CONSTRAINT not_own_parent \u001b[4mCHECK\u001b[0m nested_item_id <> id)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "UNKNOWN", + "clauses_present": [], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_313", + "db_id": "card_games", + "category": "Management", + "sql_index": 0, + "sql": "INSERT INTO rulings (date, text, uuid) SELECT t.col1, t.col2, t.col3 FROM (SELECT '2023-01-01' AS col1, 'Some ruling text.' AS col2, (SELECT uuid FROM cards WHERE borderColor = 'black' AND layout = 'normal') AS col3 UNION ALL SELECT '2023-01-02' AS col1, 'Another ruling text.' AS col2, (SELECT uuid FROM cards WHERE isAlternative = 1) AS col3) t WHERE NOT EXISTS (SELECT 1 FROM rulings WHERE rulings.date = t.col1::date);", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'uuid' is ambiguous \u2014 exists in tables: rulings, cards", + "taxonomy_category": "semantic", + "context": "uuid", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.2521, + "pattern_signature": "SELECT-FROM-WHERE-UNION-INSERT-SUBQUERY", + "clauses_present": [ + "FROM", + "INSERT", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE" + ], + "tables": [ + "cards", + "rulings" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_317", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT humidity_level, (humidity_level - LAG(humidity_level, 1) OVER (ORDER BY record_id NULLS FIRST)) AS diff FROM warehouse_humidity WHERE diff = 0 OR diff > 10", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'warehouse_humidity' does not exist in schema", + "taxonomy_category": "semantic", + "context": "warehouse_humidity", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0344, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WHERE", + "WINDOW" + ], + "tables": [ + "warehouse_humidity" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_318", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders@lpu.edu;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 1, Col: 95.\n SELECT s.member_id FROM members AS s WHERE s.position = 'Member' AND s.email @@ angela.sanders\u001b[4m@\u001b[0mlpu.edu;", + "taxonomy_category": "syntax" + }, + { + "tag": "schema_hallucination_table", + "message": "Table 'members' does not exist in schema", + "taxonomy_category": "semantic", + "context": "members", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "syntax_invalid_token", + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0281, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "members" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_332", + "db_id": "codebase_community", + "category": "Query", + "sql_index": 0, + "sql": "SELECT CASE WHEN amount_sold < 1000 THEN 'Under 1000' WHEN amount_sold BETWEEN 1000 AND 9999 THEN '1000 to 9999' WHEN amount_sold BETWEEN 10000 AND 49999 THEN '10000 to 49999' WHEN amount_sold >= 50000 THEN '50000 and above' END AS range, AVG(Count) AS avg FROM sales_data GROUP BY range", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'sales_data' does not exist in schema", + "taxonomy_category": "semantic", + "context": "sales_data", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.0167, + "pattern_signature": "SELECT-FROM-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "SELECT" + ], + "tables": [ + "sales_data" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_336", + "db_id": "thrombosis_prediction", + "category": "Management", + "sql_index": 0, + "sql": "SET list = (SELECT id FROM patient WHERE sex = 'F' AND id < 40000);", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'list' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "list" + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1073, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_339", + "db_id": "card_games", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT p.id, p.name, c.item, c.size FROM packages p LEFT JOIN contents c ON (c.packageid=p.id) WHERE (( p.id IN ( SELECT packageid FROM contents WHERE item='square' AND size='A' ) AND ( p.id IN ( SELECT packageid FROM contents WHERE item='circle' AND size='B' )) GROUP BY p.id HAVING ( SELECT COUNT(*) FROM contents WHERE packageid=p.id ) = 2;", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "2 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.2667, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-HAVING-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "HAVING", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "contents", + "packages" + ], + "num_joins": 1, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_349", + "db_id": "codebase_community", + "category": "Management", + "sql_index": 0, + "sql": "SELECT\n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Expected ]. Line 5, Col: 79.\n \n id,\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract \u001b[4mholidays\u001b[0m] AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;\n\nInvalid expression / Unexpected token. Line 5, Col: 80.\n displayname,\n age,\n SUM(date_part('day', lastaccessdate - creationdate) + 1) - [subtract holidays\u001b[4m]\u001b[0m AS TotalDays\nFROM\n users\nGROUP BY\n displayname, age\nORDER BY\n users.id;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0063, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_358", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT b.\"event_id\", b.\"amount\", b.\"link_to_member\", \"link_to_event\" FROM event AS b JOIN budget AS b ON b.\"event_id\" = b.\"link_to_event\" LEFT JOIN attendance AS b ON b.\"event_id\" = b.\"link_to_event\" ORDER BY b.\"event_id\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'link_to_event' is ambiguous \u2014 exists in tables: budget, attendance", + "taxonomy_category": "semantic", + "context": "link_to_event", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.0833, + "pattern_signature": "SELECT-FROM-JOIN-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "ORDER", + "SELECT" + ], + "tables": [ + "attendance", + "budget", + "event" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_359", + "db_id": "superhero", + "category": "Personalization", + "sql_index": 0, + "sql": "CREATE FUNCTION check_alignment(alignment_name VARCHAR) RETURNS VARCHAR(1) AS $$ BEGIN RETURN CASE WHEN alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' END", + "valid": false, + "errors": [ + { + "tag": "syntax_error", + "message": "Error tokenizing 'alignment_name LIKE '%Good%' THEN 'Y' ELSE 'N' EN'", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_error" + ] + }, + { + "instance_id": "PostgreSQL_366", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH molecule_atoms AS (\n SELECT m.molecule_id, m.label, a.atom_id, a.element,\n ROW_NUMBER() OVER (PARTITION BY m.molecule_id ORDER BY a.atom_id NULLS FIRST) AS atom_seq\n FROM molecule AS m\n LEFT JOIN atom AS a ON m.molecule_id = a.molecule_id\n),\nmolecule_bonds AS (\n SELECT b.molecule_id, b.bond_id, b.bond_type,\n c.atom_id AS source_atom, c.atom_id2 AS target_atom,\n DENSE_RANK() OVER (PARTITION BY b.molecule_id ORDER BY b.bond_id NULLS FIRST) AS bond_ran", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'molecule_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2427, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_CROSS-WHERE-WINDOW-UNION-ORDER", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "JOIN", + "JOIN_CROSS", + "ORDER", + "SELECT", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_connections", + "bond", + "connected", + "molecule", + "molecule_atoms", + "molecule_bonds" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 3, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_370", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH atom_stats AS (\n SELECT a.molecule_id, COUNT(a.atom_id) AS atom_count,\n STRING_AGG(a.element, ',' ORDER BY a.atom_id NULLS FIRST) AS elements\n FROM atom AS a\n GROUP BY a.molecule_id\n),\nbond_hierarchy AS (\n SELECT bond_id, molecule_id, bond_type,\n SUBSTRING(bond_id FROM '^[^_]+') AS molecule_prefix,\n CAST(SUBSTRING(bond_id FROM '[^_]+' FOR 1) AS DOUBLE PRECISION) AS first_atom_num,\n CAST(SUBSTRING(bond_id FROM '[^_]+$') AS DOUBLE PRECISION)", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'molecule_id' is ambiguous \u2014 exists in tables: atom, bond, molecule", + "taxonomy_category": "semantic", + "context": "molecule_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.4229, + "pattern_signature": "WITH-CTE-SELECT-DISTINCT-FROM-JOIN-JOIN_INNER-WHERE-GROUP-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "DISTINCT", + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "atom_stats", + "bond", + "bond_hierarchy", + "connected", + "molecule", + "molecule_connectivity" + ], + "num_joins": 8, + "num_subqueries": 1, + "num_ctes": 3, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_373", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT m.\"molecule_id\",\n COUNT(a.\"atom_id\") / COUNT(DISTINCT b.\"bond_id\") AS result\nFROM \"molecule\" m\nINNER JOIN \"atom\" a ON m.\"molecule_id\" = a.\"molecule_id\"\nINNER JOIN \"connected\" c ON a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" INTO :result_variable", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 7, Col: 29.\n a.\"atom_id\" = c.\"atom_id\"\nINNER JOIN \"bond\" b ON c.\"bond_id\" = b.\"bond_id\"\nGROUP BY m.\"molecule_id\" \u001b[4mINTO\u001b[0m :result_variable", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1323, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-GROUP", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "JOIN_INNER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_381", + "db_id": "student_club", + "category": "Query", + "sql_index": 0, + "sql": "SELECT e.\"event_id\", e.\"event_name\", e.\"event_date\", e.\"type\",\n(SELECT MAX(CAST(column_value AS timestamp)) AS latest_event_date FROM (VALUES (e.\"event_date\")) AS value_table(column_value)\nWHERE column_value IS NOT NULL) AS latest_event_date FROM \"event\" e", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'column_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "column_value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'column_value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "column_value", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.1031, + "pattern_signature": "SELECT-FROM-WHERE-VALUES-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "VALUES", + "WHERE" + ], + "tables": [ + "event" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_382", + "db_id": "student_club", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT\n TO_CHAR(type) AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 END) -\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = oldest_year THEN 1 END) AS year_difference\nFROM event,\n (\n SELECT\n MAX(EXTRACT(YEAR FROM event_date::timestamp)) AS recent_year,\n MIN(EXTRACT(YEAR FROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type), recent_year, oldest_year;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'format' missing for . Line 2, Col: 17.\n SELECT\n TO_CHAR(type\u001b[4m)\u001b[0m AS event_type,\n COUNT(CASE WHEN EXTRACT(YEAR FROM event_date::timestamp) = recent_year THEN 1 EN\n\nRequired keyword: 'format' missing for . Line 12, Col: 22.\n ROM event_date::timestamp)) AS oldest_year\n FROM event\n ) year_range\nGROUP BY TO_CHAR(type\u001b[4m)\u001b[0m, recent_year, oldest_year;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1406, + "pattern_signature": "SELECT-FROM-JOIN-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY" + ], + "tables": [ + "event" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_387", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH\n\n set_a (molecule_id, element_count) AS (\n SELECT molecule_id, COUNT(DISTINCT element)\n FROM atom\n GROUP BY molecule_id\n HAVING COUNT(DISTINCT element) > 1\n ),\n set_b (molecule_id, element_count) AS (\n SELECT m.molecule_id, COUNT(DISTINCT a.element)\n FROM molecule m\n JOIN atom a ON m.molecule_id = a.molecule_id\n WHERE m.label IS NOT NULL\n GROUP BY m.molecule_id\n ),\n\n unique_a (molecule_id, element_count, rn, densi", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'bond_id' is ambiguous \u2014 exists in tables: bond, connected", + "taxonomy_category": "semantic", + "context": "bond_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'element_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "element_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.5177, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule", + "molecule_hierarchy", + "set_a", + "set_b", + "unique_a", + "unique_b" + ], + "num_joins": 6, + "num_subqueries": 2, + "num_ctes": 5, + "num_aggregations": 12 + } + }, + { + "instance_id": "PostgreSQL_390", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH match_dates AS\n (SELECT \"id\",\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_date,\n TO_CHAR(TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS'), 'fmDay', 'English') AS day_of_week,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') AS match_start_time,\n TO_DATE(\"date\", 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '2 HOUR' AS match_end_time\n FROM \"match\")\nSELECT m.*,\n ROUND(GREATEST(LEAST(m.match_end_time, m.match_date + INTERVAL '17:00:00' HOUR TO SECOND) - GREATEST(m.ma", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_table", + "message": "Table 'DBA_VIEWS' does not exist in schema", + "taxonomy_category": "semantic", + "context": "DBA_VIEWS", + "affected_clauses": [ + "FROM" + ] + } + ], + "tags": [ + "schema_hallucination_table" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "SUBQUERY", + "WHERE", + "WITH" + ], + "tables": [ + "dba_views", + "match", + "match_dates" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_392", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"home_team_api_id\" AS \"team_api_id\",\n \"start_date\",\n \"end_date\",\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (consecutive_wins+) DEFINE consecutive_wins AS \"league_id\" = 'EUROPEAN_FOOTBALL_2')", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 6, Col: 38.\n \"match_count\"\nFROM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n \u001b[4mORDER BY\u001b[0m \"date\" MEASURES FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\n\nInvalid expression / Unexpected token. Line 6, Col: 54.\n OM \"match\" MATCH_RECOGNIZE (PARTITION BY \"country_id\"\n ORDER BY \"date\" \u001b[4mMEASURES\u001b[0m FIRST(\"date\") AS \"start_date\", LAST(\"date\") AS \"end_date\", COUNT(*) AS \"match_count\" PATTERN (conse", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'start_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "start_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'end_date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "end_date", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'match_count' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "match_count", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "syntax_unbalanced_tokens", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "SELECT-FROM-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT" + ], + "tables": [ + "match" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_404", + "db_id": "california_schools", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"valid_from\",\n \"valid_until\",\n \"count\"\nFROM\n (SELECT \"dt\" AS \"valid_from\",\n LEAD(\"dt\") OVER (\n ORDER BY \"dt\") - INTERVAL '1' SECOND AS \"valid_until\",\n SUM(\"count\" * \"type\") OVER (\n ORDER BY \"dt\") AS \"count\"\n FROM\n (SELECT \"valid_from\",\n \"valid_until\" + INTERVAL '1 DAY' AS \"valid_until\",\n 1 AS \"count\"\n FROM\n (SELECT TO_DATE('2014-01-01', 'YYYY-MM-DD') AS \"", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'type' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "type", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'dt' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "dt", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2885, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WHERE", + "WINDOW" + ], + "tables": [ + "schools" + ], + "num_joins": 0, + "num_subqueries": 3, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_411", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH team_speed_stats AS (\n SELECT\n team_api_id,\n date,\n buildupplayspeed,\n ROW_NUMBER() OVER (PARTITION BY team_api_id ORDER BY date DESC) as rn,\n AVG(buildupplayspeed) OVER (PARTITION BY buildupplayspeedclass) as class_avg_speed\n FROM team_attributes\n),\nmatch_details AS (\n SELECT\n m.id,\n m.date,\n m.home_team_api_id,\n m.away_team_api_id,\n m.home_team_goal,\n m.away_team_goal,\n t.team_long_name as home_te", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_api_id' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_api_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'home_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "home_team_goal", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'away_team_goal' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "away_team_goal", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.499, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-HAVING-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "HAVING", + "JOIN", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "match", + "match_details", + "team", + "team_attributes", + "team_speed_stats" + ], + "num_joins": 5, + "num_subqueries": 4, + "num_ctes": 2, + "num_aggregations": 5 + } + }, + { + "instance_id": "PostgreSQL_412", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "with lose_agg as\n (select team_api_id,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2011 then defencepressure\n end) as lose_5,\n sum(case\n when extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) = 2012 then defencepressure\n end) as lose_10\n from team_attributes\n group by team_api_id),\n profit_agg as\n (select team_api_id,\n sum(case\n when extract(ye", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 29, Col: 6.\n join profit_agg p on l.team_api_id = p.team_api_id\norder by coalesce(p.team_api_id, l.team_api_id)\n\u001b[4mselect\u001b[0m extract(year from to_date(date, 'YYYY-MM-DD HH24:MI:SS')) as year\nfrom team_attributes\nwhere date =", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1281, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-GROUP-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WITH" + ], + "tables": [ + "lose_agg", + "profit_agg", + "team_attributes" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_417", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_name\"))\n ORDER BY \"team_long_name\" COLLATE \"fr_FR\")) INDENT SIZE = 2) AS result\nFROM \"team\"\nWHERE \"id\" IN\n (SELECT \"id\"\n FROM \"team_attributes\"\n WHERE \"date\" IS NULL)", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 1, Col: 39.\n SELECT XMLSERIALIZE(DOCUMENT \u001b[4mXMLELEMENT\u001b[0m(NAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long\n\nInvalid expression / Unexpected token. Line 1, Col: 40.\n SELECT XMLSERIALIZE(DOCUMENT XMLELEMENT\u001b[4m(\u001b[0mNAME \"files\", XMLAGG(XMLELEMENT(NAME \"file\", XMLFOREST(\"id\" AS \"id\", \"team_long_name\" AS \"team_long_", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0, + "pattern_signature": "SELECT", + "clauses_present": [ + "SELECT" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_421", + "db_id": "european_football_2", + "category": "Query", + "sql_index": 0, + "sql": "WITH \"my_table\" AS\n (SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A1' AS \"file_\",\n 5 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 1 AS \"nif\",\n 'A2' AS \"file_\",\n 3 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A3' AS \"file_\",\n 2 AS \"filesize\"\n UNION ALL SELECT 'A' AS \"cto\",\n 2 AS \"nif\",\n 'A4' AS \"file_\",\n ", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 38, Col: 46.\n ize\"\n FROM \"my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n \u001b[4mORDER BY\u001b[0m \"rn\" MEASURES MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((\n\nInvalid expression / Unexpected token. Line 38, Col: 60.\n my_table\" t) MATCH_RECOGNIZE(PARTITION BY \"cto\"\n ORDER BY \"rn\" \u001b[4mMEASURES\u001b[0m MATCH_NUMBER() AS \"mn\", SUM(\"filesize\") AS \"total_size\" ALL ROWS PER MATCH PATTERN ((same_nif* nif)", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0958, + "pattern_signature": "WITH-CTE-SELECT-FROM-WINDOW-UNION-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "UNION", + "WINDOW", + "WITH" + ], + "tables": [ + "my_table" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 1, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_425", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"molecule\".\"molecule_id\",\n \"molecule\".\"label\",\n \"atom\".\"atom_id\",\n \"atom\".\"element\",\n \"bond\".\"bond_id\",\n \"bond\".\"bond_type\",\n \"connected\".\"atom_id2\"\nFROM \"molecule\"\nINNER JOIN \"atom\" ON \"molecule\".\"molecule_id\" = \"atom\".\"molecule_id\"\nINNER JOIN \"connected\" ON \"atom\".\"atom_id\" = \"connected\".\"atom_id\"\nINNER JOIN \"bond\" ON \"connected\".\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \"connected\".\"atom_id2\";", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 14, Col: 20.\n .\"bond_id\" = \"bond\".\"bond_id\"\nORDER BY \"molecule\".\"molecule_id\",\n \"atom\".\"atom_id\"\n \u001b[4m\"connected\"\u001b[0m.\"atom_id2\";", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.1198, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_INNER-ORDER", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_INNER", + "ORDER", + "SELECT" + ], + "tables": [ + "atom", + "bond", + "connected", + "molecule" + ], + "num_joins": 3, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_426", + "db_id": "california_schools", + "category": "Management", + "sql_index": 0, + "sql": "UPDATE \"frpm\" AS target\n \"Charter School (Y/N)\" = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Eligible Free (K-12)\" >= 0.5\n ) AS source\n WHERE target.\"cdscode\" = source.\"cdscode\";", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 26.\n UPDATE \"frpm\" AS target\n \u001b[4m\"Charter School (Y/N)\"\u001b[0m = 1000\n FROM (\n SELECT DISTINCT \"cdscode\"\n FROM \"frpm\"\n WHERE \"Percent (%) Elig", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0104, + "pattern_signature": "UPDATE", + "clauses_present": [ + "UPDATE" + ], + "tables": [ + "frpm" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_430", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "WITH RECURSIVE replacements (molecule_id, current_label, current_spos) AS (\n SELECT molecule_id,\n label::text,\n strpos(label::text, '+')\n FROM molecule\n UNION ALL\n SELECT r.molecule_id,\n overlay(r.current_label placing '-' from r.current_spos for 1),\n strpos(overlay(r.current_label placing '-' from r.current_spos for 1), '+')\n FROM replacements r\n WHERE r.current_spos > 0\nSELECT molecule_id,\n current_label AS label\nFROM replacements\n\nWHERE current_spos", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Unbalanced parentheses or brackets", + "taxonomy_category": "syntax", + "context": "1 unclosed '('" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0813, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-UNION", + "clauses_present": [ + "CTE", + "FROM", + "SELECT", + "UNION", + "WHERE", + "WITH" + ], + "tables": [ + "molecule", + "replacements" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_437", + "db_id": "toxicology", + "category": "Query", + "sql_index": 0, + "sql": "SELECT a.atom_id, COUNT(c.atom_id2) as connection_count FROM atom a LEFT JOIN connected c ON a.atom_id = c.atom_id WHERE a.atom_id IN (SELECT atom_id FROM test WHERE atom_id LIKE 'TR%') GROUP BY a.atom_id", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'atom_id' is ambiguous \u2014 exists in tables: atom, connected", + "taxonomy_category": "semantic", + "context": "atom_id", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_ambiguous_col", + "message": "Column 'atom_id' is ambiguous \u2014 exists in tables: atom, connected", + "taxonomy_category": "semantic", + "context": "atom_id", + "affected_clauses": [ + "WHERE" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_ambiguous_col" + ], + "query_metadata": { + "complexity_score": 0.1573, + "pattern_signature": "SELECT-FROM-JOIN-WHERE-GROUP-SUBQUERY", + "clauses_present": [ + "FROM", + "GROUP", + "JOIN", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "atom", + "connected", + "test" + ], + "num_joins": 1, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_455", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) PIVOT(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "valid": false, + "errors": [ + { + "tag": "syntax_invalid_token", + "message": "Invalid expression / Unexpected token. Line 2, Col: 36.\n T \"customerid\", \"date\", \"productid\", \"amount\" FROM \"transactions_1k\"\nWHERE (\"productid\" IN (2,5,9)) \u001b[4mPIVOT\u001b[0m(COUNT(\"amount\") FOR productid IN (2, 5, 9)) AS pivot_table;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_invalid_token" + ], + "query_metadata": { + "complexity_score": 0.0177, + "pattern_signature": "SELECT-FROM-WHERE", + "clauses_present": [ + "FROM", + "SELECT", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_457", + "db_id": "superhero", + "category": "Query", + "sql_index": 0, + "sql": "SELECT ???, s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE s.id IN (1, 2, 3)", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'this' missing for . Line 1, Col: 11.\n SELECT ???\u001b[4m,\u001b[0m s.superhero_name, p.publisher_name FROM superhero s JOIN publisher p ON s.publisher_id = p.id WHERE", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.0542, + "pattern_signature": "SELECT-FROM-JOIN-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "SELECT", + "WHERE" + ], + "tables": [ + "publisher", + "superhero" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_460", + "db_id": "toxicology", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT atom_id FROM ( SELECT CASE WHEN element = 'cl' AND lead(element) OVER\n(ORDER BY atom_id) = 'c' THEN REPLACE(CONCAT(atom_id, lead(atom_id) OVER (ORDER BY atom_id)), ' ', '')\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN atom_id, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Expected END after CASE. Line 4, Col: 82.\n _id) != 'c' THEN atom_id\nWHEN element = 'cl' AND lead(element) OVER (ORDER BY atom_id) IS NULL THEN \u001b[4matom_id\u001b[0m, ROW_NUMBER()\nOVER (ORDER BY atom_id) AS row_num ) AS tmp5 WHERE atom_id IS NOT NULL;", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.1427, + "pattern_signature": "SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 4 + } + }, + { + "instance_id": "PostgreSQL_483", + "db_id": "thrombosis_prediction", + "category": "Query", + "sql_index": 0, + "sql": "WITH PatientThrombosisHistory AS (SELECT e.ID, e.Thrombosis, ROW_NUMBER() OVER (PARTITION BY e.ID ORDER BY e.\"Examination Date\" DESC NULLS LAST) AS RecencyRank, COUNT(*) OVER (PARTITION BY e.ID) AS ExamCount FROM examination AS e WHERE NOT e.Thrombosis IS NULL), LabResults AS (SELECT l.ID, AVG(l.PLT) AS AvgPlateletCount, MAX(CASE WHEN l.PLT < 150 THEN 1 ELSE 0 END) AS HasLowPlatelets FROM laboratory AS l WHERE l.Date >= CURRENT_TIMESTAMP + INTERVAL '-1 YEAR' GROUP BY l.ID) SELECT p.ID AS Patient", + "valid": false, + "errors": [ + { + "tag": "schema_ambiguous_col", + "message": "Column 'ID' is ambiguous \u2014 exists in tables: patient, examination", + "taxonomy_category": "semantic", + "context": "ID", + "affected_clauses": [ + "WHERE" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'Examination Date' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "Examination Date", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_ambiguous_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2448, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER-LIMIT-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "LIMIT", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "examination", + "laboratory", + "labresults", + "patient", + "patientthrombosishistory" + ], + "num_joins": 2, + "num_subqueries": 1, + "num_ctes": 2, + "num_aggregations": 3 + } + }, + { + "instance_id": "PostgreSQL_488", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT RACEID, NAME, \"date\", LAG(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS PREVRACEID, LEAD(RACEID) OVER (PARTITION BY YEAR ORDER BY \"date\" NULLS FIRST) AS NEXTRACEID FROM races ORDER BY YEAR NULLS FIRST, \"date\" NULLS FIRST, \"non_existent_column\" NULLS FIRST", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'non_existent_column' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "non_existent_column", + "affected_clauses": [ + "ORDER BY" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0229, + "pattern_signature": "SELECT-FROM-WINDOW-ORDER", + "clauses_present": [ + "FROM", + "ORDER", + "SELECT", + "WINDOW" + ], + "tables": [ + "races" + ], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 2 + } + }, + { + "instance_id": "PostgreSQL_499", + "db_id": "debit_card_specializing", + "category": "Query", + "sql_index": 0, + "sql": "SELECT\n c.customerid,\n (\n SELECT\n CAST(t.transactionid AS TEXT) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n FOR JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.customerid\nWHERE segment = 'SME'\nFOR JSON PATH, WITHOUT_ARRAY_WRAPPER;", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c\n\nInvalid expression / Unexpected token. Line 8, Col: 11.\n ) AS transactionid\n FROM transactions_1k t\n WHERE t.customerid = c.customerid\n \u001b[4mFOR\u001b[0m JSON PATH\n ) AS transactions\nFROM customers c\nINNER JOIN transactions_1k t ON c.customerid = t.c", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0969, + "pattern_signature": "SELECT-FROM-WHERE-SUBQUERY", + "clauses_present": [ + "FROM", + "SELECT", + "SUBQUERY", + "WHERE" + ], + "tables": [ + "transactions_1k" + ], + "num_joins": 0, + "num_subqueries": 1, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_502", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "SELECT name, value FROM races CROSS JOIN LATERAL unnest(string_to_array(name, ' ')) AS value PIVOT (GROUPING(name) as name FOR value in ('name1','name2','name3','name4')) piv;", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "JOIN" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0427, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT" + ], + "tables": [ + "races" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 1 + } + }, + { + "instance_id": "PostgreSQL_505", + "db_id": "formula_1", + "category": "Query", + "sql_index": 0, + "sql": "WITH RaceResults AS (\n\n SELECT\n r.raceId,\n r.year,\n r.date,\n res.driverId,\n res.points,\n\n DENSE_RANK() OVER (PARTITION BY res.driverId, r.year ORDER BY r.date) AS SeasonRaceNumber,\n\n ROW_NUMBER() OVER (PARTITION BY res.driverId ORDER BY r.year, r.date) AS CareerRaceNumber\n FROM results res\n JOIN races r ON res.raceId = r.raceId\n WHERE res.position IS NOT NULL\n),\nDriverFirstFiveRaces AS (\n\n SELECT\n driverId,\n year,\n ", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "GROUP BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'year' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "year", + "affected_clauses": [ + "ORDER BY" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + }, + { + "tag": "schema_hallucination_col", + "message": "Column 'points' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "points", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col", + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.2021, + "pattern_signature": "WITH-CTE-SELECT-FROM-JOIN-WHERE-GROUP-WINDOW-ORDER", + "clauses_present": [ + "CTE", + "FROM", + "GROUP", + "JOIN", + "ORDER", + "SELECT", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "driverfirstfiveraces", + "drivers", + "raceresults", + "races", + "results" + ], + "num_joins": 2, + "num_subqueries": 0, + "num_ctes": 2, + "num_aggregations": 6 + } + }, + { + "instance_id": "PostgreSQL_510", + "db_id": "european_football_2", + "category": "Personalization", + "sql_index": 0, + "sql": "WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' || pa.player_api_id::text || ','\n LIKE '%,' || p.player_api_id::text || ',%'\n)\nSELECT\n id,\n name,\n player_api_id = xpath('text()', col)::VARCHAR(100)\nFROM CTE\nCROSS JOIN LATERAL XMLTABLE('/t' PASSING xml_val COLUMNS col XML PATH '.') AS CA\nLI", + "valid": false, + "errors": [ + { + "tag": "syntax_unbalanced_tokens", + "message": "Expecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\nExpecting ). Line 5, Col: 39.\n WITH CTE AS\n(\n SELECT\n pa.id,\n xml_val = XMLPARSE(CONTENT \u001b[4m''\u001b[0m || REPLACE(pa.player_api_id::text, ',', '') || ''),\n p.player_name as name\n FRO\n\ndpipe does not support CTE. Line 5, Col: 101.\n xml_val = XMLPARSE(CONTENT '' || REPLACE(pa.player_api_id::text, ',', '') || ''\u001b[4m)\u001b[0m,\n p.player_name as name\n FROM player_attributes pa\n INNER JOIN player p\n ON ',' |\n\n... and 1 more", + "taxonomy_category": "syntax", + "context": "Parser reported expecting parenthesis" + } + ], + "tags": [ + "syntax_unbalanced_tokens" + ], + "query_metadata": { + "complexity_score": 0.0458, + "pattern_signature": "WITH-CTE-SELECT", + "clauses_present": [ + "CTE", + "SELECT", + "WITH" + ], + "tables": [], + "num_joins": 0, + "num_subqueries": 0, + "num_ctes": 1, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_516", + "db_id": "thrombosis_prediction", + "category": "Personalization", + "sql_index": 0, + "sql": "SELECT ID, value FROM PATIENT CROSS JOIN LATERAL string_to_table(DIAGNOSIS, ',') AS s(value) WHERE DIAGNOSIS = 'SLE' || '; DROP TABLE PATIENT; --';", + "valid": false, + "errors": [ + { + "tag": "schema_hallucination_col", + "message": "Column 'value' does not exist in any referenced table", + "taxonomy_category": "semantic", + "context": "value", + "affected_clauses": [ + "SELECT" + ] + } + ], + "tags": [ + "schema_hallucination_col" + ], + "query_metadata": { + "complexity_score": 0.0438, + "pattern_signature": "SELECT-FROM-JOIN-JOIN_CROSS-LATERAL-WHERE", + "clauses_present": [ + "FROM", + "JOIN", + "JOIN_CROSS", + "LATERAL", + "SELECT", + "WHERE" + ], + "tables": [ + "patient" + ], + "num_joins": 1, + "num_subqueries": 0, + "num_ctes": 0, + "num_aggregations": 0 + } + }, + { + "instance_id": "PostgreSQL_521", + "db_id": "financial", + "category": "Query", + "sql_index": 0, + "sql": "WITH PaymentRanks AS (SELECT payments, ROW_NUMBER() OVER (ORDER BY payments DESC NULLS LAST) AS row_num, DENSE_RANK() OVER (ORDER BY payments DESC NULLS LAST) AS dense_rank_num, COUNT(*) OVER () AS total_count FROM loan), DistinctPayments AS (SELECT COUNT( payments) AS distinct_payment_count FROM loan) SELECT CASE WHEN (SELECT COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM payme", + "valid": false, + "errors": [ + { + "tag": "syntax_keyword_misuse", + "message": "Required keyword: 'expression' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nRequired keyword: 'true' missing for . Line 1, Col: 436.\n UNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 AND \u001b[4mWHERE\u001b[0m payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END AS Se\n\nExpected END after CASE. Line 1, Col: 430.\n T COUNT(*) FROM loan) <= 2 THEN NULL WHEN (SELECT distinct_payment_count FROM distinctpayments) = 1 \u001b[4mAND\u001b[0m WHERE payments IS NOT NULL THEN NULL ELSE (SELECT payments FROM paymentranks WHERE row_num = 1) END\n\n... and 1 more", + "taxonomy_category": "syntax" + } + ], + "tags": [ + "syntax_keyword_misuse" + ], + "query_metadata": { + "complexity_score": 0.176, + "pattern_signature": "WITH-CTE-SELECT-FROM-WHERE-WINDOW-ORDER-SUBQUERY", + "clauses_present": [ + "CTE", + "FROM", + "ORDER", + "SELECT", + "SUBQUERY", + "WHERE", + "WINDOW", + "WITH" + ], + "tables": [ + "distinctpayments", + "loan" + ], + "num_joins": 0, + "num_subqueries": 2, + "num_ctes": 2, + "num_aggregations": 4 + } + } +] \ No newline at end of file diff --git a/tests/run_validate_with_db_benchmark.py b/tests/run_validate_with_db_benchmark.py new file mode 100644 index 0000000..d39d3a6 --- /dev/null +++ b/tests/run_validate_with_db_benchmark.py @@ -0,0 +1,395 @@ +# -*- coding: utf-8 -*- +""" +Run all issue_sql queries from postgresql_full.jsonl through validate_with_db +using live Docker PostgreSQL databases. + +Prerequisites: + 1. Start Docker containers: + cd benchmark && docker-compose up -d + 2. Wait for databases to be healthy: + docker exec sequel2sql_postgresql pg_isready -U root + +Usage: + cd sequel2sql + uv run python tests/run_validate_with_db_benchmark.py + +Outputs: + tests/output/validate_with_db_benchmark_results.json + tests/output/validate_with_db_benchmark_errors_only.json +""" + +import json +import os +import sys +import time +from pathlib import Path +from typing import Dict, List, Optional, Tuple + +# Add src to path so ast_parsers is importable +ROOT = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT / "src")) + +from sqlalchemy import create_engine, text +from sqlalchemy.engine import Engine + +from ast_parsers.result import ValidationResult +from ast_parsers.validator import invalidate_schema_cache, validate_with_db + +# ─── Docker PostgreSQL connection config ───────────────────────────────────── +# These match benchmark/docker-compose.yml +PG_USER = "root" +PG_PASSWORD = "123123" +PG_HOST = "localhost" # Docker maps container port to host +PG_PORT = 5534 # docker-compose maps 5534 -> 5432 +DB_TEMPLATE_SUFFIX = "_template" + +# ─── Engine cache ──────────────────────────────────────────────────────────── +_engine_cache: Dict[str, Engine] = {} + + +def get_engine(db_name: str) -> Engine: + """Get or create a SQLAlchemy engine for the given database.""" + if db_name not in _engine_cache: + url = f"postgresql://{PG_USER}:{PG_PASSWORD}@{PG_HOST}:{PG_PORT}/{db_name}" + _engine_cache[db_name] = create_engine(url, pool_size=3, max_overflow=5) + return _engine_cache[db_name] + + +def check_db_exists(db_name: str) -> bool: + """Check if a database exists on the PostgreSQL server.""" + try: + engine = get_engine("postgres") + with engine.connect() as conn: + result = conn.execute( + text("SELECT 1 FROM pg_database WHERE datname = :name"), + {"name": db_name}, + ) + return result.fetchone() is not None + except Exception as e: + print(f" ⚠ Could not check database '{db_name}': {e}") + return False + + +def run_preprocess_sql(db_name: str, preprocess_sqls: List[str]) -> bool: + """Run preprocess SQL statements on the given database. Returns True on success.""" + if not preprocess_sqls: + return True + try: + engine = get_engine(db_name) + with engine.connect() as conn: + for sql_stmt in preprocess_sqls: + if not sql_stmt or not sql_stmt.strip(): + continue + try: + conn.execute(text(sql_stmt)) + except Exception as e: + # Some preprocess SQL may fail (e.g. DROP IF EXISTS on non-existing) + # That's generally fine — continue with the rest + pass + conn.commit() + return True + except Exception as e: + return False + + +def run_cleanup_sql(db_name: str, cleanup_sqls: List[str]) -> None: + """Run cleanup SQL statements to restore DB state.""" + if not cleanup_sqls: + return + try: + engine = get_engine(db_name) + with engine.connect() as conn: + for sql_stmt in cleanup_sqls: + if not sql_stmt or not sql_stmt.strip(): + continue + try: + conn.execute(text(sql_stmt)) + except Exception: + pass + conn.commit() + except Exception: + pass + + +def check_docker_connection() -> bool: + """Verify we can connect to the Docker PostgreSQL instance.""" + try: + engine = get_engine("postgres") + with engine.connect() as conn: + result = conn.execute(text("SELECT 1")) + result.fetchone() + print("✓ Connected to Docker PostgreSQL") + return True + except Exception as e: + print(f"✗ Cannot connect to Docker PostgreSQL at {PG_HOST}:{PG_PORT}") + print(f" Error: {e}") + print(f"\n Please start Docker containers first:") + print(f" cd benchmark && docker-compose up -d") + print(f" # Wait for healthy status, then retry") + return False + + +# ─── Main runner ───────────────────────────────────────────────────────────── + + +def run_benchmark( + data_path: str, + output_path: str, + limit: Optional[int] = None, +) -> None: + """Run all issue_sql queries through validate_with_db with live DB.""" + + # Check Docker connection first + if not check_docker_connection(): + sys.exit(1) + + # Load data + print(f"Loading data from {data_path}...") + with open(data_path, "r") as f: + entries = [json.loads(line) for line in f] + + if limit: + entries = entries[:limit] + + # Get unique db_ids and check which template databases exist + db_ids = sorted(set(e["db_id"] for e in entries)) + print(f"Loaded {len(entries)} entries across {len(db_ids)} databases") + + available_dbs: Dict[str, str] = {} # db_id -> actual db name to connect to + for db_id in db_ids: + # Prefer the real (writable) database — templates are read-only + if check_db_exists(db_id): + available_dbs[db_id] = db_id + print(f" ✓ {db_id} -> {db_id}") + else: + template_name = f"{db_id}{DB_TEMPLATE_SUFFIX}" + if check_db_exists(template_name): + available_dbs[db_id] = template_name + print(f" ✓ {db_id} -> {template_name} (template, read-only)") + else: + print(f" ✗ {db_id} -> NOT FOUND (skipping)") + + print(f"\nAvailable databases: {len(available_dbs)}/{len(db_ids)}") + if not available_dbs: + print("No databases available! Exiting.") + sys.exit(1) + + # Run validation + results: List[dict] = [] + error_count = 0 + valid_count = 0 + skip_count = 0 + exception_count = 0 + + for i, entry in enumerate(entries): + instance_id = entry.get("instance_id", f"entry_{i}") + db_id = entry["db_id"] + category = entry.get("category", "unknown") + issue_sqls = entry.get("issue_sql", []) + preprocess_sqls = entry.get("preprocess_sql", []) + cleanup_sqls = entry.get("clean_up_sql", []) + + # Skip multi-query entries (16 entries have >1 issue_sql) + if len(issue_sqls) > 1: + continue + + if db_id not in available_dbs: + skip_count += len(issue_sqls) if issue_sqls else 1 + continue + + actual_db = available_dbs[db_id] + + # Run preprocess SQL if any + run_preprocess_sql(actual_db, preprocess_sqls) + + # Invalidate live schema cache after preprocess_sql may have created + # new tables — forces re-reflection on the next validate_with_db call + if preprocess_sqls: + invalidate_schema_cache(get_engine(actual_db)) + + for sql_idx, sql in enumerate(issue_sqls): + if not sql or not sql.strip(): + continue + + try: + engine = get_engine(actual_db) + result = validate_with_db(sql, engine) + except Exception as exc: + exception_count += 1 + results.append( + { + "instance_id": instance_id, + "db_id": db_id, + "category": category, + "sql_index": sql_idx, + "sql": sql[:500], + "valid": None, + "exception": str(exc)[:200], + "errors": [], + "tags": [], + } + ) + continue + + if result.valid: + valid_count += 1 + else: + error_count += 1 + + entry_result = { + "instance_id": instance_id, + "db_id": db_id, + "category": category, + "sql_index": sql_idx, + "sql": sql[:500], + "valid": result.valid, + "errors": [e.to_dict() for e in result.errors], + "tags": [t.value for t in result.tags], + } + + if result.query_metadata: + entry_result["query_metadata"] = result.query_metadata.to_dict() + + results.append(entry_result) + + # Run cleanup SQL to restore DB state + run_cleanup_sql(actual_db, cleanup_sqls) + + # Progress + if (i + 1) % 50 == 0: + print(f" Processed {i + 1}/{len(entries)} entries...") + + # ── Summary stats ──────────────────────────────────────────────────────── + total = valid_count + error_count + exception_count + print(f"\n{'=' * 60}") + print(f"VALIDATE_WITH_DB BENCHMARK RESULTS") + print(f"{'=' * 60}") + print(f"Total SQL queries: {total}") + print(f" Valid (no errors): {valid_count}") + print(f" Invalid (has errors): {error_count}") + print(f" Exceptions: {exception_count}") + print(f" Skipped (no DB): {skip_count}") + print(f"{'=' * 60}") + + # Error breakdown by tag + tag_counts: Dict[str, int] = {} + for r in results: + for tag in r.get("tags", []): + tag_counts[tag] = tag_counts.get(tag, 0) + 1 + + if tag_counts: + print(f"\nError Tag Distribution:") + for tag, count in sorted(tag_counts.items(), key=lambda x: -x[1]): + print(f" {tag:45s} {count:>4d}") + + # Per-database breakdown + db_error_counts: Dict[str, List[int]] = {} + for r in results: + db = r["db_id"] + if db not in db_error_counts: + db_error_counts[db] = [0, 0] + if r.get("valid") is True: + db_error_counts[db][0] += 1 + elif r.get("valid") is False: + db_error_counts[db][1] += 1 + + print(f"\nPer-Database Breakdown:") + print(f" {'Database':<35s} {'Valid':>6s} {'Invalid':>8s}") + print(f" {'-' * 35} {'-' * 6} {'-' * 8}") + for db in sorted(db_error_counts.keys()): + v, inv = db_error_counts[db] + print(f" {db:<35s} {v:>6d} {inv:>8d}") + + # Per-category breakdown + cat_counts: Dict[str, List[int]] = {} + for r in results: + cat = r.get("category", "unknown") + if cat not in cat_counts: + cat_counts[cat] = [0, 0] + if r.get("valid") is True: + cat_counts[cat][0] += 1 + elif r.get("valid") is False: + cat_counts[cat][1] += 1 + + print(f"\nPer-Category Breakdown:") + print(f" {'Category':<25s} {'Valid':>6s} {'Invalid':>8s}") + print(f" {'-' * 25} {'-' * 6} {'-' * 8}") + for cat in sorted(cat_counts.keys()): + v, inv = cat_counts[cat] + print(f" {cat:<25s} {v:>6d} {inv:>8d}") + + # ── Comparison with static validation ──────────────────────────────────── + print(f"\n{'=' * 60}") + print(f"COMPARISON: Static validate() vs validate_with_db()") + print(f"{'=' * 60}") + print(f"{'Metric':<30s} {'Static':>10s} {'With DB':>10s}") + print(f"{'-' * 30} {'-' * 10} {'-' * 10}") + + # Load static results if they exist + static_path = output_path.replace("validate_with_db_", "validator_") + if os.path.exists(static_path): + with open(static_path) as f: + static_data = json.load(f) + s = static_data["summary"] + print(f"{'Valid queries':<30s} {s['valid']:>10d} {valid_count:>10d}") + print(f"{'Invalid queries':<30s} {s['invalid']:>10d} {error_count:>10d}") + + static_tags = s.get("tag_distribution", {}) + all_tags = sorted(set(list(static_tags.keys()) + list(tag_counts.keys()))) + print(f"\n{'Tag':<45s} {'Static':>8s} {'With DB':>8s} {'Δ':>6s}") + print(f"{'-' * 45} {'-' * 8} {'-' * 8} {'-' * 6}") + for tag in all_tags: + sc = static_tags.get(tag, 0) + dc = tag_counts.get(tag, 0) + delta = dc - sc + sign = "+" if delta > 0 else "" + print(f" {tag:<43s} {sc:>8d} {dc:>8d} {sign}{delta:>5d}") + else: + print( + f" (Static results not found at {static_path} — run run_validator_benchmark.py first)" + ) + + # ── Save full results ──────────────────────────────────────────────────── + output = { + "summary": { + "total_queries": total, + "valid": valid_count, + "invalid": error_count, + "exceptions": exception_count, + "skipped": skip_count, + "tag_distribution": tag_counts, + "per_database": { + db: {"valid": v, "invalid": inv} + for db, (v, inv) in db_error_counts.items() + }, + "per_category": { + cat: {"valid": v, "invalid": inv} + for cat, (v, inv) in cat_counts.items() + }, + }, + "results": results, + } + + os.makedirs(os.path.dirname(output_path), exist_ok=True) + with open(output_path, "w") as f: + json.dump(output, f, indent=2, default=str) + + print(f"\nFull results saved to: {output_path}") + + # Save errors-only + error_results = [r for r in results if r.get("valid") is False] + error_output_path = output_path.replace(".json", "_errors_only.json") + with open(error_output_path, "w") as f: + json.dump(error_results, f, indent=2, default=str) + + print(f"Errors-only file saved to: {error_output_path}") + print(f"({len(error_results)} entries with errors)") + + +if __name__ == "__main__": + data_file = str(ROOT / "benchmark" / "data" / "postgresql_full.jsonl") + output_file = str( + ROOT / "tests" / "output" / "validate_with_db_benchmark_results.json" + ) + + run_benchmark(data_file, output_file) diff --git a/tests/run_validator_benchmark.py b/tests/run_validator_benchmark.py new file mode 100644 index 0000000..7708e62 --- /dev/null +++ b/tests/run_validator_benchmark.py @@ -0,0 +1,299 @@ +# -*- coding: utf-8 -*- +""" +Run all issue_sql queries from postgresql_full.jsonl through the validator. + +Usage: + cd sequel2sql + uv run python tests/run_validator_benchmark.py + +Outputs results to tests/output/validator_benchmark_results.json +""" + +import json +import os +import re +import sys +from pathlib import Path +from typing import Dict, List, Optional, Tuple + +# Add src to path so ast_parsers is importable +ROOT = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT / "src")) + +from ast_parsers.validator import validate +from ast_parsers.result import ValidationResult + + +# ─── Schema parser ─────────────────────────────────────────────────────────── + + +def parse_schema_from_ddl(ddl_text: str) -> Dict[str, Dict[str, str]]: + """ + Parse CREATE TABLE statements from preprocess_schema text into + {table_name: {column_name: column_type}} dict. + + Handles quoted identifiers, DEFAULT clauses, FOREIGN KEY, PRIMARY KEY, etc. + Also catches CREATE TABLE AS SELECT, CREATE TEMP TABLE, IF NOT EXISTS, etc. + """ + schema: Dict[str, Dict[str, str]] = {} + + # ── Pass 1: Full column parsing for standard CREATE TABLE (columns) ────── + table_pattern = re.compile( + r'CREATE\s+TABLE\s+"?(\w+)"?\s*\((.*?)\);', + re.IGNORECASE | re.DOTALL, + ) + + for match in table_pattern.finditer(ddl_text): + table_name = match.group(1) + body = match.group(2) + columns: Dict[str, str] = {} + + for line in body.split("\n"): + line = line.strip().rstrip(",") + if not line: + continue + # Skip constraint lines + if re.match( + r"^\s*(PRIMARY\s+KEY|FOREIGN\s+KEY|UNIQUE|CHECK|CONSTRAINT)", + line, + re.IGNORECASE, + ): + continue + + # Parse: "column_name" type_name ... or column_name type_name ... + col_match = re.match( + r'"?(\w+)"?\s+([a-zA-Z][\w\s()]*?)(?:\s+(?:NOT\s+NULL|NULL|DEFAULT|PRIMARY|UNIQUE|REFERENCES|CHECK)|\s*$)', + line, + re.IGNORECASE, + ) + if col_match: + col_name = col_match.group(1) + col_type = col_match.group(2).strip() + columns[col_name] = col_type + + if columns: + schema[table_name] = columns + + # ── Pass 2: Broad catch-all for any CREATE TABLE variant ───────────────── + # Catches: CREATE TABLE AS SELECT, CREATE TEMP TABLE, CREATE TABLE IF NOT + # EXISTS, CREATE UNLOGGED TABLE, etc. Registers the table name with an + # empty column dict if not already parsed in pass 1. + broad_pattern = re.compile( + r'CREATE\s+(?:TEMP(?:ORARY)?\s+)?(?:UNLOGGED\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:"?(\w+)"?\.)?\"?(\w+)\"?', + re.IGNORECASE, + ) + for match in broad_pattern.finditer(ddl_text): + table_name = match.group(2) # group(1) is optional schema qualifier + if table_name and table_name.lower() not in {k.lower() for k in schema}: + schema[table_name] = {} + + # ── Pass 3: SELECT INTO creates a table too ────────────────────────────── + select_into_pattern = re.compile( + r'SELECT\s+.+?\s+INTO\s+(?:TEMP(?:ORARY)?\s+)?(?:TABLE\s+)?\"?(\w+)\"?', + re.IGNORECASE | re.DOTALL, + ) + for match in select_into_pattern.finditer(ddl_text): + table_name = match.group(1) + if table_name and table_name.lower() not in {k.lower() for k in schema}: + schema[table_name] = {} + + return schema + + +# ─── Main runner ───────────────────────────────────────────────────────────── + + +def run_benchmark_validation( + data_path: str, + output_path: str, + limit: Optional[int] = None, +) -> None: + """Run all issue_sql queries through the validator and save results.""" + + # Load data + print(f"Loading data from {data_path}...") + with open(data_path, "r") as f: + entries = [json.loads(line) for line in f] + + if limit: + entries = entries[:limit] + + print(f"Loaded {len(entries)} entries across {len(set(e['db_id'] for e in entries))} databases") + + # Parse schemas per db_id (cache to avoid re-parsing) + schema_cache: Dict[str, Dict[str, Dict[str, str]]] = {} + + results: List[dict] = [] + error_count = 0 + valid_count = 0 + parse_fail_count = 0 + + for i, entry in enumerate(entries): + instance_id = entry.get("instance_id", f"entry_{i}") + db_id = entry["db_id"] + category = entry.get("category", "unknown") + issue_sqls = entry.get("issue_sql", []) + + # Skip multi-query entries (16 entries have >1 issue_sql) + if len(issue_sqls) > 1: + continue + + # Parse schema if not cached + if db_id not in schema_cache: + ddl = entry.get("preprocess_schema", "") + schema_cache[db_id] = parse_schema_from_ddl(ddl) + + # Start with cached schema and merge tables from preprocess_sql + schema = dict(schema_cache[db_id]) + preprocess_sqls = entry.get("preprocess_sql", []) + if preprocess_sqls: + for ps in preprocess_sqls: + if ps and "CREATE" in ps.upper(): + extra_tables = parse_schema_from_ddl(ps) + schema.update(extra_tables) + + for sql_idx, sql in enumerate(issue_sqls): + if not sql or not sql.strip(): + continue + + try: + result = validate(sql, schema=schema) + except Exception as exc: + parse_fail_count += 1 + results.append({ + "instance_id": instance_id, + "db_id": db_id, + "category": category, + "sql_index": sql_idx, + "sql": sql[:200], + "valid": None, + "exception": str(exc)[:200], + "errors": [], + "tags": [], + }) + continue + + if result.valid: + valid_count += 1 + else: + error_count += 1 + + entry_result = { + "instance_id": instance_id, + "db_id": db_id, + "category": category, + "sql_index": sql_idx, + "sql": sql[:500], + "valid": result.valid, + "errors": [e.to_dict() for e in result.errors], + "tags": [t.value for t in result.tags], + } + + if result.query_metadata: + entry_result["query_metadata"] = result.query_metadata.to_dict() + + results.append(entry_result) + + # Progress + if (i + 1) % 50 == 0: + print(f" Processed {i + 1}/{len(entries)} entries...") + + # ── Summary stats ──────────────────────────────────────────────────────── + total = valid_count + error_count + parse_fail_count + print(f"\n{'='*60}") + print(f"VALIDATION RESULTS SUMMARY") + print(f"{'='*60}") + print(f"Total SQL queries: {total}") + print(f" Valid (no errors): {valid_count}") + print(f" Invalid (has errors): {error_count}") + print(f" Parse exceptions: {parse_fail_count}") + print(f"{'='*60}") + + # Error breakdown by tag + tag_counts: Dict[str, int] = {} + for r in results: + for tag in r.get("tags", []): + tag_counts[tag] = tag_counts.get(tag, 0) + 1 + + if tag_counts: + print(f"\nError Tag Distribution:") + for tag, count in sorted(tag_counts.items(), key=lambda x: -x[1]): + print(f" {tag:45s} {count:>4d}") + + # Error breakdown by db_id + db_error_counts: Dict[str, Tuple[int, int]] = {} # db_id -> (valid, invalid) + for r in results: + db = r["db_id"] + if db not in db_error_counts: + db_error_counts[db] = [0, 0] + if r.get("valid") is True: + db_error_counts[db][0] += 1 + elif r.get("valid") is False: + db_error_counts[db][1] += 1 + + print(f"\nPer-Database Breakdown:") + print(f" {'Database':<35s} {'Valid':>6s} {'Invalid':>8s}") + print(f" {'-'*35} {'-'*6} {'-'*8}") + for db in sorted(db_error_counts.keys()): + v, inv = db_error_counts[db] + print(f" {db:<35s} {v:>6d} {inv:>8d}") + + # Error breakdown by category + cat_counts: Dict[str, Tuple[int, int]] = {} + for r in results: + cat = r.get("category", "unknown") + if cat not in cat_counts: + cat_counts[cat] = [0, 0] + if r.get("valid") is True: + cat_counts[cat][0] += 1 + elif r.get("valid") is False: + cat_counts[cat][1] += 1 + + print(f"\nPer-Category Breakdown:") + print(f" {'Category':<25s} {'Valid':>6s} {'Invalid':>8s}") + print(f" {'-'*25} {'-'*6} {'-'*8}") + for cat in sorted(cat_counts.keys()): + v, inv = cat_counts[cat] + print(f" {cat:<25s} {v:>6d} {inv:>8d}") + + # ── Save full results ──────────────────────────────────────────────────── + output = { + "summary": { + "total_queries": total, + "valid": valid_count, + "invalid": error_count, + "parse_exceptions": parse_fail_count, + "tag_distribution": tag_counts, + "per_database": { + db: {"valid": v, "invalid": inv} + for db, (v, inv) in db_error_counts.items() + }, + "per_category": { + cat: {"valid": v, "invalid": inv} + for cat, (v, inv) in cat_counts.items() + }, + }, + "results": results, + } + + os.makedirs(os.path.dirname(output_path), exist_ok=True) + with open(output_path, "w") as f: + json.dump(output, f, indent=2, default=str) + + print(f"\nFull results saved to: {output_path}") + + # ── Also save just the errors to a separate file for quick review ──────── + error_results = [r for r in results if r.get("valid") is False] + error_output_path = output_path.replace(".json", "_errors_only.json") + with open(error_output_path, "w") as f: + json.dump(error_results, f, indent=2, default=str) + + print(f"Errors-only file saved to: {error_output_path}") + print(f"({len(error_results)} entries with errors)") + + +if __name__ == "__main__": + data_file = str(ROOT / "benchmark" / "data" / "postgresql_full.jsonl") + output_file = str(ROOT / "tests" / "output" / "validator_benchmark_results.json") + + run_benchmark_validation(data_file, output_file) diff --git a/tests/test_confirmed_fix_retrieval.py b/tests/test_confirmed_fix_retrieval.py new file mode 100644 index 0000000..1b17741 --- /dev/null +++ b/tests/test_confirmed_fix_retrieval.py @@ -0,0 +1,152 @@ +""" +Test that each of the first 50 entries in postgresql_full.jsonl can retrieve +its corresponding confirmed fix from the per-database ChromaDB instances. + +Uses the `query` field from postgresql_full.jsonl (the user's natural-language +question) as the search intent, queries ChromaDB directly (bypassing the 0.75 +similarity threshold in find_similar_confirmed_fixes), and checks whether the +seeded confirmed fix ranks as the top-1 result. + +Run: + cd + .venv/bin/python -m tests.test_confirmed_fix_retrieval +""" + +import json +import sys +from pathlib import Path + +# Ensure project root is on sys.path for direct script execution (e.g. uv run) +PROJECT_ROOT = Path(__file__).parent.parent +sys.path.insert(0, str(PROJECT_ROOT)) + +from src.db_confirmed_fixes.retriever import _get_collection # noqa: E402 + +# --------------------------------------------------------------------------- +# Paths +# --------------------------------------------------------------------------- + +BENCHMARK_DATA = PROJECT_ROOT / "benchmark" / "data" / "postgresql_full.jsonl" +CONFIRMED_FIXES = ( + PROJECT_ROOT / "src" / "db_confirmed_fixes" / "db_confirmed_fixes.json" +) + +# --------------------------------------------------------------------------- +# Load data +# --------------------------------------------------------------------------- + + +def load_benchmark_entries(limit: int = 50) -> list[dict]: + """Load the first `limit` entries from postgresql_full.jsonl.""" + entries = [] + with open(BENCHMARK_DATA, "r", encoding="utf-8") as f: + for i, line in enumerate(f): + if i >= limit: + break + entries.append(json.loads(line)) + return entries + + +def load_confirmed_fixes() -> dict[str, dict]: + """Load confirmed fixes keyed by instance_id.""" + with open(CONFIRMED_FIXES, "r", encoding="utf-8") as f: + fixes = json.load(f) + return {fix["instance_id"]: fix for fix in fixes} + + +# --------------------------------------------------------------------------- +# Test +# --------------------------------------------------------------------------- + + +def run_retrieval_test(): + benchmark_entries = load_benchmark_entries(50) + confirmed_fixes = load_confirmed_fixes() + + total = 0 + top1_hits = 0 + top4_hits = 0 + misses = [] + + print(f"Testing retrieval for {len(benchmark_entries)} benchmark entries...") + print("Querying ChromaDB directly (no similarity threshold)\n") + print( + f"{'ID':<18} {'DB':<25} {'Top-1 Sim':>10} {'Rank':>6} {'Status'}" + ) + print("-" * 85) + + for entry in benchmark_entries: + instance_id = entry["instance_id"] + db_id = entry["db_id"] + query_intent = entry["query"] # natural-language question from benchmark + + # Skip if no confirmed fix exists for this instance + if instance_id not in confirmed_fixes: + continue + + expected_fix = confirmed_fixes[instance_id] + expected_sql = expected_fix["corrected_sql"] + total += 1 + + # Query ChromaDB directly (bypasses the 0.75 threshold) + collection = _get_collection(db_id) + count = collection.count() + + if count == 0: + rank = -1 + top_sim = 0.0 + else: + results = collection.query( + query_texts=[query_intent], + n_results=min(4, count), + include=["documents", "metadatas", "distances"], + ) + + # Find rank of the expected fix + rank = -1 + top_sim = 0.0 + if results["distances"] and results["distances"][0]: + top_sim = 1.0 - results["distances"][0][0] # best match similarity + + for idx, meta in enumerate(results["metadatas"][0]): + if meta.get("corrected_sql") == expected_sql: + rank = idx + 1 + break + + if rank == 1: + top1_hits += 1 + status = "✓ TOP-1" + elif rank > 1: + top4_hits += 1 + status = f"~ RANK-{rank}" + else: + status = "✗ NOT IN TOP-4" + misses.append((instance_id, top_sim)) + + print( + f"{instance_id:<18} {db_id:<25} {top_sim:>10.4f} {rank:>6} {status}" + ) + + # Summary + print("-" * 85) + print(f"\n{'Metric':<35} {'Value':>10}") + print("-" * 45) + print(f"{'Total entries tested':<35} {total:>10}") + print(f"{'Top-1 hits (exact best match)':<35} {top1_hits:>10}") + print(f"{'Top-4 hits (in results)':<35} {top1_hits + top4_hits:>10}") + print(f"{'Not found in top-4':<35} {len(misses):>10}") + print(f"{'Top-1 accuracy':<35} {top1_hits / total * 100:>9.1f}%") + print(f"{'Top-4 recall':<35} {(top1_hits + top4_hits) / total * 100:>9.1f}%") + + if misses: + print(f"\nMissing from top-4 ({len(misses)}):") + for iid, sim in misses: + print(f" - {iid} (best sim: {sim:.4f})") + + return top1_hits, top4_hits, total + + +if __name__ == "__main__": + top1, top4, total = run_retrieval_test() + # Exit with non-zero if top-1 accuracy is below 80% + exit(0 if top1 / total >= 0.8 else 1) diff --git a/tests/test_database_con.py b/tests/test_database_con.py index a2613d3..ff8e4c6 100644 --- a/tests/test_database_con.py +++ b/tests/test_database_con.py @@ -82,7 +82,7 @@ def example_3_custom_connection(): deps = get_database_deps( database_name="formula_1_template", host="localhost", - port=5433, + port=5534, user="root", password="123123", max_return_values=100, # Return fewer results diff --git a/tests/test_skills_loading.py b/tests/test_skills_loading.py new file mode 100644 index 0000000..d5e41ae --- /dev/null +++ b/tests/test_skills_loading.py @@ -0,0 +1,64 @@ +""" +Tests for the pydantic-ai-skills SkillsToolset integration. + +Verifies skill discovery, loading, and the get_db_skill_hint() helper +without requiring a live database connection. +""" + +from pathlib import Path + +from pydantic_ai_skills import SkillsToolset + +SKILLS_DIR = Path(__file__).parent.parent / "src" / "skills" + + +def test_skill_discovery(): + """SkillsToolset discovers all expected skills in the skills directory.""" + toolset = SkillsToolset(directories=[str(SKILLS_DIR)]) + skill_names = list(toolset.skills.keys()) + assert "db-query" in skill_names, f"db-query skill not found. Found: {skill_names}" + assert "california-schools-template-semantic-model" in skill_names, ( + f"california-schools-template-semantic-model not found. Found: {skill_names}" + ) + + +def test_skill_loading(): + """Loading the california schools skill returns its full content.""" + toolset = SkillsToolset(directories=[str(SKILLS_DIR)]) + skill = toolset.get_skill("california-schools-template-semantic-model") + content = skill.content + assert "Key Concepts" in content + assert "Gotchas" in content + assert "Core Join Paths" in content + + +def test_base_skill_loading(): + """Loading the db-query base skill returns its content.""" + toolset = SkillsToolset(directories=[str(SKILLS_DIR)]) + skill = toolset.get_skill("db-query") + content = skill.content + assert "Safety Rules" in content + assert "Query Quality" in content + + +def test_db_skill_hint_present(): + """get_db_skill_hint returns a load_skill hint when a skill exists for the DB.""" + from src.agent.skills_config import get_db_skill_hint + hint = get_db_skill_hint("california_schools_template") + assert hint != "" + assert "load_skill" in hint + assert "california-schools-template-semantic-model" in hint + + +def test_db_skill_hint_absent(): + """get_db_skill_hint returns empty string when no skill exists for the DB.""" + from src.agent.skills_config import get_db_skill_hint + hint = get_db_skill_hint("nonexistent_db") + assert hint == "" + + +def test_agent_no_regression(): + """skills_config module imports cleanly and exposes expected names.""" + from src.agent.skills_config import get_db_skill_hint, skills_toolset + assert skills_toolset is not None + assert callable(get_db_skill_hint) diff --git a/tests/test_validator.py b/tests/test_validator.py index ca0e714..dfb39d7 100644 --- a/tests/test_validator.py +++ b/tests/test_validator.py @@ -2,23 +2,23 @@ """Tests for SQL validator and error context pipeline.""" import pytest +from ast_parsers.errors import SchemaErrorTags, SyntaxErrorTags + from ast_parsers import ( - validate_syntax, - validate_schema, - validate_query, - ValidationResult, - ValidationError, QueryMetadata, + ValidationError, + ValidationResult, + analyze_query, + calculate_complexity, extract_error_code, - get_taxonomy_category, - get_category_for_tag, extract_sql_clauses, - calculate_complexity, generate_pattern_signature, - analyze_query, + get_category_for_tag, + get_taxonomy_category, + validate_query, + validate_schema, + validate_syntax, ) -from ast_parsers.errors import SyntaxErrorTags, SchemaErrorTags - # ============================================================================= # Test Schema (from experimentation) @@ -40,15 +40,14 @@ class TestSyntaxValidation: - def test_valid_simple_query(self): """Valid SQL should pass syntax validation.""" result = validate_syntax("SELECT id, name FROM users WHERE id > 5") - + assert result.valid is True assert result.errors == [] assert result.ast is not None - + def test_valid_complex_query(self): """Complex valid SQL with joins should pass.""" sql = """ @@ -58,50 +57,50 @@ def test_valid_complex_query(self): WHERE o.amount > 100 """ result = validate_syntax(sql) - + assert result.valid is True assert result.ast is not None - + def test_trailing_comma(self): """Trailing comma before FROM should be detected.""" result = validate_syntax("SELECT id, name, FROM users") - + assert result.valid is False assert SyntaxErrorTags.TRAILING_DELIMITER in result.tags - + def test_unbalanced_parentheses(self): """Unbalanced parentheses should be detected.""" result = validate_syntax("SELECT count(* FROM users WHERE id = 1") - + assert result.valid is False assert SyntaxErrorTags.UNBALANCED_TOKENS in result.tags - + def test_unbalanced_closing_paren(self): """Extra closing parenthesis should be detected.""" result = validate_syntax("SELECT id FROM users WHERE id = 1)") - + assert result.valid is False assert SyntaxErrorTags.UNBALANCED_TOKENS in result.tags - + def test_keyword_misuse(self): """Misused keywords should be detected.""" result = validate_syntax("SELECT FROM users WHERE id") - + assert result.valid is False # Should have some error tag assert len(result.tags) > 0 - + def test_unterminated_string(self): """Unterminated string literals should be detected.""" result = validate_syntax("SELECT * FROM users WHERE name = 'John") - + assert result.valid is False assert SyntaxErrorTags.UNTERMINATED_STRING in result.tags - + def test_result_to_dict(self): """ValidationResult.to_dict() should work correctly.""" result = validate_syntax("SELECT id, name, FROM users") - + d = result.to_dict() assert "valid" in d assert "errors" in d @@ -113,49 +112,50 @@ def test_result_to_dict(self): # Part 2: Schema Validation Tests # ============================================================================= + class TestSchemaValidation: """Tests for validate_schema() - Part 2: Semantic Validation.""" - + def test_valid_query_with_schema(self): """Valid query against schema should pass.""" result = validate_schema( "SELECT id, name FROM users", schema=TEST_SCHEMA, ) - + assert result.valid is True assert result.errors == [] - + def test_hallucinated_table(self): """Non-existent table should be detected.""" result = validate_schema( "SELECT * FROM non_existent_table", schema=TEST_SCHEMA, ) - + assert result.valid is False assert SchemaErrorTags.HALLUCINATION_TABLE in result.tags assert "non_existent_table" in result.error_messages[0] - + def test_hallucinated_column(self): """Non-existent column should be detected.""" result = validate_schema( "SELECT address FROM users", schema=TEST_SCHEMA, ) - + assert result.valid is False assert SchemaErrorTags.HALLUCINATION_COLUMN in result.tags - + def test_valid_join_query(self): """Valid join query should pass schema validation.""" result = validate_schema( "SELECT users.id, orders.amount FROM users JOIN orders ON users.id = orders.user_id", schema=TEST_SCHEMA, ) - + assert result.valid is True - + def test_ambiguous_column_in_join(self): """Ambiguous column in join should be detected.""" # Both users and orders could have columns that need qualification @@ -168,68 +168,70 @@ def test_ambiguous_column_in_join(self): "SELECT id FROM users JOIN orders ON users.id = orders.user_id", schema=schema_with_ambiguity, ) - + # Should either fail with ambiguous or require qualification # The exact behavior depends on sqlglot version if not result.valid: - assert SchemaErrorTags.AMBIGUOUS_COLUMN in result.tags or len(result.errors) > 0 - + assert ( + SchemaErrorTags.AMBIGUOUS_COLUMN in result.tags + or len(result.errors) > 0 + ) + def test_case_insensitive_table_names(self): """Table name matching should be case-insensitive.""" result = validate_schema( "SELECT id FROM USERS", # uppercase schema=TEST_SCHEMA, # lowercase keys ) - + assert result.valid is True class TestValidateQuery: - def test_syntax_only_valid(self): """Valid syntax without schema should pass.""" result = validate_query("SELECT * FROM any_table") - + assert result.valid is True - + def test_syntax_only_invalid(self): """Invalid syntax without schema should fail.""" result = validate_query("SELECT id, FROM users") - + assert result.valid is False assert SyntaxErrorTags.TRAILING_DELIMITER in result.tags - + def test_with_schema_valid(self): """Valid query with schema should pass both stages.""" result = validate_query( "SELECT id, name FROM users", schema=TEST_SCHEMA, ) - + assert result.valid is True - + def test_syntax_error_stops_schema_validation(self): """Syntax errors should prevent schema validation.""" result = validate_query( "SELECT id, FROM users", # syntax error schema=TEST_SCHEMA, ) - + assert result.valid is False # Should have syntax error, not schema error assert SyntaxErrorTags.TRAILING_DELIMITER in result.tags assert SchemaErrorTags.HALLUCINATION_TABLE not in result.tags - + def test_schema_error_after_syntax_passes(self): """Schema errors should be caught after syntax passes.""" result = validate_query( "SELECT nonexistent_column FROM users", schema=TEST_SCHEMA, ) - + assert result.valid is False assert SchemaErrorTags.HALLUCINATION_COLUMN in result.tags - + def test_dialect_parameter(self): """Dialect parameter should be respected.""" # Test with MySQL-specific syntax @@ -237,34 +239,34 @@ def test_dialect_parameter(self): "SELECT `id` FROM users", # backticks are MySQL style dialect="mysql", ) - + assert result.valid is True class TestEdgeCases: """Tests for edge cases and error classification.""" - + def test_empty_query(self): """Empty query should fail gracefully.""" result = validate_syntax("") - + assert result.valid is False - + def test_whitespace_only_query(self): """Whitespace-only query should fail gracefully.""" result = validate_syntax(" \n\t ") - + assert result.valid is False - + def test_multiple_statements(self): """Query with multiple statements should be handled.""" # sqlglot.parse_one expects single statement result = validate_syntax("SELECT 1; SELECT 2;") - + # Behavior depends on sqlglot version - may fail or parse first only # Just ensure it doesn't crash assert isinstance(result, ValidationResult) - + def test_cte_query(self): """CTE (WITH clause) should parse correctly.""" sql = """ @@ -277,17 +279,17 @@ def test_cte_query(self): FROM regional_sales """ result = validate_syntax(sql) - + assert result.valid is True - + def test_subquery(self): """Subqueries should parse correctly.""" result = validate_syntax( "SELECT * FROM users WHERE id IN (SELECT user_id FROM orders)" ) - + assert result.valid is True - + def test_validation_error_to_dict(self): """ValidationError.to_dict() should work correctly.""" error = ValidationError( @@ -296,7 +298,7 @@ def test_validation_error_to_dict(self): location=42, context="test context", ) - + d = error.to_dict() assert d["tag"] == "test_tag" assert d["message"] == "Test message" @@ -308,27 +310,28 @@ def test_validation_error_to_dict(self): # Error Code Extraction and Taxonomy Tests # ============================================================================= + class TestErrorCodes: """Tests for error code extraction and taxonomy mapping.""" - + def test_extract_error_code_from_message(self): """Should extract SQLSTATE codes from error messages.""" # Direct SQLSTATE format assert extract_error_code("ERROR: 42703: column 'x' does not exist") == "42703" assert extract_error_code("SQLSTATE 42P01") == "42P01" assert extract_error_code("[42702] ambiguous column") == "42702" - + def test_extract_error_code_from_pattern(self): """Should extract codes from error message patterns.""" assert extract_error_code("column reference is ambiguous") == "42702" assert extract_error_code("table users does not exist") == "42P01" assert extract_error_code("syntax error at or near") == "42601" assert extract_error_code("must appear in the GROUP BY clause") == "42803" - + def test_extract_error_code_not_found(self): """Should return None when no code can be extracted.""" assert extract_error_code("some random error message") is None - + def test_get_taxonomy_category(self): """Should map error codes to taxonomy categories.""" assert get_taxonomy_category("42601") == "syntax" @@ -337,7 +340,7 @@ def test_get_taxonomy_category(self): assert get_taxonomy_category("42P01") == "semantic" assert get_taxonomy_category("42P20") == "logical" assert get_taxonomy_category("UNKNOWN") is None - + def test_get_category_for_tag(self): """Should find category for error tags.""" assert get_category_for_tag("syntax_trailing_delimiter") == "syntax" @@ -348,18 +351,17 @@ def test_get_category_for_tag(self): class TestQueryAnalysis: - def test_extract_sql_clauses_simple(self): """Should extract clauses from simple query.""" result = validate_syntax("SELECT id, name FROM users WHERE id > 5") assert result.valid assert result.ast is not None - + clauses = extract_sql_clauses(result.ast) assert "SELECT" in clauses assert "FROM" in clauses assert "WHERE" in clauses - + def test_extract_sql_clauses_complex(self): """Should extract clauses from complex query.""" sql = """ @@ -375,7 +377,7 @@ def test_extract_sql_clauses_complex(self): result = validate_syntax(sql) assert result.valid assert result.ast is not None - + clauses = extract_sql_clauses(result.ast) assert "SELECT" in clauses assert "FROM" in clauses @@ -385,7 +387,7 @@ def test_extract_sql_clauses_complex(self): assert "HAVING" in clauses assert "ORDER" in clauses assert "LIMIT" in clauses - + def test_extract_sql_clauses_cte(self): """Should extract CTE clauses.""" sql = """ @@ -400,39 +402,39 @@ def test_extract_sql_clauses_cte(self): result = validate_syntax(sql) assert result.valid assert result.ast is not None - + clauses = extract_sql_clauses(result.ast) assert "WITH" in clauses or "CTE" in clauses - + def test_calculate_complexity_simple(self): """Should calculate complexity for simple query.""" result = validate_syntax("SELECT id FROM users") assert result.valid assert result.ast is not None - + complexity = calculate_complexity(result.ast) assert complexity == 0 # No joins, subqueries, etc. - + def test_calculate_complexity_with_join(self): """Should calculate complexity for query with join.""" sql = "SELECT u.name FROM users u JOIN orders o ON u.id = o.user_id" result = validate_syntax(sql) assert result.valid assert result.ast is not None - + complexity = calculate_complexity(result.ast) assert complexity >= 1 # At least one join - + def test_calculate_complexity_with_subquery(self): """Should calculate complexity for query with subquery.""" sql = "SELECT * FROM users WHERE id IN (SELECT user_id FROM orders)" result = validate_syntax(sql) assert result.valid assert result.ast is not None - + complexity = calculate_complexity(result.ast) assert complexity >= 1 # At least one subquery - + def test_calculate_complexity_with_cte(self): """Should calculate complexity for query with CTE.""" sql = """ @@ -442,22 +444,22 @@ def test_calculate_complexity_with_cte(self): result = validate_syntax(sql) assert result.valid assert result.ast is not None - + complexity = calculate_complexity(result.ast) assert complexity >= 2 # CTEs are weighted 2 - + def test_generate_pattern_signature(self): """Should generate pattern signature for query.""" result = validate_syntax("SELECT id FROM users WHERE id > 5") assert result.valid assert result.ast is not None - + signature = generate_pattern_signature(result.ast) assert isinstance(signature, str) assert len(signature) > 0 # Should contain main clauses assert "SELECT" in signature or "FROM" in signature - + def test_analyze_query(self): """Should perform complete query analysis.""" sql = """ @@ -470,7 +472,7 @@ def test_analyze_query(self): result = validate_syntax(sql) assert result.valid assert result.ast is not None - + metadata = analyze_query(result.ast) assert isinstance(metadata, QueryMetadata) assert metadata.complexity_score >= 0 @@ -484,32 +486,33 @@ def test_analyze_query(self): # Enhanced Error Fields Tests # ============================================================================= + class TestEnhancedErrorFields: """Tests for enhanced error fields (error_code, taxonomy_category, affected_clauses).""" - + def test_error_has_error_code(self): """Errors should have error_code field when available.""" result = validate_syntax("SELECT id, name, FROM users") assert not result.valid assert len(result.errors) > 0 - + # Error code may or may not be present depending on error message # But the field should exist error = result.errors[0] - assert hasattr(error, 'error_code') - assert hasattr(error, 'taxonomy_category') - assert hasattr(error, 'affected_clauses') - + assert hasattr(error, "error_code") + assert hasattr(error, "taxonomy_category") + assert hasattr(error, "affected_clauses") + def test_error_has_taxonomy_category(self): """Errors should have taxonomy_category field.""" result = validate_syntax("SELECT id, name, FROM users") assert not result.valid - + error = result.errors[0] # Should have taxonomy category (syntax errors should map to "syntax") if error.taxonomy_category: assert error.taxonomy_category in ["syntax", "semantic", "logical"] - + def test_schema_error_has_affected_clauses(self): """Schema errors should have affected_clauses.""" result = validate_schema( @@ -517,13 +520,13 @@ def test_schema_error_has_affected_clauses(self): schema=TEST_SCHEMA, ) assert not result.valid - + error = result.errors[0] - assert hasattr(error, 'affected_clauses') + assert hasattr(error, "affected_clauses") # Schema errors might affect SELECT or FROM clauses if error.affected_clauses: assert isinstance(error.affected_clauses, list) - + def test_error_to_dict_includes_new_fields(self): """Error.to_dict() should include new fields when present.""" error = ValidationError( @@ -533,7 +536,7 @@ def test_error_to_dict_includes_new_fields(self): taxonomy_category="semantic", affected_clauses=["SELECT", "FROM"], ) - + d = error.to_dict() assert d["error_code"] == "42703" assert d["taxonomy_category"] == "semantic" @@ -541,28 +544,27 @@ def test_error_to_dict_includes_new_fields(self): class TestQueryMetadata: - def test_valid_query_has_metadata(self): """Valid queries should have query metadata.""" result = validate_syntax("SELECT id, name FROM users WHERE id > 5") assert result.valid assert result.query_metadata is not None assert isinstance(result.query_metadata, QueryMetadata) - + def test_query_metadata_has_complexity(self): """Query metadata should include complexity score.""" result = validate_syntax("SELECT id FROM users") assert result.valid assert result.query_metadata is not None assert result.query_metadata.complexity_score >= 0 - + def test_query_metadata_has_signature(self): """Query metadata should include pattern signature.""" result = validate_syntax("SELECT id FROM users WHERE id > 5") assert result.valid assert result.query_metadata is not None assert len(result.query_metadata.pattern_signature) > 0 - + def test_query_metadata_has_clauses(self): """Query metadata should include list of clauses.""" result = validate_syntax("SELECT id FROM users WHERE id > 5") @@ -570,7 +572,7 @@ def test_query_metadata_has_clauses(self): assert result.query_metadata is not None assert isinstance(result.query_metadata.clauses_present, list) assert len(result.query_metadata.clauses_present) > 0 - + def test_query_metadata_counts(self): """Query metadata should include element counts.""" sql = """ @@ -583,18 +585,18 @@ def test_query_metadata_counts(self): assert result.query_metadata is not None assert result.query_metadata.num_joins >= 1 assert result.query_metadata.num_aggregations >= 1 - + def test_query_metadata_in_result_dict(self): """Query metadata should be included in result.to_dict().""" result = validate_syntax("SELECT id FROM users") assert result.valid - + d = result.to_dict() assert "query_metadata" in d assert d["query_metadata"] is not None assert "complexity_score" in d["query_metadata"] assert "pattern_signature" in d["query_metadata"] - + def test_schema_validation_has_metadata(self): """Schema validation results should also have metadata.""" result = validate_schema( @@ -609,6 +611,7 @@ def test_schema_validation_has_metadata(self): # ErrorContext pipeline tests (build_error_context, extract_diagnostics) # ============================================================================= + class TestErrorContextPipeline: """Tests for build_error_context and extract_diagnostics.""" @@ -633,13 +636,16 @@ def __str__(self): ctx = build_error_context("SELECT x FROM t", error=FakeError()) assert ctx.sql == "SELECT x FROM t" # May get 42703 from regex; tags should have source and confidence - assert all(hasattr(t, "tag") and hasattr(t, "source") and hasattr(t, "confidence") for t in ctx.tags) + assert all( + hasattr(t, "tag") and hasattr(t, "source") and hasattr(t, "confidence") + for t in ctx.tags + ) if ctx.tags: assert all(0 <= t.confidence <= 1 for t in ctx.tags) def test_build_error_context_to_dict(self): """ErrorContext.to_dict() includes sql, sqlstate, diagnostics, tags.""" - from ast_parsers import build_error_context, ErrorContext, Diagnostics + from ast_parsers import Diagnostics, ErrorContext, build_error_context ctx = build_error_context("SELECT 1", error=None) d = ctx.to_dict() @@ -673,7 +679,11 @@ def test_tag_with_provenance_to_dict(self): """TagWithProvenance.to_dict() has tag, source, confidence.""" from ast_parsers import TagWithProvenance - t = TagWithProvenance(tag="schema_hallucination_col", source="pg_diag.column_name", confidence=0.95) + t = TagWithProvenance( + tag="schema_hallucination_col", + source="pg_diag.column_name", + confidence=0.95, + ) d = t.to_dict() assert d["tag"] == "schema_hallucination_col" assert d["source"] == "pg_diag.column_name" diff --git a/tests/test_validator_fixes.py b/tests/test_validator_fixes.py new file mode 100644 index 0000000..18f2bdf --- /dev/null +++ b/tests/test_validator_fixes.py @@ -0,0 +1,293 @@ +# -*- coding: utf-8 -*- +"""Focused tests for the 5 validator fixes in _check_schema and validate_with_db.""" + +import pytest + +from ast_parsers.result import ValidationError, ValidationResult +from ast_parsers.tags import ErrorTag +from ast_parsers.validator import validate, _check_schema + + +# Schema shared across tests +SCHEMA = { + "users": {"id": "int", "name": "text", "email": "text"}, + "orders": {"id": "int", "user_id": "int", "amount": "decimal", "status": "text"}, + "products": {"id": "int", "name": "text", "price": "decimal"}, +} + + +# ============================================================================= +# Fix 2 & 3: CTE column handling +# ============================================================================= + + +class TestCTEColumnHandling: + """Tests for CTE-derived and CTE-internal column handling.""" + + def test_cte_output_column_not_flagged(self): + """Unqualified column from CTE output should NOT be flagged as hallucinated.""" + sql = """ + WITH revenue AS ( + SELECT user_id, SUM(amount) AS total_rev + FROM orders + GROUP BY user_id + ) + SELECT total_rev FROM revenue + """ + result = validate(sql, schema=SCHEMA) + halluc_cols = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + ] + assert halluc_cols == [], ( + f"CTE-output column 'total_rev' should not be flagged: {halluc_cols}" + ) + + def test_cte_internal_column_not_checked(self): + """Columns inside CTE definitions should not be schema-checked.""" + # 'computed_field' doesn't exist anywhere but is an alias inside the CTE + sql = """ + WITH enriched AS ( + SELECT id, name || ' <' || email || '>' AS computed_field + FROM users + ) + SELECT computed_field FROM enriched + """ + result = validate(sql, schema=SCHEMA) + halluc_cols = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + ] + assert halluc_cols == [], ( + f"CTE-internal computed columns should not be flagged: {halluc_cols}" + ) + + def test_cte_with_base_table_columns_still_checked(self): + """When query has CTEs plus base table refs, base table columns are still checked.""" + sql = """ + WITH top_users AS ( + SELECT user_id FROM orders GROUP BY user_id + ) + SELECT nonexistent_col FROM users + WHERE id IN (SELECT user_id FROM top_users) + """ + result = validate(sql, schema=SCHEMA) + halluc_cols = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + ] + assert len(halluc_cols) >= 1, ( + "Hallucinated column 'nonexistent_col' against base table 'users' should be caught" + ) + + def test_nested_cte_columns_not_flagged(self): + """Nested CTEs referencing each other should not produce false positives.""" + sql = """ + WITH step1 AS ( + SELECT user_id, SUM(amount) AS total + FROM orders + GROUP BY user_id + ), + step2 AS ( + SELECT total FROM step1 WHERE total > 100 + ) + SELECT total FROM step2 + """ + result = validate(sql, schema=SCHEMA) + halluc_cols = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + ] + assert halluc_cols == [], ( + f"Nested CTE columns should not be flagged: {halluc_cols}" + ) + + def test_cte_alias_not_flagged_as_missing_table(self): + """CTE names should not be flagged as missing tables.""" + sql = """ + WITH my_cte AS (SELECT id FROM users) + SELECT id FROM my_cte + """ + result = validate(sql, schema=SCHEMA) + halluc_tables = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_TABLE + ] + assert halluc_tables == [], ( + f"CTE alias 'my_cte' should not be flagged as missing table: {halluc_tables}" + ) + + +# ============================================================================= +# Fix 4: Ambiguous column detection +# ============================================================================= + + +class TestAmbiguousColumnDetection: + """Tests for ambiguous column detection in _check_schema.""" + + def test_ambiguous_column_in_join(self): + """Unqualified column existing in multiple joined tables should be flagged.""" + # Both 'users' and 'orders' have 'id' + sql = "SELECT id FROM users JOIN orders ON users.id = orders.user_id" + result = validate(sql, schema=SCHEMA) + ambig_errors = [ + e for e in result.errors + if e.tag == ErrorTag.AMBIGUOUS_COLUMN + ] + assert len(ambig_errors) >= 1, ( + "Unqualified 'id' in JOIN of users+orders should be flagged as ambiguous" + ) + + def test_qualified_column_not_ambiguous(self): + """Qualified column reference should NOT be flagged as ambiguous.""" + sql = "SELECT users.id FROM users JOIN orders ON users.id = orders.user_id" + result = validate(sql, schema=SCHEMA) + ambig_errors = [ + e for e in result.errors + if e.tag == ErrorTag.AMBIGUOUS_COLUMN + ] + assert ambig_errors == [], ( + f"Qualified 'users.id' should not be ambiguous: {ambig_errors}" + ) + + def test_unique_column_not_ambiguous(self): + """Column existing in only one table should not be flagged.""" + sql = "SELECT email FROM users JOIN orders ON users.id = orders.user_id" + result = validate(sql, schema=SCHEMA) + ambig_errors = [ + e for e in result.errors + if e.tag == ErrorTag.AMBIGUOUS_COLUMN + ] + assert ambig_errors == [], ( + f"'email' only exists in users, should not be ambiguous: {ambig_errors}" + ) + + def test_ambiguous_name_across_three_tables(self): + """Column 'name' exists in users and products — flagged when both joined.""" + sql = """ + SELECT name + FROM users + JOIN products ON users.id = products.id + """ + result = validate(sql, schema=SCHEMA) + ambig_errors = [ + e for e in result.errors + if e.tag == ErrorTag.AMBIGUOUS_COLUMN + ] + assert len(ambig_errors) >= 1, ( + "'name' exists in both users and products, should be ambiguous" + ) + + +# ============================================================================= +# Fix 5: Partial column check when some tables are missing +# ============================================================================= + + +class TestPartialColumnCheck: + """Tests that column checks still run for valid tables when others are missing.""" + + def test_missing_table_still_checks_valid_table_columns(self): + """One hallucinated table shouldn't prevent column checks on valid tables.""" + sql = """ + SELECT nonexistent_col + FROM users + JOIN fake_table ON users.id = fake_table.fk + """ + result = validate(sql, schema=SCHEMA) + + # Should have the missing table error + table_errors = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_TABLE + ] + assert len(table_errors) >= 1, "fake_table should be flagged as missing" + + # Should ALSO have the column error for nonexistent_col against users + col_errors = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + ] + assert len(col_errors) >= 1, ( + "nonexistent_col should be flagged even though fake_table is missing" + ) + + def test_missing_table_columns_not_checked(self): + """Columns qualified to a missing table should be skipped, not double-reported.""" + sql = "SELECT fake_table.some_col FROM users JOIN fake_table ON users.id = fake_table.fk" + result = validate(sql, schema=SCHEMA) + + # Missing table error should exist + table_errors = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_TABLE + ] + assert len(table_errors) >= 1 + + # Column error for fake_table.some_col should NOT exist (table already flagged) + col_errors = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_COLUMN + and "fake_table" in (e.context or "") + ] + assert col_errors == [], ( + f"Columns on missing table shouldn't be separately flagged: {col_errors}" + ) + + +# ============================================================================= +# Existing behavior preservation +# ============================================================================= + + +class TestExistingBehavior: + """Verify that existing correct behaviors are preserved after the fixes.""" + + def test_valid_simple_query(self): + result = validate("SELECT id, name FROM users", schema=SCHEMA) + assert result.valid is True + assert result.errors == [] + + def test_valid_join_query(self): + sql = "SELECT users.name, orders.amount FROM users JOIN orders ON users.id = orders.user_id" + result = validate(sql, schema=SCHEMA) + assert result.valid is True + + def test_hallucinated_table_still_caught(self): + result = validate("SELECT * FROM nonexistent", schema=SCHEMA) + assert result.valid is False + tags = [e.tag for e in result.errors] + assert ErrorTag.HALLUCINATION_TABLE in tags + + def test_hallucinated_column_still_caught(self): + result = validate("SELECT address FROM users", schema=SCHEMA) + assert result.valid is False + tags = [e.tag for e in result.errors] + assert ErrorTag.HALLUCINATION_COLUMN in tags + + def test_syntax_error_still_caught(self): + result = validate("SELECT id, name, FROM users") + assert result.valid is False + tags = [e.tag for e in result.errors] + assert ErrorTag.TRAILING_DELIMITER in tags + + def test_subquery_alias_not_flagged(self): + sql = "SELECT sub.id FROM (SELECT id FROM users) AS sub" + result = validate(sql, schema=SCHEMA) + table_errors = [ + e for e in result.errors + if e.tag == ErrorTag.HALLUCINATION_TABLE + ] + assert table_errors == [], ( + f"Subquery alias 'sub' should not be flagged: {table_errors}" + ) + + def test_syntax_only_no_schema(self): + result = validate("SELECT * FROM any_table") + assert result.valid is True + assert result.errors == [] + + +if __name__ == "__main__": + pytest.main([__file__, "-v"]) diff --git a/uv.lock b/uv.lock index 871fa25..9af5ffa 100644 --- a/uv.lock +++ b/uv.lock @@ -3084,6 +3084,20 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/5c/35/f4a7fd2b9962ddb9b021f76f293e74fda71da190bb74b57ed5b343c93022/pydantic_ai-1.56.0-py3-none-any.whl", hash = "sha256:b6b3ac74bdc004693834750da4420ea2cde0d3cbc3f134c0b7544f98f1c00859", size = 7222, upload-time = "2026-02-06T01:13:11.755Z" }, ] +[[package]] +name = "pydantic-ai-skills" +version = "0.4.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "pydantic-ai-slim" }, + { name = "pyyaml" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/11/2b/b2011be2e17a643dfcadc1dfb2ab0b26ef5bbe2185b9098d3ec98c7e87d2/pydantic_ai_skills-0.4.0.tar.gz", hash = "sha256:67803b71cc78672fd36f72c92b5f58210ad31102517e7fa5a33b16e5fc7bd5a8", size = 587348, upload-time = "2026-01-24T15:16:13.287Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/65/9c/152a243b87c9debf916fdac77b94d8e3b3633f56a31d2643cd84d0a25972/pydantic_ai_skills-0.4.0-py3-none-any.whl", hash = "sha256:f21cabc104537d4b2f3de6c23b16ad83110643cbe5f518ea4fe687fe1fa4a2ad", size = 31261, upload-time = "2026-01-24T15:16:11.273Z" }, +] + [[package]] name = "pydantic-ai-slim" version = "1.56.0" @@ -4013,6 +4027,7 @@ dependencies = [ { name = "psycopg2-binary" }, { name = "pydantic" }, { name = "pydantic-ai" }, + { name = "pydantic-ai-skills" }, { name = "pydantic-ai-slim", extra = ["google", "mistral", "web"] }, { name = "pyfiglet" }, { name = "pymysql" }, @@ -4033,6 +4048,11 @@ dev = [ { name = "pytest" }, ] +[package.dev-dependencies] +dev = [ + { name = "pytest" }, +] + [package.metadata] requires-dist = [ { name = "chromadb", specifier = ">=1.4.1" }, @@ -4046,6 +4066,7 @@ requires-dist = [ { name = "psycopg2-binary", specifier = ">=2.9.11" }, { name = "pydantic", specifier = ">=2.0.0" }, { name = "pydantic-ai", specifier = ">=1.51.0" }, + { name = "pydantic-ai-skills", specifier = ">=0.1.1" }, { name = "pydantic-ai-slim", extras = ["google", "mistral", "web"], specifier = ">=1.51.0" }, { name = "pyfiglet", specifier = ">=1.0.4" }, { name = "pymysql", specifier = ">=1.1.0" }, @@ -4064,6 +4085,9 @@ requires-dist = [ ] provides-extras = ["dev"] +[package.metadata.requires-dev] +dev = [{ name = "pytest", specifier = ">=9.0.2" }] + [[package]] name = "setuptools" version = "80.10.2"