Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Insert: column reference "score" is ambiguous

Tags:

postgresql

I have the following command in postgresql:

INSERT INTO word_relations(word1_id, word2_id, score) VALUES($1, $2, $3) ON CONFLICT (word1_id, word2_id) DO UPDATE SET score = score + $3`) 

I get the following error:

column reference "score" is ambiguous 

I thought it was odd as I am only using one table. Any ideas?

like image 216
biw Avatar asked Apr 02 '16 20:04

biw


1 Answers

On the right side of the = in the set clause, there are two possibilities for score: EXCLUDED.score and word_relations.score. The former is a way of accessing the value being inserted; the latter a way of accessing the value stored in the row.

I would write this as:

ON CONFLICT (word1_id, word2_id) DO     UPDATE SET score = word_relations.score + EXCLUDED.score 
like image 89
Gordon Linoff Avatar answered Sep 29 '22 18:09

Gordon Linoff