I am porting an Oracle function into Postgres PGPLSQL.. I have been using this guide: http://www.postgresql.org/docs/8.1/static/plpgsql.html
CREATE OR REPLACE PROCEDURE DATA_UPDATE
(mission NUMBER,
task NUMBER)
AS
BEGIN
IF mission IS NOT NULL THEN
UPDATE MISSION_OBJECTIVE MO
SET (MO.MO_TKR_TOTAL_OFF_SCHEDULED,
MO.MO_TKR_TOTAL_RECEIVERS) =
(SELECT NVL(SUM(RR.TRQ_FUEL_OFFLOAD),0),
NVL(SUM(RR.TRQ_NUMBER_RECEIVERS),0)
FROM REFUELING_REQUEST RR, MISSION_REQUEST_PAIRING MRP
WHERE MO.MSN_INT_ID = MRP.MSN_INT_ID
AND MO.MO_INT_ID = MRP.MO_INT_ID
AND MRP.REQ_INT_ID = RR.REQ_INT_ID)
WHERE MO.MSN_INT_ID = mission
AND MO.MO_INT_ID = task ;
END IF ;
COMMIT ;
END ;
I've got it this far:
CREATE OR REPLACE FUNCTION DATA_UPDATE
(NUMERIC,
NUMERIC)
RETURNS integer as '
DECLARE
mission ALIAS for $1;
task ALIAS for $2;
BEGIN
IF mission IS NOT NULL THEN
UPDATE MISSION_OBJECTIVE MO
SET (MO.MO_TKR_TOTAL_OFF_SCHEDULED,
MO.MO_TKR_TOTAL_RECEIVERS) =
(SELECT COALESCE(SUM(RR.TRQ_FUEL_OFFLOAD),0),
COALESCE(SUM(RR.TRQ_NUMBER_RECEIVERS),0)
FROM REFUELING_REQUEST RR, MISSION_REQUEST_PAIRING MRP
WHERE MO.MSN_INT_ID = MRP.MSN_INT_ID
AND MO.MO_INT_ID = MRP.MO_INT_ID
AND MRP.REQ_INT_ID = RR.REQ_INT_ID)
WHERE MO.MSN_INT_ID = mission
AND MO.MO_INT_ID = task ;
END IF;
COMMIT;
END;
' LANGUAGE plpgsql;
This is the error I get:
ERROR: syntax error at or near "SELECT"
LINE 1: ...OTAL_OFF_SCHEDULED, MO.MO_TKR_TOTAL_RECEIVERS) = (SELECT COA...
I do not know why this isn't working... any ideas?