Repository navigation
Closed
Labels
Description
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/[email protected]/internal/compiler/output_columns.go:409 +0x639
github.com/kyleconroy/sqlc/internal/compiler.outputColumns(0xc00051f0a0, {0x14205a0, 0xc00037dd90})
/go/pkg/mod/github.com/kyleconroy/[email protected]/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/[email protected]/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/[email protected]/internal/compiler/compile.go:108 +0x513
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({_, _}, {_, _}, {_, _}, {_, _}, {{0xc0002294a6, 0xa}, ...}, ...)
/go/pkg/mod/github.com/kyleconroy/[email protected]/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/[email protected]/internal/cmd/generate.go:183 +0x7bb
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x1d3bcc0, {0x116a2e3, 0x0, 0x0})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:144 +0x194
github.com/spf13/cobra.(*Command).execute(0x1d3bcc0, {0x2366b60, 0x0, 0x0})
/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002fea00)
/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bc
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({0xc00003c050, 0x1, 0x1}, {0x14250a0, 0xc000010010}, {0x14250e0, 0xc000010018}, {0x14250e0, 0xc000010020})
/go/pkg/mod/github.com/kyleconroy/[email protected]/internal/cmd/cmd.go:47 +0x4ba
main.main()
/go/pkg/mod/github.com/kyleconroy/[email protected]/cmd/sqlc/main.go:10 +0x7aDatabase 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
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Activity
danielbprice commentedon May 31, 2022
I also reproduced this on HEAD of main, b0d6f13
danielbprice commentedon May 31, 2022
With a little more experimentation, I found that adding
RETURNS voidto the function avoids the crash, but then an error is thrown:query.sql:17:1: empty edit contents: https://play.sqlc.dev/p/50db6d7ed79a5b1cd22ae47ec5938ccb856fa1f89f4d83caad779bc6e6fbffcdModifying the code to
SELECT add_author(...);instead ofSELECT * FROM add_author(...)')further helps, but the out argument appears to be ignored: https://play.sqlc.dev/p/bb7c8c91e7e3f775c095e1905f890eea93c6cf9371c6a00ed9582cf9a0f16e87test: add a test case for #1654
fix(compiler): Support functions with OUT params (#2865)
mdigger commentedon May 26, 2024
Does not work in version 1.26.
wexder commentedon Aug 18, 2024
Does not work in version 1.27.0
fix(compiler): Support functions with OUT params (sqlc-dev#2865)