title: Problem writing a function (pl/pgsql) to determine a degree of similarity
body: <p>I have a schema made of 5 tables. I think 2 of them are useful to solve my problem :<br>
  - <strong>polling_station</strong>, made of the number of <strong>expressed votes</strong> and many other columns related to votes<br>
  - <strong>department</strong>, which has an ID and a name<br>
  3 others :<br>
  - candidate<br>
  - voice<br>
  - municipality<br>
  I need to create a <strong>function</strong> that determines the <strong>degree of similarity</strong> between <strong>each department</strong> based on the "<strong>expressed votes</strong>".<br>
  I have no idea how to do it right now, if you could give me a hand, that would be great!<br>
  I have just been told that to calculate the similarity, I should use the cosine one :<br>
  <a href="https://en.wikipedia.org/wiki/Cosine_similarity" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Cosine_similarity</a></p>
  
  <p>(EDIT)
  A row of this database would be :<br>
  Candidate(id : 4, lastname : HAMON, firstname : Benoît, sex : M)<br>
  Polling_station(id : 0001, id_district : 03, ps_name : Mairie, coords : "43.755611, 4.013062", address : null, zipcode : 34160, city : "Saint-Hilaire-de-Beauvoir", registered : 302, voters : 270, abstentions : 32, expressed : 263, nil : 2, blank : 5)<br>
  Municipality(id : 263, m_name : "Saint-Hilaire-de-Beauvoir)<br>
  Department(id : 34, d_name : "Hérault)<br>
  Voice(nb_voices)</p>
  
  <p>If you want the whole data (but it is in French) :
  <a href="https://public.opendatasoft.com/explore/dataset/election-presidentielle-2017-resultats-par-bureaux-de-vote-tour-1/table/?disjunctive.libelle_de_la_commune" rel="nofollow noreferrer">https://public.opendatasoft.com/explore/dataset/election-presidentielle-2017-resultats-par-bureaux-de-vote-tour-1/table/?disjunctive.libelle_de_la_commune</a></p>
  
  <p>Thank you in advance for your answer(s)!</p>