Posts Tagged plpgsql

get hostname from url as stored procedure in plpgsql

I just needed a simple stored procedure to extract the hostname from any given URL. So here is what I came up with.

CREATE OR REPLACE FUNCTION getHostFromUrl(p_url character varying)
  RETURNS character varying AS
$BODY$
declare
begin
  return substring(p_url from  'http.?://(.*?)/(.*)');
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;

,

3 Comments