go-zero
go-zero copied to clipboard
goctl gen model with pg and cache leads to a column "xxx" does not exist error
Describe the bug
I use the code generated by goctl model pg datasource -url="postgresql://postgres@localhost:5432/postgres?sslmode=disable" -table="xxx" -c
the ddl is below and there is a unique index
CREATE TABLE tx_status (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
network character varying(255) NOT NULL,
hash text NOT NULL,
status character varying NOT NULL,
receipt jsonb NOT NULL DEFAULT '{}'::jsonb,
"createAt" timestamp with time zone NOT NULL,
"updateAt" timestamp with time zone NOT NULL
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX tx_network_hash_uniq_index ON tx_status(network text_ops,hash text_ops);
To Reproduce
-
The code is
res, err := l.svcCtx.DB.FindOneByNetworkHash(l.ctx, network, in.Hash)
-
The error is
{"@timestamp":"2022-09-21T15:03:22.197+08:00","caller":"sqlx/utils.go:140","content":"stmt: select id,network,hash,status,receipt,createAt,updateAt from \"public\".\"tx_status\" where network = 'xxx' and hash = 'xxx' limit 1, error: pq: column \"createat\" does not exist","level":"error","span":"754988c3cdf31f51","trace":"d69c8f5d160d9b30dbab024f1b353bd4"}
It's strange while in the log the column is camelcase , but in the error message the column is lowercased.
Expected behavior
no error
Screenshots
Environments (please complete the following information):
- OS: macos 12.5.1
- github.com/zeromicro/go-zero v1.4.1
- goctl version 1.4.0 darwin/amd64
try without quoting createAt and updateat field
try without quoting createAt and updateat field
Of course I can try. But I think it doesn't solve the problem. It's the code generated.
The fields are from :
txStatusFieldNames = builder.RawFieldNames(&TxStatus{}, true)
txStatusRows = strings.Join(txStatusFieldNames, ",")
I can hack this time. But it's not the right way to solve this problem forever.
This error also happens in FindOne
function.
So it's a critical bug ? The generated code don't work.
{"@timestamp":"2022-09-22T10:23:00.305+08:00","caller":"sqlx/utils.go:139","content":"stmt: select id,network,hash,status,receipt,createAt,updateAt from \"public\".\"tx_status\" where id = 16268 limit 1, error: pq: column \"createat\" does not exist","level":"error","span":"7cbb99e9939a30e0","trace":"ebdd9781527ac4e87500db7ea60e2d29"}
test, err := l.svcCtx.DB.FindOne(l.ctx, 16268)
fmt.Println("err test", err)
err test pq: column "createat" does not exist
If I change the ddl from createAt
to create_at
it works.
And I added a test field named uuuTest
{"caller":"sqlx/utils.go:139","
content":"stmt: select id,network,hash,status,receipt,uuuTest from \"public\".\"tx_status\" where network = 'x' and hash = 'x' limit 1,
error: pq: column \"uuutest\" does not exist",
"level":"error","
span":"cfd58604191f622e",
"trace":"25b150fd5dcb7032a29dc9a2c8720a92"}
err pq: column "uuutest" does not exist
Postsql is case sensitive, just change the uuutest column name to lowercase. https://stackoverflow.com/questions/20878932/are-postgresql-column-names-case-sensitive
Postsql is case sensitive, just change the uuutest column name to lowercase. https://stackoverflow.com/questions/20878932/are-postgresql-column-names-case-sensitive
It's the right case.
select id,network,hash,status,receipt,uuuTest from \"public\".\"tx_status\"
and then leads to an pq: column "uuutest" does not exist
I just want to know when it changed from uuuTest
to uuutest
Anyone follow this issue ?
Hey, is there anyone following this issue ?
See #2100
See #2100
So what about the column uuuTest
?