cockroachdb / cockroachdb/cockroach

Parser fails to parse quoted identifiers in FOR .. IN loop

Open
#148,985 1 comment 0 reactions 0 assignees View on GitHub
A-sql-plpgsql C-bug O-community T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

The `FOR .. IN` loop should allow for using quoted identifiers just like any other syntactic element, but it currently doesn't.

**To Reproduce**

This doesn't compile:

```sql
create procedure "proc_ForIndexedLoop"()
language plpgsql
as $$
begin
for "i" in 1 .. 10 loop
raise notice '%', "i";
end loop;
end;
$$
```

It fails with this error:

```
SQL Error [42703]: ERROR: column "i" does not exist
```

**Expected behavior**

It should compile just like in PostgreSQL. The workaround is to not quote the identifier:

```sql
create procedure "proc_ForIndexedLoop"()
language plpgsql
as $$
begin
for i in 1 .. 10 loop
raise notice '%', "i";
end loop;
end;
$$
```

**Environment:**
- CockroachDB version: CockroachDB CCL v25.2.1 (x86_64-pc-linux-gnu, built 2025/06/02 23:17:23, go1.23.7 X:nocoverageredesign)
- Server OS: Linux on Docker on Windows
- Client app: JDBC

Jira issue: CRDB-51911

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the SQL example and trace the parser entry point for quoted identifiers in a FOR .. IN loop. Compare it with the unquoted workaround and PostgreSQL behavior, then add coverage showing that the quoted procedure compiles and runs correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.