diff --git a/cmd/server/main.go b/cmd/server/main.go index f7069d8..1395381 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -778,7 +778,13 @@ func (a *app) reanalyzeChannel(ctx context.Context, w http.ResponseWriter, r *ht return } key := verdictKey(ch.Vertical) - tag, err := a.db.Exec(ctx, `UPDATE messages SET extracted = COALESCE(extracted, '{}'::jsonb) - $1 WHERE channel_id = $2`, key, id) + tag, err := a.db.Exec(ctx, ` + UPDATE messages + SET extracted = ( + CASE WHEN jsonb_typeof(extracted) = 'object' THEN extracted ELSE '{}'::jsonb END + ) - $1 + WHERE channel_id = $2 + `, key, id) if err != nil { writeDBError(w, err) return