Assuming you have a connected graph (otherwise the max distance is infinite) and all your node points are numbers....
Seed a table (from, to, distance) with (from_node, to_node, 1). For each tuple, you must ensure that the value of from_node is always less than the value of to_node
CREATE TABLE hops (
from_node int not null,
to_node int not null,
distance int not null default 0,
primary key (from_node, to_node, distance)
)
-- first load:
INSERT INTO hops (from_node, to_node)
SELECT from_node, to_node FROM rel;
-- iterative step
INSERT INTO hops (from_node, to_node, distance)
SELECT a.from_node, b.to_node, min(a.distance+b.distance)
FROM hops a, hops b
WHERE a.to_node = b.from_node
AND a.from_node <> b.from_node -- not self
AND a.to_node <> b.to_node -- still not self
AND a.from_node <> b.from_node -- no loops
AND NOT EXISTS ( -- avoid duplicates
SELECT * FROM hops c
WHERE c.from_node = a.from_node
AND c.to_node = b.to_node
AND c.distance = a.distance+b.distance)
GROUP BY a.from_node, b.to_node
Execute the insert repeatedly until no rows are inserted. Then select max distance to get your diameter.
EDIT: For a graph with weighted vertices, you would just seed the distance field with the weights rather than using 1.