Skip to content

panic: expected range var #1590

Closed
Closed

Description

@drhoden-fastly

Version

Other

What happened?

A previously filed bug. Was found again while attempting to perform an implicit JOIN with mysql.

Using version v1.13.0

Relevant log output

panic: expected range var

goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/engine/dolphin.(*cc).convertUpdateStmt(0x10?, 0xc0001ecc60)
	github.com/kyleconroy/sqlc/internal/engine/dolphin/convert.go:551 +0x5ad
github.com/kyleconroy/sqlc/internal/engine/dolphin.(*cc).convert(0xc000418600?, {0x5051910?, 0xc0001ecc60?})
	github.com/kyleconroy/sqlc/internal/engine/dolphin/convert.go:1722 +0xb73
github.com/kyleconroy/sqlc/internal/engine/dolphin.(*Parser).Parse(0xc00019a820, {0x5046aa0?, 0xc00003dca0?})
	github.com/kyleconroy/sqlc/internal/engine/dolphin/parse.go:63 +0x19d
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc0004cc000, {0x50?, {0x50?, 0xe7?, {0x0?, 0x1?}}})
	github.com/kyleconroy/sqlc/internal/compiler/compile.go:102 +0x3ad
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
	github.com/kyleconroy/sqlc/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {_, _}, {{0xc0002934b6, 0x5}, ...}, ...)
	github.com/kyleconroy/sqlc/internal/cmd/generate.go:262 +0x253
github.com/kyleconroy/sqlc/internal/cmd.Generate({0x504baa0, 0xc00019e008}, {0xc0?, 0x6b?}, {0xc000040004, 0x21}, {0x0?, 0x4c01500?}, {0x50469c0, 0xc00019a010})
	github.com/kyleconroy/sqlc/internal/cmd/generate.go:183 +0x7b4
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x5e32000, {0x4d52b07?, 0x0?, 0x0?})
	github.com/kyleconroy/sqlc/internal/cmd/cmd.go:144 +0x194
github.com/spf13/cobra.(*Command).execute(0x5e32000, {0x5ea5678, 0x0, 0x0})
	github.com/spf13/cobra@v1.4.0/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xc000370a00)
	github.com/spf13/cobra@v1.4.0/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.4.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	github.com/spf13/cobra@v1.4.0/command.go:895
github.com/kyleconroy/sqlc/internal/cmd.Do({0xc0001a8010, 0x1, 0x1}, {0x5046980?, 0xc00019a000}, {0x50469c0?, 0xc00019a008}, {0x50469c0?, 0xc00019a010})
	github.com/kyleconroy/sqlc/internal/cmd/cmd.go:47 +0x4ba
main.main()
	github.com/kyleconroy/sqlc/cmd/sqlc/main.go:10 +0x7a

Database schema

CREATE TABLE authors (
  name text NOT NULL, 
  deleted_at datetime NOT NULL,
  created_at datetime NOT NULL,
  updated_at datetime NOT NULL
);

CREATE TABLE books (
  is_amazing tinyint(1) NOT NULL,
  deleted_at datetime NOT NULL,
  created_at datetime NOT NULL,
  updated_at datetime NOT NULL
);

SQL queries

-- name: DeleteAuthor :exec
UPDATE authors, books
SET
  authors.deleted_at = now(),
  authors.updated_at = now()
WHERE books.is_amazing = 1
AND authors.name = sqlc.arg(name);

Configuration

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

Playground URL

https://play.sqlc.dev/p/9fc9f9695357e74d7f9f4050bda23c51999cd7bb07380ff3615b69b6a4f8428c

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on May 5, 2022
  2. j0holo commented on May 16, 2022

    @j0holo

    I have the same expected var range error with a double INNER JOIN UPDATE query.

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

  3. blampe commented on Jul 27, 2022

    @blampe

    I also see this with convertDeleteStmt, although I'm pointing to a migrations folder (golang-migrate) and I'm not sure how to easily identify which one is the culprit.

  4. ravayak commented on Apr 3, 2023

    @ravayak

    Same 'range var' problem here with this update query:

    UPDATE clients_homes_bills chb
    INNER JOIN `clients_homes`ch ON ch.ch_id = chb.chb_home_id
    INNER JOIN `clients` c ON c.client_id = ch.ch_client_id
    INNER JOIN `clients_installations` ci ON ci.ci_client_id = c.client_id
    SET chb.chb_electricity=?, chb.chb_natural_gas=?, chb.chb_propane_gas=?, chb.chb_wood=?, chb.chb_heating_oil=?, chb.chb_year=?
    WHERE ci.ci_user_id = ? AND chb.chb_id = ?;
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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