title: Presto URL Functions
body: <p>I need to pull urls from a database, re-formatting them slightly in the process. Some of the URLs in the db have port numbers specified, some don't. I'm using Presto's handy <a href="https://prestodb.io/docs/current/functions/url.html" rel="nofollow noreferrer">URL extraction functions</a>, such as url_extract_port. </p>
  
  <p>However, when the following sql encounters a url where no port is specified, it returns null - even for rows that are not in fact null. (If I remove the url_extract_port function I get the link value, but without the port.)</p>
  
  <pre><code>SELECT
    concat(
      url_extract_protocol(link)
      ,'://'
      ,url_extract_host(link)
      ,':'
      ,cast(url_extract_port(link) AS VARCHAR)
    )
     AS  url
   FROM db.schema.urltable
  WHERE link is not null
  </code></pre>
  
  <p>Is there a way to specify in the sql that i only want to use url_extract_port when a port is specified? </p>