Skip to content

[Bug]: ST05 panic on WITH INSERT subqueries #2039

@rtzll

Description

@rtzll

What happened?

With .sqruff:

[sqruff]
rules = all

And min.sql:

WITH a AS (SELECT 1 AS x),

b AS (SELECT 1 AS y)

INSERT INTO t2 (z)
SELECT 1
FROM (SELECT ROW_NUMBER() OVER () AS rn FROM a) AS x
INNER JOIN (SELECT ROW_NUMBER() OVER () AS rn FROM b) AS y
    ON x.rn = y.rn;

Linting panics:

$ sqruff lint min.sql

thread 'main' panicked at crates/lib/src/rules/structure/st05.rs:224:52:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
== [min.sql] FAIL
L:   1 | P:   1 | ???? | Unexpected exception. Could you open an issue at
                       | https://github.com/quarylabs/sqruff
The linter processed 1 file(s).
All Finished 📜 🎉

Version

v0.29.3

Checked in Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions