electric-sql / electric-sql/electric

Misleading error when using $1 parameter in where clause with subquery

Open
#3,143 0 comments 0 reactions 0 assignees View on GitHub
triage
Dominant language
TypeScript
Stars
10.4k
Forks
375
Avg merge
3d 1h
Merged PRs (30d)
18

Description

**Describe the bug**
When using a `where` clause with a subquery and a parameter placeholder (`$1`), Electric reports inconsistent errors depending on whether parameters are passed.

Example:

```ts
originUrl.searchParams.set(
"where",
"novel_id IN (SELECT id FROM novel WHERE author_id = $1)"
);
originUrl.searchParams.set("params[1]", user.id);
```

➡️ Response:

```json
{
"message": "Invalid request",
"errors": {
"where": [
"At location 0: parameter value for $1 was not used"
]
}
}
```

However, if I omit the `params[1]` value:

```ts
originUrl.searchParams.set(
"where",
"novel_id IN (SELECT id FROM novel WHERE author_id = $1)"
);
```

➡️ Response:

```json
{
"message": "Invalid request",
"errors": {
"where": [
"At location 52: parameter $1 was not provided"
]
}
}
```

---

**Expected behavior**
The second case (`$1` not provided) is correct: it should complain that `$1` is missing.
But the first case is misleading — the parameter **is provided**, yet the error incorrectly says “parameter value for \$1 was not used.”

[/discussions/2931]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.