Skip to main content
Database query engineering is the work of making an application get the right data, in the right shape, from a real database. It is not a SQL quiz, and the patch is usually not a standalone .sql file. The agent may also edit the application code that the production path already uses: an ORM method, a query builder, a manager or filterset, a migration etc. The database behind that code has a schema, indexes, types, and a distribution of rows. The caller cares about columns, duplicates, order, empty groups, and time. People hear “database task” and think of writing a SELECT. That is the shallow end, and many tasks never ask for raw SQL at all. The hard part is semantics: what a JOIN does to the row count, what “latest” means when rows tie, which rows a window actually includes. The real work is to understand the application, understand what the endpoint is for, then change the production code that path actually runs.

The task

An agent gets a real application repository and a live database in the sandbox. The problem statement describes a data requirement, and the agent has to change the production code that fetches that data so the application is right. It is the usual Ridges contract: a repo, a problem statement, a patch. Some tasks name the file or function to change and some do not. Your agent has to be able to trace a symptom to the code that issues the query.

The engines and the kinds of work

The engines in play are PostgreSQL and ClickHouse. Each problem names its own contract and scope; we do not publish a list of queries. The change may be ORM expressions, query-builder code, embedded SQL, or a schema or index migration. Expect three kinds of work:
  • Generation: write the production fetch path to meet a data requirement.
  • Fixing: correct application code that returns the wrong data.
  • Optimization: make a correct fetch path faster without changing its result.

A prompt is a starting point, not the whole job

What counts is tracing from the requirement through the schema, the code the application actually runs, and what the caller does with the result. Writing a private SQL snippet that never sits on that path, or matching the sample rows while getting the grain wrong, is a common way to fail. Correctness is the gate. On optimization tasks in particular, faster-and-wrong does not count. A few things about how tasks are checked:
  • Correctness is judged on data the task does not show. Matching the sample rows is not enough; the result has to be right on the grain, ties, and edge cases the visible data does not exercise.
  • Optimization tasks measure the database work the production path performs, not just whether tests pass. The effort should go into genuinely solving the problem, not into passing a hidden check.
  • The tests a task names are regression checks that already pass. They tell you what must keep working, not what the fix is. Passing them is necessary, not sufficient.
  • When a task bounds the change to one method, everything else in that file stays exactly as it is, including imports. Use only names the file already imports.

Allowed vs not

Optimizing for the niche is expected and rewarded: understanding schemas, joins, ORMs, and query performance, and fixing the code the application actually runs, is the skill. Specializing on engines, query layers, and kinds of query problems is the point. What is not allowed is recognizing a specific problem, repository, or database and applying a stored answer, or matching expected rows without getting the production path right. See Passing Pre-Screening.

Sample problems

Public sample tasks for this niche are in ridges-bench: six tasks, each tagged authoring, repair, or optimization, with a reference solution for after-the-fact inspection. Run one against your agent from the ridges-bench repository root:
The samples show the task format only. They come from one repository on PostgreSQL. The competition uses different repositories, both engines, and other languages and query layers, and differs in difficulty. Build for the niche, not for that codebase. See Testing your Agent Locally.