# Pastebin 9FDl9NUU I added a column histogram to the avg_rating table using ALTER TABLE avg_rating ADD COLUMN histogram jsonb NULL DEFAULT '{"1" : 0, "2" : 0, "3" : 0, "4" : 0, "5" : 0}'::jsonb; Now to insert data into the table I was trying to create a query by INSERT INTO avg_rating(entity_id, entity_type, rating, count, histogram) VALUES ('42ca4d72-41cd-4874-aedf-8ff6bb2c18d2', 'release_group', 80, 1, jsonb_set(histogram, '1' , (COALESCE(histogram->>'2','0')::int + 1)::text::jsonb)) ON CONFLICT ON CONSTRAINT avg_rating_pkey DO UPDATE SET rating = EXCLUDED.rating, count = EXCLUDED.count, histogram = jsonb_set(histogram, '1' , (COALESCE(histogram->>'2','0')::int + 1)::text::jsonb); I am getting an error saying There is a column named "histogram" in table "avg_rating", but it cannot be referenced from this part of the query.