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

Union in view causes panic #3863

Open
asger-noer opened this issue Feb 26, 2025 · 0 comments
Open

Union in view causes panic #3863

asger-noer opened this issue Feb 26, 2025 · 0 comments
Labels
📚 mysql bug Something isn't working 🔧 golang

Comments

@asger-noer
Copy link

Version

1.28.0

What happened?

When trying to generate code for MySQL where there is a union view in the schema definition sqlc panics. It seems it can't in process the parentheses around the select statements.

Relevant log output

panic: interface conversion: ast.Node is *ast.SetOprSelectList, not *ast.SelectStmt

goroutine 7 [running]:
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convertSetOprSelectList(0x3ef96676f108?, 0xc0004e5880)
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/convert.go:1200 +0x4e5
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convertSetOprStmt(0xc0004d6a00?, 0xc0004e5810)
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/convert.go:1243 +0x31
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convert(0xc0004d6b30, {0x1d59f70?, 0xc0004e5810?})
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/convert.go:1776 +0x109f
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convertCreateViewStmt(0x8?, 0xc000277760)
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/convert.go:793 +0x5d
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convert(0xc0004d6b30, {0x1d58940?, 0xc000277760?})
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/convert.go:1563 +0x59d
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*Parser).Parse(0xc0001201a8, {0x1d39760?, 0xc000352960?})
	/home/runner/work/release-workflow/release-workflow/internal/engine/dolphin/parse.go:63 +0x1ee
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseCatalog(0xc0002c7200, {0xc0003874b0?, 0xc0003406e6?, 0x5?})
	/home/runner/work/release-workflow/release-workflow/internal/compiler/compile.go:42 +0x242
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseCatalog(...)
	/home/runner/work/release-workflow/release-workflow/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc0003406e6, 0x5}, ...}, ...)
	/home/runner/work/release-workflow/release-workflow/internal/cmd/generate.go:294 +0x1ce
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
	/home/runner/work/release-workflow/release-workflow/internal/cmd/process.go:107 +0x897
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.5.0/errgroup/errgroup.go:75 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.5.0/errgroup/errgroup.go:72 +0x96

Database schema

CREATE TABLE authors0 (
  id   int      PRIMARY KEY,
  name text     NOT NULL,
  bio  text
);

CREATE TABLE authors1 (
  id   int      PRIMARY KEY,
  name text     NOT NULL,
  bio  text
);

CREATE OR REPLACE VIEW `authors_union` AS 
(SELECT * FROM `authors0`)
UNION
(SELECT * FROM `authors1`);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors0
WHERE id = ? LIMIT 1;

-- name: ListAuthors :many
SELECT * FROM authors0
ORDER BY name;

-- name: CreateAuthor :exec
INSERT INTO authors0 (
  name, bio
) VALUES (
  ?, ?
);

-- name: DeleteAuthor :exec
DELETE FROM authors0
WHERE id = ?;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "mysql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/0578ccf36af3a339036348855d6db6dd12be2a08ca84434521772c51640af60e

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@asger-noer asger-noer added the bug Something isn't working label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql bug Something isn't working 🔧 golang
Projects
None yet
Development

No branches or pull requests

1 participant