You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// both queries were used in testingqueryv1:=`SELECT * FROM "accounts" WHERE id=$1 OR username=$2 OR email=$3`queryv2:=`SELECT id,username,email,created_at,updated_at FROM "accounts" WHERE id=$1 OR username=$2 OR email=$3`
Code being ran
typestoragestruct {
Conn*pgx.Conn
}
func (s*storage) Find(ctx context.Context, id uuid.UUID, email, usernamestring) (AccountModel, error) {
rows, err:=s.Conn.Query(ctx, queryv1, id, username, email) // both queryv1 and queryv2 was tried hereiferr!=nil {
returnAccountModel{}, err
}
// doesn't work with// RowToStructByName// RowToStructByNameLax// RowToStructByPosm, err:=pgx.CollectOneRow(rows, pgx.RowToStructByName[AccountModel])
iferr!=nil {
returnAccountModel{}, err
}
returnm, nil
}
Error Message
"struct doesn't have corresponding row field id"
Expected behavior
Should expect the id field to be excluded in the returned struct.
When I include the id field it works and throws no error.
I've looked through all previous error post opened and the solutions linked there have not worked.
Version
Go: go version go1.22.5 windows/amd64
PostgreSQL: PostgreSQL 16.1, compiled by Visual C++ build 1937, 64-bit
pgx: github.com/jackc/pgx/v5 v5.6.0
The text was updated successfully, but these errors were encountered:
MiniJ147
changed the title
RowToStructByName, RowToStructByNameLax and RowToStructByPos not working with db:"-" tag
RowToStructByName, Lax and Pos not working with db:"-" tag
Jul 19, 2024
Your query returns a column "id" but you don't have anywhere to scan it. Every column returned from a query must have a destination for the RowToStruct* functions.
pgx throwing "struct doesn't have corresponding row field " when attempting to use struct tag
db:"-"
with the following functions:Code Im working with
Model
Postgres Table
Queries used
Code being ran
Error Message
Expected behavior
Should expect the id field to be excluded in the returned struct.
When I include the id field it works and throws no error.
I've looked through all previous error post opened and the solutions linked there have not worked.
Version
The text was updated successfully, but these errors were encountered: