sqlc
sqlc copied to clipboard
Crash in compiler.(*Compiler).resolveCatalogRefs using jsonb_build_object()
Version
1.14.0
What happened?
sqlc consistently crashes when using jsonb_build_object()
with sqlc.arg(). As a workaround, adding ::varchar
to the inputs to give sqlc a hint about the types seems to help.
Relevant log output
sqlc generate failed.
panic: runtime error: index out of range [1] with length 1
goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).resolveCatalogRefs(0xc00037f730?, 0xc000778a50, {0x0, 0x0, 0xc000306001?}, {0xc00090aae0, 0x2, 0xc00033c421?}, 0xc000792150)
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/resolve.go:332 +0x2dca
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQuery(0xc0004d6400, {0x1459980?, 0xc000279320?}, {0xc000306000, 0xbf}, {0x0, {0x0, 0x0, {0x0, 0x0}}})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/parse.go:111 +0x88d
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc0004d6400, {0x40?, {0x40?, 0xc8?, {0x0?, 0x1?}}})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/compile.go:108 +0x4ff
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {_, _}, {{0xc00028d4a6, 0xa}, ...}, ...)
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:303 +0x265
github.com/kyleconroy/sqlc/internal/cmd.Generate({0x1463808, 0xc0001a0000}, {0x20?, 0x82?}, {0xc000180300, 0x57}, {0x0?, 0x1012a40?}, {0x145e7c0, 0xc00019a010})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/generate.go:210 +0x894
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x1ce4020, {0x116617d?, 0x0?, 0x0?})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:147 +0x194
github.com/spf13/cobra.(*Command).execute(0x1ce4020, {0x22fa740, 0x0, 0x0})
/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xc000380c80)
/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/go/pkg/mod/github.com/spf13/[email protected]/command.go:895
github.com/kyleconroy/sqlc/internal/cmd.Do({0xc00019e010, 0x1, 0x1}, {0x145e780?, 0xc00019a000}, {0x145e7c0?, 0xc00019a008}, {0x145e7c0?, 0xc00019a010})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:50 +0x46e
main.main()
/go/pkg/mod/github.com/kyleconroy/[email protected]/cmd/sqlc/main.go:10 +0x7a
Database schema
No response
SQL queries
-- name: Panics :exec
SELECT jsonb_build_object(sqlc.arg('Key'), sqlc.arg('Value'));
-- name: WorksOk :exec
SELECT jsonb_build_object(sqlc.arg('Key')::varchar, sqlc.arg('Value')::varchar);
Configuration
{
"version": "1",
"packages": [
{
"path": "db",
"engine": "postgresql",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
Playground URL
https://play.sqlc.dev/p/3810df72b2036c004d0303fb6bd4ed235138c208c332a598d97e4e8522d71db1
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Ah, I hit this bug too - and coincidentally found the same workaround.
This problem has resolved. Editing the content will compile successfully. https://play.sqlc.dev/p/a36559494b89d7b9b59722ff6d7615cd0116fa3a33c9165a5dc239f96931948c