I am trying to create a very simple PostgreSQL function, though I keep getting a very strange syntax error. The syntax I use is different from anything I have seen online (though this is the one the textbook uses), and thus I can't figure out why it fails...
This is the SQL:
CREATE OR REPLACE FUNCTION gsum(graphID integer)
RETURNS integer
BEGIN
DECLARE total integer DEFAULT 0
SELECT sum(weight) INTO total
FROM Edge
WHERE gno = graphID
RETURN total;
END;
The error is:
ERROR: syntax error at or near "BEGIN"
LINE 3: BEGIN
^
********** Error **********
ERROR: syntax error at or near "BEGIN"
SQL state: 42601
Character: 68