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
Upsert fails, returning sql.ErrNoRows, because Postgres does not return any values when DO NOTHING is used as the conflict action. This happens when there is a conflict on the tuple to be inserted, such as when trying to insert a duplicate primary key/unique.
The expected result would be that Upsert returns no error and updates the object on which Upsert was called.
Schema:
CREATETABLEvideo
(
id serialPRIMARY KEY,
youtube_id varchar(64) NOT NULL,
title textNOT NULL
);
ALTERTABLE video ADD CONSTRAINT youtube_id_uniq UNIQUE (youtube_id);
Call:
// A record with YoutubeID="foo" already exists in the databasevideo:= models.Video{YoutubeID: "foo", Title: "abc"}
iferr=video.UpsertG(false, []string{"youtube_id"}, nil); err!=nil {
returnnil, err
}
SQL query + parameters:
INSERT INTO"video" ("youtube_id", "title") VALUES ($1,$2) ON CONFLICT DO NOTHING RETURNING "id"
[foo abc]
The text was updated successfully, but these errors were encountered:
Upsert fails, returning
sql.ErrNoRows
, because Postgres does not return any values whenDO NOTHING
is used as the conflict action. This happens when there is a conflict on the tuple to be inserted, such as when trying to insert a duplicate primary key/unique.The expected result would be that Upsert returns no error and updates the object on which Upsert was called.
Schema:
Call:
SQL query + parameters:
The text was updated successfully, but these errors were encountered: