sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

sqlite ALTER TABLE ADD COLUMN without type name panics

Open dvob opened this issue 9 months ago • 2 comments

Version

1.26.0

What happened?

sqlc panics after i've added a migration which adds a generated column which uses a json function

Relevant log output

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

goroutine 6 [running]:
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convertAlter_table_stmtContext(0x1?, 0xc00012c280)
        github.com/sqlc-dev/[email protected]/internal/engine/sqlite/convert.go:77 +0x709
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convert(0x2bc0ae0?, {0x1d8a320?, 0xc00012c280?})
        github.com/sqlc-dev/[email protected]/internal/engine/sqlite/convert.go:1124 +0x251
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convertSql_stmtContext(0xc000a68b18, 0xc000196e80)
        github.com/sqlc-dev/[email protected]/internal/engine/sqlite/convert.go:657 +0x3a28
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convert(0x2bc27a0?, {0x1d8a620?, 0xc000196e80?})
        github.com/sqlc-dev/[email protected]/internal/engine/sqlite/convert.go:1197 +0x315
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*Parser).Parse(0x0?, {0x1d84640?, 0xc00037c1a0?})
        github.com/sqlc-dev/[email protected]/internal/engine/sqlite/parse.go:70 +0x579
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseCatalog(0xc0003bf688, {0xc000066490?, 0xc00061a01a?, 0x6?})
        github.com/sqlc-dev/[email protected]/internal/compiler/compile.go:42 +0x242
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseCatalog(...)
        github.com/sqlc-dev/[email protected]/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc00061a01a, 0x6}, ...}, ...)
        github.com/sqlc-dev/[email protected]/internal/cmd/generate.go:308 +0x1ce
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
        github.com/sqlc-dev/[email protected]/internal/cmd/process.go:107 +0x877
golang.org/x/sync/errgroup.(*Group).Go.func1()
        golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x96

Database schema

CREATE TABLE my_data (
	id        INTEGER NOT NULL PRIMARY KEY,
	data      BLOB
);


ALTER TABLE my_data ADD COLUMN object_id AS ( data->>'id' );

-- the following doesn't work either
-- ALTER TABLE my_data ADD COLUMN object_id AS ( json_extract(data, '$.id') );

SQL queries

-- name: GetIDs :many
SELECT object_id FROM my_data;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "tutorial"
        out: "tutorial"

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

dvob avatar May 10 '24 17:05 dvob