CREATE OR REPLACE FUNCTION f_graph1() RETURNS text AS ' sqlUDP <- paste("SELECT count(*) FROM firewall WHERE protocol LIKE ''UDP''",sep=""); sqlTCP <- paste("SELECT count(*) FROM firewall WHERE protocol LIKE ''TCP''",sep=""); sqlICMP <- paste("SELECT count(*) FROM firewall WHERE protocol LIKE ''ICMP''",sep=""); strUDP <- pg.spi.exec (sqlUDP); strTCP <- pg.spi.exec (sqlTCP); strICMP <- pg.spi.exec (sqlICMP); str <- c(range(strUDP,strTCP),range(strICMP)[1]); pdf(''/tmp/graph1.pdf''); protocolNames <- c("UDP","TCP","ICMP"); barplot(str,names.arg=protocolNames); mtext("Total number of hits on the firewall this past month",side=3); title(main="Graph 1",xlab="organized by protocol"); dev.off(); print (''DONE''); ' LANGUAGE plr; -- now generating the graph SELECT f_graph1();