sqlc
sqlc copied to clipboard
Panic on generate for postgresql function
Version
1.27.0
What happened?
Sqlc panics when generating from migration containing PLPGSQL function
Relevant log output
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x10bcbba]
goroutine 19 [running]:
github.com/sqlc-dev/sqlc/internal/compiler.dataType(...)
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/resolve.go:17
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).outputColumns(0xc0003acf08, 0xc000599080, {0x1da9fa0, 0xc000576210})
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/output_columns.go:315 +0x49a
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler)._analyzeQuery(0xc0003acf08, 0xc000164ea0, {0xc00012febc, 0x46}, 0x1)
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/analyze.go:180 +0xccd
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).analyzeQuery(...)
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/analyze.go:110
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQuery(0xc0003acf08, {0x1daa160, 0xc000164ea0}, {0xc00012fc00, 0x3c7}, {{0x0, 0x0, {0x0, 0x0}, 0x0, ...}})
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/parse.go:103 +0x5d5
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQueries(0xc0003acf08, {{0x0, 0x0, {0x0, 0x0}, 0x0, 0x0, 0x0, 0x0}})
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/compile.go:81 +0x467
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc0004243c0, 0xa}, ...}, ...)
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/cmd/generate.go:322 +0x2eb
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
/go/pkg/mod/github.com/sqlc-dev/[email protected]/internal/cmd/process.go:107 +0x81a
golang.org/x/sync/errgroup.(*Group).Go.func1()
/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x96
cmd/main.go:3: running "sqlc": exit status 2
Database schema
CREATE OR REPLACE FUNCTION next_id(IN seq regclass, OUT result bigint) AS $$
DECLARE
-- 6/4/2013 00:00:00 GMT
our_epoch bigint := 1370304000000;
seq_id bigint;
now_millis bigint;
shard_id int := 1;
BEGIN
SELECT nextval(seq) % 1024 INTO seq_id;
SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000) INTO now_millis;
result := (now_millis - our_epoch) << 23;
result := result | (shard_id << 10);
result := result | (seq_id);
END;
$$ LANGUAGE PLPGSQL;
SQL queries
-- name: AllocateIdentityID :one
SELECT next_id('identities_id_seq');
Configuration
version: "2"
sql:
- engine: "postgresql"
queries: "./internal/stores/sql/"
schema: "./migrations/"
gen:
go:
package: "postgresQueries"
out: "./internal/stores/sql/generated/"
sql_package: "pgx/v5"
emit_pointers_for_null_types: true
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go