Skip to content

panic: unknown mysql function type "coalesce" #725

Closed
@CArnoud

Description

@CArnoud

I have a query where I need to use group_concat. The attribute generated from that is type string so when group_concat returns NULL, I get a scan error telling me that NULL can't be assigned to string.
So, I thought using COALESCE would tell the code generator to use type sql.NullString instead (it works if I manually change it).
But I get the aforementioned error:

panic: unknown mysql function type "coalesce"

goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/mysql.functionReturnType(0xc00047d170, 0x8, 0xc00047d170, 0x8)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/functions.go:18 +0x48c
github.com/kyleconroy/sqlc/internal/mysql.PackageGenerator.parseSelectAliasExpr(0xc00034f898, 0x589a0a8, 0x1, 0xc0003e9180, 0x1, 0x1, 0xc0003df960, 0x0, 0xc0003c96f6, 0x5, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/parse.go:440 +0x66c
github.com/kyleconroy/sqlc/internal/mysql.PackageGenerator.parseSelect(0xc00034f898, 0x589a0a8, 0x1, 0xc0003e9180, 0x1, 0x1, 0xc0003df960, 0x0, 0xc0003c96f6, 0x5, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/parse.go:180 +0x430
github.com/kyleconroy/sqlc/internal/mysql.PackageGenerator.parseQueryString(0xc00034f898, 0x589a0a8, 0x1, 0xc0003e9180, 0x1, 0x1, 0xc0003df960, 0x0, 0xc0003c96f6, 0x5, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/parse.go:102 +0x149
github.com/kyleconroy/sqlc/internal/mysql.parsePath(0xc0003b5df0, 0x1, 0x1, 0xc00034f898, 0x589a0a8, 0x1, 0xc0003e9180, 0x1, 0x1, 0xc0003df960, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/parse.go:73 +0x7d3
github.com/kyleconroy/sqlc/internal/mysql.GeneratePkg(0xc0003c96c0, 0x8, 0xc0003b5df0, 0x1, 0x1, 0xc0003b5e00, 0x1, 0x1, 0x589a0a8, 0x1, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/mysql/parse.go:473 +0x13e
github.com/kyleconroy/sqlc/internal/cmd.parseMySQL(0xc0003c96c0, 0x8, 0xc000042780, 0x41, 0xc0003c96f6, 0x5, 0xc0003b5df0, 0x1, 0x1, 0xc0003b5e00, ...)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/cmd/generate.go:195 +0xd8
github.com/kyleconroy/sqlc/internal/cmd.Generate(0xc000042780, 0x41, 0x4e7cf60, 0xc000010020, 0xc000010020, 0x32, 0x5a42a80)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/cmd/generate.go:152 +0x139f
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x59cd0a0, 0x5a41b50, 0x0, 0x0)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/cmd/cmd.go:89 +0xab
github.com/spf13/cobra.(*Command).execute(0x59cd0a0, 0x5a41b50, 0x0, 0x0, 0x59cd0a0, 0x5a41b50)
        /Users/c.arnoud/Library/Caches/Homebrew/go_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003ab340, 0xc0000e5f10, 0x1, 0x1)
        /Users/c.arnoud/Library/Caches/Homebrew/go_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/c.arnoud/Library/Caches/Homebrew/go_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/kyleconroy/sqlc/internal/cmd.Do(0xc00000e090, 0x1, 0x1, 0x4e7cf40, 0xc000010010, 0x4e7cf60, 0xc000010018, 0x4e7cf60, 0xc000010020, 0xc0000ac058)
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/internal/cmd/cmd.go:30 +0x205
main.main()
        /private/tmp/sqlc-20201005-23751-gjtz1m/sqlc-1.5.0/src/github.com/kyleconroy/sqlc/cmd/sqlc/main.go:10 +0xb7
internal/bootstrapper/bootstrapper.go:10: running "sqlc": exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions