Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

postgresql - Postgres BIGINT value not being created or updated

I am doing this:

Note : Request is generated with squirrel

    // Prepare query
    qb := sq.Update(d.table).
        SetMap(updates).
        Where(filter).
        PlaceholderFormat(sq.Dollar)

    // Build sql query
    q, args, err := qb.ToSql()
    if err != nil {
        return fmt.Errorf("postgresql: unable to build query: %w", err)
    }

    fmt.Println(q, args)

    // Prepare the statement
    stmt, err := d.session.PreparexContext(ctx, q)
    if err != nil {
        return fmt.Errorf("postgresql: unable to prepare query: %w", err)
    }

    // Do the insert query
    res, err := stmt.ExecContext(ctx, args...)
    if err != nil {
        return fmt.Errorf("postgresql: unable to execute query: %w", err)
    }

With this data :

    // Updates
    updates := map[string]interface{}{
        "acknowledgment_duration": obj.AcknowledgmentDuration,
    }
type sqlIssue struct {
    ...
    AcknowledgmentDuration int       `db:"acknowledgment_duration"`

I am sure that the value is not 0 when I print it I got the right value, the SQL request is good when I print it, but whatever I try the value in Postgress stays at "0". It is not being updated, nor created with the right value.

The generated SQL request is :

UPDATE issues SET ..................., acknowledgment_duration = $9, .......... WHERE id = $14 [ ......... 10000000000 ..... ]

SQL table is :

-- +migrate Up
CREATE TABLE issues (
    ...
    acknowledgment_duration BIGINT,

Am I missing something?

If I perform the request myself into the database with a too such as Adminer, it is working. So it must be inside my Go code I guess.

question from:https://stackoverflow.com/questions/65858504/postgres-bigint-value-not-being-created-or-updated

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...