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

Delete query with join returns panic: expected range var error #3848

Open
wouthoekstra opened this issue Feb 17, 2025 · 0 comments
Open

Delete query with join returns panic: expected range var error #3848

wouthoekstra opened this issue Feb 17, 2025 · 0 comments
Labels

Comments

@wouthoekstra
Copy link

Version

1.28.0

What happened?

When generating a query with a delete statement that uses a join, sqlc returns this error:

panic: expected range var

The code itself works in my database if I run it native. I've made a simplified version of my database and query to show the issue.

Relevant log output

panic: expected range var

goroutine 7 [running]:
github.com/sqlc-dev/sqlc/internal/engine/dolphin.convertToRangeVarList(0xc00006aa40?, 0xc0004bb3b0)
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/engine/dolphin/utils.go:68 +0x328
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convertDeleteStmt(0xc00006aa40, 0xc000b93cc0)
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/engine/dolphin/convert.go:302 +0x90
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*cc).convert(0xc00006aa40, {0x1e8c7e0?, 0xc000b93cc0?})
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/engine/dolphin/convert.go:1557 +0x3e5
github.com/sqlc-dev/sqlc/internal/engine/dolphin.(*Parser).Parse(0xc0000a70f8, {0x1e692e0?, 0xc0007f14c0?})
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/engine/dolphin/parse.go:63 +0x205
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQueries(0xc000474008, {{0x0, 0x0, {0x0, 0x0}, 0x0, 0x0, 0x0, 0x0}})
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/compile.go:75 +0x24e
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc000438866, 0x5}, ...}, ...)
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/cmd/generate.go:322 +0x2dc
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
	/home/wout/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/cmd/process.go:107 +0x81a
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/wout/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
	/home/wout/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x96

Database schema

CREATE TABLE `conflicts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `currency_id` int(10) unsigned NOT NULL,
  `blockchain_id` int(10) unsigned NOT NULL,
  `reference` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
);

SQL queries

-- name: DeleteConflicts :execrows
DELETE conflicts
FROM conflicts
  JOIN (
      SELECT blockchain_id, reference
        FROM conflicts
    GROUP BY blockchain_id, reference
      HAVING COUNT(DISTINCT currency_id) = 1
  ) AS resolved_conflicts
    ON conflicts.blockchain_id = resolved_conflicts.blockchain_id
   AND conflicts.reference = resolved_conflicts.reference;

Configuration

version: "2"
cloud:
    organization: ""
    project: ""
    hostname: ""
sql:
  - schema: ./sql/schema.sql
    queries: ./sql/queries
    engine: mysql
    gen:
      go:
        package: sqlc
        out: ./_sqlc
        emit_json_tags: true
        emit_prepared_queries: false
        emit_interface: false
        emit_exact_table_names: true
overrides:
    go: null
plugins: []
rules: []
options: {}

Playground URL

https://play.sqlc.dev/p/8b36238bfbc667bc2478394d370938fdaad11bd2c82df63a5e59f17b699b24f0

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@wouthoekstra wouthoekstra added the bug Something isn't working label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant