Skip to content

Error when using bytea datatype  #82

@Oliver-Fish

Description

@Oliver-Fish

Before this commit 2489d54 I was able to do the following.

CREATE TABLE table_name (
    id BIGSERIAL PRIMARY KEY,
    data BYTEA
);
-- name: InsertData :exec
INSERT INTO table_name (data)
    VALUES (pggen.arg ('data'));

However, from that commit onwards, I now get the following error.

ERROR: generate go code: template all: template query file /path/file.sql for go: resolve known type &{"" %!q(*gotype.OpaqueType=&{<nil> byte})} does not have pg array type "bytea"

My command looks like the following;

pggen gen go \
    --output-dir ./../postgres \
    --query-glob './queries/*.sql' \
    --postgres-connection "user=postgres port=5432 dbname=databasename password=password host=localhost"

It appears this changed the behavior 2489d54#diff-c42aa8077d6b0565a2ffc41636d61300a263997cbe44e90c16b7db051f9f9fdeR50

According to the comments on pg.ArrayType

// ArrayType is an array type where pg_type.typelem != 0 and the name begins
// with an underscore.

However, this is not the case for bytea.

Bytea            = BaseType{ID: pgtype.ByteaOID, Name: "bytea"}

I was able to overcome this error by using the following command instead. However, this feels like it should be the default behavior.

pggen gen go \
    --output-dir ./../postgres \
    --query-glob './queries/*.sql' \
    --go-type bytea=[]byte \
    --postgres-connection "user=postgres port=5432 dbname=databasename password=password host=localhost"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions