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

Error when using bytea datatype #82

Open
Oliver-Fish opened this issue Mar 10, 2023 · 1 comment
Open

Error when using bytea datatype #82

Oliver-Fish opened this issue Mar 10, 2023 · 1 comment

Comments

@Oliver-Fish
Copy link

Oliver-Fish commented Mar 10, 2023

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"
@jschaf
Copy link
Owner

jschaf commented Mar 13, 2023

Thank you, definitely looks like a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants