Skip to content

sqlc crashes when calling a function with OUT arg #1654

Closed
@danielbprice

Description

@danielbprice

Version

1.13.0

What happened?

I tried to call a function which has an OUT argument. I am seeing sqlc crash a lot when I try to do this. I realize I might have botched the syntax or something somewhat, but the crash is making diagnosis of the problem harder.

Relevant log output

sqlc generate failed.

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

goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/compiler.sourceTables(0xc00051f0a0, {0x14205a0, 0xc00037dd90})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/compiler/output_columns.go:409 +0x639
github.com/kyleconroy/sqlc/internal/compiler.outputColumns(0xc00051f0a0, {0x14205a0, 0xc00037dd90})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/compiler/output_columns.go:54 +0x56
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQuery(0xc000424000, {0x1420340, 0xc0002159a0}, {0xc000418480, 0x21a}, {0x0, {0x0, 0x0, {0x0, 0x0}}})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/compiler/parse.go:114 +0x8bf
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc000424000, {0x20, {0x20, 0x45, {0x0, 0x1}}})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/compiler/compile.go:108 +0x513
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {_, _}, {{0xc0002294a6, 0xa}, ...}, ...)
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/cmd/generate.go:262 +0x253
github.com/kyleconroy/sqlc/internal/cmd.Generate({0x14343d0, 0xc00004e040}, {0x80, 0x46}, {0xc00004a3c0, 0x57}, {0x0, 0x101e900}, {0x14250e0, 0xc000010020})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/cmd/generate.go:183 +0x7bb
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x1d3bcc0, {0x116a2e3, 0x0, 0x0})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/cmd/cmd.go:144 +0x194
github.com/spf13/cobra.(*Command).execute(0x1d3bcc0, {0x2366b60, 0x0, 0x0})
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002fea00)
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:895
github.com/kyleconroy/sqlc/internal/cmd.Do({0xc00003c050, 0x1, 0x1}, {0x14250a0, 0xc000010010}, {0x14250e0, 0xc000010018}, {0x14250e0, 0xc000010020})
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/internal/cmd/cmd.go:47 +0x4ba
main.main()
	/go/pkg/mod/github.com/kyleconroy/sqlc@v1.13.0/cmd/sqlc/main.go:10 +0x7a

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

CREATE OR REPLACE FUNCTION add_author (name text, bio text, out id int)
AS $$
DECLARE
BEGIN
  id = 123;
END;
$$ LANGUAGE plpgsql;

SQL queries

-- name: CreateAuthor :one
SELECT * FROM add_author (
  sqlc.arg(name), sqlc.arg(bio)
);

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

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