-- For systems that do not allow overvoting:  turn all overvotes into
-- undervotes.  (1) Assumes that straight party overrides, bad aliases,
-- etc. will be caught by the integrity checks and we don't need to worry about
-- them here.  (2) Must be run before materializing views.  (3) Has not been
-- tested for scalability to large numbers of ballots and votes.

\echo $Id: Infrastructure-KillOvervotes.sql 445 2008-01-08 20:46:58Z dflater $
\echo Killing overvotes.
delete from VoterInput
  where (BallotId, ChoiceId) in (
    select BallotId, ChoiceId
      from VoterInput
	natural join Choice
	natural join Contest
	natural join Ballot
	natural join S
      where S_val > N
  );
