Skip to content

Union in view causes panic #3863

Open
Open
@asger-noer

Description

@asger-noer

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

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