Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: query has no destination for result data

I ve created function and trigger as follows:

CREATE OR REPLACE FUNCTION New_Ticket()
RETURNS TRIGGER AS
$$BEGIN
    SELECT * FROM Ticket WHERE productID=(SELECT MAX(ticketID) FROM Ticket);
    RETURN NEW;
END$$ 
LANGUAGE PLPGSQL;

CREATE TRIGGER New_TicketTr
AFTER INSERT ON Ticket
FOR EACH ROW execute procedure New_Ticket();

After I do insertion as follows:

INSERT INTO Ticket (ticketID, Problem, Status, Priority,LoggedTime,CustomerID,ProductID) VALUES 
(1, 'Cannot play games.', 'open', 1,'2005-05-13 07:15:31.123456789',1,1);

I get ERROR message:ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL function "new_ticket" line 2 at SQL statement. Can anyone help me? What is the problem there?

like image 412
Sermilion Avatar asked Dec 31 '25 22:12

Sermilion


2 Answers

I think the problem is that you are not doing anything with that query. Neither a DML nor returning the result into a variable or record.

like image 58
Alejandro B. Avatar answered Jan 02 '26 13:01

Alejandro B.


You misinterpret the basic concept of a trigger. A trigger function can manipulate the row it has been called for. Or it can execute additional DML statements to manipulate other data in the database.

But there is no way to "return a variable", because there is no calling instance it could return values to.

Now, if you define in your question what you intend to do with the row you query, we might be able to help.

However, the query itself does not seem to make any sense. Why would a productid matchmax(ticketid) in table ticket?

Also, you are creating a trigger AFTER INSERT. It is nonsensiccal to RETURN NEW in the trigger function in such a case.

You really need to get a grasp on the whole concept first.
Start by reading the chapter Triggers in the manual.

like image 39
Erwin Brandstetter Avatar answered Jan 02 '26 11:01

Erwin Brandstetter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!