Skip to content

Panics when using UNION operator within IN operator#2139

@SRkuma

Description

@SRkuma

Version

1.17.2

What happened?

Generation fails even though the SQL is correct syntax.

Relevant log output

sqlc generate failed. panic: runtime error: index out of range [0] with length 0 goroutine 19 [running]: github.com/kyleconroy/sqlc/internal/compiler.paramSearch.Visit({{0x0, 0x0}, 0x0, 0xc00047a3a8, 0xc000467f50, 0xc00047a3c0,{0x0, 0x0},{0x0, 0x0}}, ...) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/find_params.go:197 +0xad5 github.com/kyleconroy/sqlc/internal/sql/astutils.Walk({0x1f73840?, 0xc00023bc70?},{0x1f6de80?, 0xc00023bbd0?}) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/sql/astutils/walk.go:21 +0x51 github.com/kyleconroy/sqlc/internal/sql/astutils.Walk({0x1f73840?, 0xc00023bc20?},{0x1f6e6c0?, 0xc0003c38c0?}) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/sql/astutils/walk.go:1818 +0x2972 github.com/kyleconroy/sqlc/internal/compiler.findParameters({0x1f6e6c0, 0xc0003c38c0}) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/find_params.go:14 +0x15e github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQuery(0xc0002dfc00,{0x1f6e460?, 0xc000472400?},{0xc0003ff680, 0x204},{{0x89?, 0xea?,{0x0?, 0x2?}}}) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/parse.go:76 +0x635 github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc0002dfc00,{{0xb0?, 0xc8?,{0x0?, 0x1?}}}) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/compile.go:108 +0x4df github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/engine.go:49 github.com/kyleconroy/sqlc/internal/cmd.parse({_, _},{_, _},{_, _},{{0xc000218fc6, 0x5},{0xc00030c8b0, 0x1, ...}, ...}, ...) /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:276 +0x25b github.com/kyleconroy/sqlc/internal/cmd.Generate.func1() /go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:213 +0x975 golang.org/x/sync/errgroup.(*Group).Go.func1() /go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x64 created by golang.org/x/sync/errgroup.(*Group).Go /go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:72 +0xa5

Database schema

-- Example queries for sqlcCREATETABLEauthors ( id intPRIMARY KEY, name textNOT NULL, bio text ); CREATETABLEbook1 ( author_id intPRIMARY KEY, name text, FOREIGN KEY (`author_id`) REFERENCES`authors` (`id`) ON DELETE CASCADE ); CREATETABLEbook2 ( author_id intPRIMARY KEY, name text, FOREIGN KEY (`author_id`) REFERENCES`authors` (`id`) ON DELETE CASCADE );

SQL queries

-- name: GetAuthors :manySELECT*FROM authors whereauthors.id not in (select author_id from book1 unionselect author_id from book2)

Configuration

{"version": "1","packages": [{"path": "db","engine": "mysql","schema": "query.sql","queries": "query.sql"}]}

Playground URL

https://play.sqlc.dev/p/af4016069178c0a6b6aa0836af1845909b60ba84ec3da78a616231ffd1ecca9f

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions