plpgsql function - Mailing list pgsql-general

From Andreas Kendlinger
Subject plpgsql function
Date
Msg-id 1203692702.5004.5.camel@maat.bestsolution.at
Whole thread Raw
Responses Re: plpgsql function
List pgsql-general
Hello.

I wrote a little stored function to simulate the EXTRACT(YEAR_MONTH ...)
from mySQL.

//---------------------------------
CREATE OR REPLACE FUNCTION "BiSCAT_combined".extractyearmonth(date
timestamp without time zone)
  RETURNS character varying AS
$BODY$

   DECLARE i INTEGER;

   BEGIN
       i := EXTRACT(MONTH FROM $1 ::timestamp);
    if i > 9 THEN
        RETURN  EXTRACT(YEAR FROM $1 :: timestamp) || EXTRACT(MONTH FROM $1 ::
timestamp);
    else
        RETURN EXTRACT(YEAR FROM $1 ::timestamp) || 0 || EXTRACT(MONTH FROM
$1 :: timestamp);
    end if;

   END;
  $BODY$
  LANGUAGE 'plpgsql' IMMUTABLE STRICT;

//--------------------

One Method call requires 53ms.
I'm sure that this function is absolutely unoptimezed but I think
53ms is too long.

Are there any suggestions to improve the execution time of the function.

Best regards

Andi Kendlinger


pgsql-general by date:

Previous
From: Simon Riggs
Date:
Subject: Re: unnesesary sorting after Merge Full Join
Next
From: "D. Dante Lorenso"
Date:
Subject: Cascading Trigger - changing row on delete does not delete row