Skip to content

invalid memory address or nil pointer dereference when trying to generate go code from sqlite query #3963

Open
@WWology

Description

@WWology

Version

1.29.0

What happened?

I have these 2 queries

When i try to run sqlc generate it returns an error saying invalid memory address

Not quite sure what i did wrong, and also sorry if the issue seems disconnected since this is my 1st issue

any help would be appreciated TY

Relevant log output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11448a7]

goroutine 11 [running]:
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).sourceTables(0xc00038d408, 0xc0005f2fc0, {0x1ebe7a0?, 0xc00047e630?})
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/output_columns.go:601 +0xaa7
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).outputColumns(0xc00038d408, 0xc0005f2fc0, {0x1ebe7a0, 0xc00047e630})
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/output_columns.go:55 +0x45
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler)._analyzeQuery(0xc00038d408, 0xc00077bd40, {0xc0006118bb, 0x1d7}, 0x1)
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/analyze.go:180 +0xcdd
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).analyzeQuery(...)
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/analyze.go:110
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQuery(0xc00038d408, {0x1ebe960, 0xc00077bd40}, {0xc000611680, 0x415}, {{0x0, 0x0, {0x0, 0x0}, 0x0, ...}})
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/parse.go:103 +0x5b5
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQueries(0xc00038d408, {{0x0, 0x0, {0x0, 0x0}, 0x0, 0x0, 0x0, 0x0}})
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/compile.go:81 +0x467
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc0003302b0, 0x6}, ...}, ...)
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/cmd/generate.go:322 +0x2f6
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
        /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.29.0/internal/cmd/process.go:107 +0x857
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /go/pkg/mod/golang.org/x/sync@v0.13.0/errgroup/errgroup.go:79 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        /go/pkg/mod/golang.org/x/sync@v0.13.0/errgroup/errgroup.go:76 +0x96

Database schema

CREATE TABLE
    IF NOT EXISTS cs_scoreboard (id INTEGER PRIMARY KEY, score INTEGER NOT NULL);

SQL queries

-- name: GetCSScoreForId :one
SELECT
    rank, id, score
FROM (
    SELECT
        DENSE_RANK() OVER (ORDER BY score DESC) rank_position,
        id,
        score
    FROM
        cs_scoreboard
)
WHERE
    id = ?;

-- name: GetCSWinners :many
SELECT
    rank, id, score
FROM (
    SELECT
        DENSE_RANK() OVER (ORDER BY score DESC) rank_position,
        id,
        score
    FROM
        cs_scoreboard
)
WHERE
    rank <= 3;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: "data/sql/"
    schema: "data/sql/schema.sql"
    gen:
      go:
        package: "data"
        out: "data"

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

SQLite

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