Recommendation about the implementation of a voting process - Mailing list pgsql-novice

From JORGE MALDONADO
Subject Recommendation about the implementation of a voting process
Date
Msg-id CAAY=A79aTSyxz7HoNkj0UADD=5ODnCyhstnV12dUe-++D9SRzg@mail.gmail.com
Whole thread Raw
Responses Re: Recommendation about the implementation of a voting process  (amul sul <sul_amul@yahoo.co.in>)
List pgsql-novice
Hi,

We have an information system for the World Wide Web already running and we need to include a new functionality which should allow users to vote for certain events. This means that users will be able to (for example) click a button to vote. 

This might imply 2 things:
(1) The insertion of a record to a DB table containing data like the event ID the user is voting, the username and timestamp.
(2) Update a counter for the event the user is voting each time a user votes (each event would have its own counter).

Our main concern is how to implement the process of showing the events information in real time. We need to display the events in descending order, showing those with more votes first.

We see at least 2 options to achieve this goal: 
(a) To use a SELECT statement with COUNT and GROUP BY.
(b) To display the counter that I mentioned in point (2) above.

How reliable it is to use a counter? Is there any risk that the PostgreSQL DB does not update such a counter?

I know that using option (a) will provide the correct results without any doubt, but it also means more process for the DB.

What do you recommend?

Respectfully,
Jorge Maldonado

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: numeric data type upper limit.
Next
From: amul sul
Date:
Subject: Re: Recommendation about the implementation of a voting process