Thread: Suppress output from function?

Suppress output from function?

From
Ron St-Pierre
Date:
Whenever I run certain functions, such as the example below, the output
is either displayed in the terminal or emailed to be by cron, depending
on how I run it.  Is there any way I can re-write the function, set some
psql parameters, etc, to ensure that the results aren't displayed?  I've
checked some of the postgresql.conf logging properties and running psql
with quiet = true, but all to no avail.  Anyone have any suggestions,
hints, ?

   CREATE TYPE employeeType AS (empID INTEGER, updateDate DATE, bDate
INTEGER, val1 NUMERIC, val2 NUMERIC, val3 NUMERIC, val4 NUMERIC, favNum
NUMERIC);

   CREATE OR REPLACE FUNCTION updateEmployeeData() RETURNS SETOF
employeeType AS '
       DECLARE
           rec     RECORD;
       BEGIN
           FOR rec IN SELECT empID, updateDate, bDate, val1, val2 ,
val3, val4, favNum FROM newData LOOP
               RETURN NEXT rec;
               UPDATE currentData SET val1=rec.val1, val2=rec.val2,
val3=rec.val2, val4=rec.val4, favNum=rec.favNum, updateDate=rec.updateDate
               WHERE empID=rec.empID;
           END LOOP;
           RETURN;
       END;
   ' LANGUAGE 'plpgsql';

SELECT * FROM updateEmployeeData();


Thanks
Ron


Re: Suppress output from function?

From
Tom Lane
Date:
Ron St-Pierre <rstpierre@syscor.com> writes:
> Whenever I run certain functions, such as the example below, the output
> is either displayed in the terminal or emailed to be by cron, depending
> on how I run it.  Is there any way I can re-write the function, set some
> psql parameters, etc, to ensure that the results aren't displayed?

Add "> /dev/null" to the psql invocation in the cron script.  You might
also want to add "-q" to suppress uninteresting comments on stderr,
while still hearing about any actual errors (in other words, I wouldn't
also route stderr to /dev/null...)

            regards, tom lane