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;

,

  1. #1 by Kelly Brown on June 12, 2009 - 21:27

    I really like your post. Does it copyright protected?

  2. #2 by jens on June 12, 2009 - 23:37

    thanks,
    and use it however you want.

  3. #3 by KonstantinMiller on July 6, 2009 - 22:25

    Hello, can you please post some more information on this topic? I would like to read more.

(will not be published)