Trigger for a Select

1

I would like to know if it is possible to execute a Trigger when a SELECT is performed in a certain table, for example:

CREATE TABLE IF NOT EXISTS "Conversa" (
  "idConversa" SERIAL NOT NULL,
  "idEmissorConversa" INT NOT NULL,
  "idReceptorConversa" INT NOT NULL,
  "mensagemConversa" VARCHAR(250) NOT NULL,
  "statusConversa" INT NOT NULL,
  "horaConversa" TIMESTAMP NOT NULL,
  PRIMARY KEY ("idConversa")

This is the table, the concept of it is to create a Chat, where I will save the ID of the person who sent the message, the ID of the person who received the message, the statusConversa would be the item I wanted to change with Trigger, because:

statusConversa = 0 -- Significa que a mensagem não foi lida(carregada)
statusConversa = 1 -- Significa que a mensagem foi lida(carregada)

Then, when a SELECT is carried out in this message, the Trigger should change the StatusConversa to 1. So that later, when checking via AJAX if there is a new message, it will fetch messages with statusConversa = 0. >     

asked by anonymous 11.10.2014 / 15:59

1 answer

2

It is not possible to use a trigger for a select.

Maybe you could use a SELECT FOR UPDATE like this

 SELECT * FROM Conversa FOR UPDATE;
 UPDATE Conversa SET statusConversa = 1;
    
11.10.2014 / 16:16