# query-not-boolean

The query of an **[`isEventQlQueryTrue` precondition](/docs/eventsourcingdb/preconditions)** does **not return exactly one boolean**.

- **Route:** `write-events`
- **Description:** `/preconditions/<index>: query does not return exactly one boolean: it returned <result>`, with the place of the precondition in its list, counting from 0, and what the query returned instead: `more than one result`, `a value of another type`, or `no result`
- **Details:** **`precondition`**, the place of the precondition in its list, counting from 0.

## Why It Happens

An `isEventQlQueryTrue` precondition holds if its query returns **exactly one row**, and that row is `true`. The query runs, but returns something else: **one row per event**, since its projection uses no **[aggregation function](/docs/eventsourcingdb/eventql#aggregation-functions)**, as `PROJECT INTO e.type == 'io.eventsourcingdb.library.book-borrowed'` does, **no row at all**, since such a query found no event, or a **value that is not a boolean**, as `PROJECT INTO COUNT()` without a comparison returns.

## How to Fix It

Write the query so that it **always returns a single boolean**, by comparing an aggregation function with a value, as `PROJECT INTO COUNT() == 0` does. Sending the same request again does not help: whether a query without an aggregation function returns exactly one row depends on the events it finds.

## Example

For a write whose only precondition has the query `FROM e IN events WHERE e.subject == '/books/42' PROJECT INTO e.type == 'io.eventsourcingdb.library.book-borrowed'`, while `/books/42` has several events, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its `end` item:

```json
{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/query-not-boolean",
    "description": "/preconditions/0: query does not return exactly one boolean: it returned more than one result",
    "details": {
      "precondition": 0
    }
  }
}
```
