sqlc
sqlc copied to clipboard
sqlite: invalid references to table names when parsing json1 query
Version
1.14.0
What happened?
sqlc appears to be referencing invalid table names when parsing the following JSON-heavy query.
Relevant log output
% ~/go/bin/sqlc generate
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0xb8 pc=0x101676638]
goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertTablesOrSubquery(0x14000537c38?, {0x14000e0eca0?, 0x2, 0x12b1f8dd8?})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:668 +0x118
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).getTables(0x102634f00?, 0x140009ea390)
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:326 +0x98
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertMultiSelect_stmtContext(0x14000131e58?, 0x140009ea378)
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:282 +0x8e8
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0x14000131e88?, {0x10277aca8?, 0x140009ea378?})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:785 +0x380
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertSql_stmtContext(0x1?, 0x140009ea360)
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:483 +0xc64
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0x102649460?, {0x10277acc8?, 0x140009ea360?})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/convert.go:788 +0x504
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*Parser).Parse(0x140001f8c80?, {0x1027821c8?, 0x140009e91e0?})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/engine/sqlite/parse.go:71 +0x6e0
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0x1400047e000, {0x10?, {0x0?, 0x0?, {0x0?, 0x140001db700?}}})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/compile.go:102 +0x31c
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {_, _}, {{0x1400028d010, 0x6}, ...}, ...)
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:279 +0x20c
github.com/kyleconroy/sqlc/internal/cmd.Generate({0x102787148, 0x1400019e008}, {0x4?, 0x0?}, {0x14000042094, 0x23}, {0x0?, 0x0?}, {0x1027820a8, 0x1400019a010})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:221 +0x618
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x1034ff780, {0x101fe150c?, 0x0?, 0x0?})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:147 +0x12c
github.com/spf13/cobra.(*Command).execute(0x1034ff780, {0x1035739a0, 0x0, 0x0})
/Users/dew/go/pkg/mod/github.com/spf13/[email protected]/command.go:876 +0x4b8
github.com/spf13/cobra.(*Command).ExecuteC(0x1400037ca00)
/Users/dew/go/pkg/mod/github.com/spf13/[email protected]/command.go:990 +0x354
github.com/spf13/cobra.(*Command).Execute(...)
/Users/dew/go/pkg/mod/github.com/spf13/[email protected]/command.go:918
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/Users/dew/go/pkg/mod/github.com/spf13/[email protected]/command.go:911
github.com/kyleconroy/sqlc/internal/cmd.Do({0x140001ac010, 0x1, 0x1}, {0x102782068?, 0x1400019a000}, {0x1027820a8?, 0x1400019a008}, {0x1027820a8?, 0x1400019a010})
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:50 +0x390
main.main()
/Users/dew/go/pkg/mod/github.com/kyleconroy/[email protected]/cmd/sqlc/main.go:10 +0x8c
Database schema
create table transactions (
uri text not null,
program_id text not null,
data text not null
);
SQL queries
select
json_extract(transactions.data, '$.transaction.signatures[0]'),
json_group_array(instructions.value)
from transactions,
json_each(json_extract(transactions.data, '$.transaction.message.instructions')) as instructions
where
transactions.program_id = @program_id
and json_extract(transactions.data, '$.transaction.signatures[0]') > @cursor
and json_extract(json_extract(transactions.data, '$.transaction.message.accountKeys'), '$[' || json_extract(instructions.value, '$.programIdIndex') || ']') = transactions.program_id
group by transactions.rowid
limit @limit;
Configuration
version: "2"
sql:
- schema: "cmd/engine/migrations"
queries: "engine.sql"
engine: "sqlite"
gen:
go:
out: "enginesql"
emit_prepared_queries: true
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
No response
What type of code are you generating?
Go