Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panics when using UNION operator within IN operator #2139

Closed
SRkuma opened this issue Mar 10, 2023 · 2 comments · Fixed by #3652
Closed

Panics when using UNION operator within IN operator #2139

SRkuma opened this issue Mar 10, 2023 · 2 comments · Fixed by #3652

Comments

@SRkuma
Copy link

SRkuma commented Mar 10, 2023

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 sqlc
CREATE TABLE authors (
  id   int PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);
CREATE TABLE book1 (
  author_id  int PRIMARY KEY,
  name text,
  FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON DELETE CASCADE
);
CREATE TABLE book2 (
  author_id  int PRIMARY KEY,
  name text,
  FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON DELETE CASCADE
);

SQL queries

-- name: GetAuthors :many
SELECT * FROM authors
where authors.id not in (select author_id from book1 union select 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

@SRkuma SRkuma added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 10, 2023
@kyleconroy kyleconroy added 📚 mysql 🔧 golang 💻 darwin panic and removed triage New issues that hasn't been reviewed labels Jun 7, 2023
Jille added a commit to Jille/sqlc that referenced this issue Oct 14, 2024
Jille added a commit to hexon/sqlc that referenced this issue Oct 14, 2024
@kyleconroy
Copy link
Collaborator

Thanks to @Jille this has been fixed on main

@SRkuma
Copy link
Author

SRkuma commented Nov 25, 2024

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants