CREATE FUNCTION "get_match" (text) RETURNS SETOF integer AS 'DECLARE id int; description TEXT; pattern text; rate numeric; carrierid int; active int; carrierid int; dialstring text; begin select i.pattern, i.carrierid, description,dialstring from intlroutes as I, carrier where $1 like pattern and i.carrierid = carrier.carrierid order by length(pattern) desc; return; end ' LANGUAGE "sql" STABLE