在Cakephp中运行Postgresql函数

Okay so I am trying to run this postgresql function through a Cakephp AppShell class.

CREATE OR REPLACE FUNCTION rdcdev.populatetemptables() RETURNS date AS '
DECLARE
    lastSync date;
BEGIN
SELECT INTO lastSync lastsyncdate FROM rdcdev.syncsettings;

INSERT INTO rdcdev.temp_sourcelists (
    SELECT *
    FROM rdcdev.sourcelists
    );
INSERT INTO rdcdev.temp_beamdatas (
    SELECT *
    FROM rdcdev.beamdatas
    WHERE temp_beamdatas.datetime > lastsync
    );
INSERT INTO rdcdev.temp_beams (
    SELECT *
    FROM rdcdev.beams
    WHERE temp_beams.datetime > lastsync
    );  
INSERT INTO rdcdev.temp_logdatas (
    SELECT *
    FROM rdcdev.logdatas
    WHERE temp_logdatas.datetime > lastsync
    );
INSERT INTO rdcdev.temp_paramdatas (
    SELECT *
    FROM rdcdev.paramdatas
    WHERE temp_paramdatas.datetime > lastsync
    );

RETURN lastSync;
END;
' LANGUAGE 'plpgsql';

As you can see it's quite a few things I would rather be able to call from a function instead of calling these all individually in the cakephp calls. I have verified that the function is working as intended by calling it via command line but it doesn't seem to like calling it via the query call in cakephp:

class SyncShell extends AppShell 
{
    ...blah blah blah
    $SQLcommand = "SELECT rdcdev.populatetemptables();";
    $this->Syncsetting->query($SQLcommand); 
}

Syncsetting is just one of the data models in the database. The code just seems to crash without an error in the cakephp logs so I'm having a hard time figuring out why it doesn't like this. Is it because the function is working with tables outside of SyncSettings. If so do I need to somehow make a model class for the function in Cakephp's model folder or is there some speciall way to call Functions in Cakephp that my rudimentary google-foo has been unable to find.