Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on generate for postgresql function #3554

Open
wexder opened this issue Aug 18, 2024 · 0 comments
Open

Panic on generate for postgresql function #3554

wexder opened this issue Aug 18, 2024 · 0 comments
Labels

Comments

@wexder
Copy link

wexder commented Aug 18, 2024

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/sqlc@v1.27.0/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/sqlc@v1.27.0/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/sqlc@v1.27.0/internal/compiler/analyze.go:180 +0xccd
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).analyzeQuery(...)
  /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.27.0/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/sqlc@v1.27.0/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/sqlc@v1.27.0/internal/compiler/compile.go:81 +0x467
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
  /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.27.0/internal/compiler/engine.go:72
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc0004243c0, 0xa}, ...}, ...)
  /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.27.0/internal/cmd/generate.go:322 +0x2eb
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
  /go/pkg/mod/github.com/sqlc-dev/sqlc@v1.27.0/internal/cmd/process.go:107 +0x81a
golang.org/x/sync/errgroup.(*Group).Go.func1()
  /go/pkg/mod/golang.org/x/sync@v0.8.0/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
  /go/pkg/mod/golang.org/x/sync@v0.8.0/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

@wexder wexder added the bug Something isn't working label Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant