I have created a stored procedure in Postgres. It's about to get max of message_id
from table Messages
and store in another table (MaxMessageID
) in column MessageID
.
Here is my stored procedure:
CREATE OR REPLACE FUNCTION MaxId()
RETURNS integer AS $MID$
declare
MID integer;
BEGIN
DELETE FROM MaxMessageID;
INSERT INTO MaxMessageID(MessageID)
SELECT MAX(MESSAGE_ID) FROM Messages;
RETURN MID;
END;
$MID$ LANGUAGE plpgsql;
After running this procedure, max(MESSAGE_ID) should be stored in MaxMessageID(MessageID).
When I run the procedure and check following command:
Select * from MaxMessageID
It shows this. But when I call procedure with Select MaxId()
, it shows this.
What am I missing?