CREATE OR REPLACE FUNCTION CHARINDEX(text, text, integer) 
RETURNS integer AS 
$$ 
SELECT	CASE	WHEN strpos(substr($2, $3+1), $1) = 0 THEN 0 
		ELSE strpos(substr($2, $3+1), $1) + $3 
	END; 
$$ LANGUAGE SQL 
IMMUTABLE RETURNS NULL ON NULL INPUT;