Search Postgresql Archives

plpgsql function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux