Recommendation about the implementation of a voting process

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Recommendation about the implementation of a voting process
Date: 2016-08-15 16:18:34
Message-ID: CAAY=A79aTSyxz7HoNkj0UADD=5ODnCyhstnV12dUe-++D9SRzg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message amul sul 2016-08-15 16:34:49 Re: Recommendation about the implementation of a voting process
Previous Message Tom Lane 2016-08-14 17:28:41 Re: numeric data type upper limit.