title: Returning Table with null value causes error
body: <p>I have a simple function that has optional parameters. When I leave out a parameter, which should just default to null, I get an error that it is not an integer.</p>
  <p>Here is the function:</p>
  <pre><code>CREATE FUNCTION rewrite(_postid integer DEFAULT NULL::integer,
                                         _url character varying DEFAULT NULL::character varying)
      RETURNS TABLE
              (
                PostTypeID                 integer,
                DestinationURL             varchar,
              )
      LANGUAGE plpgsql
  AS
  $function$
  BEGIN
  RETURN QUERY
                  SELECT 
                  NULL AS PostTypeID,
                  _url      AS DestinationURL,
                        
                  FROM reference.destinations dest1
              
                  WHERE length(TRIM(dest1.DestinationURL)) &gt; 0
                  AND _url LIKE '%' || TRIM(dest1.DestinationURL)) || '%'
                  ORDER BY length(dest1.DestinationURL)) DESC
                  LIMIT 1;
  END;
  $function$
  </code></pre>
  <p>If I run <code>SELECT * FROM utility.rewrite(_url := 'wikipedia.org')</code> then I get this error:</p>
  <blockquote>
  <p>[42804] ERROR: structure of query does not match function result type
  Detail: Returned type text does not match expected type integer in
  column 1.</p>
  </blockquote>
  <p>So <code>column1</code> must be the <code>PostTypeID</code> column in my <code>RETURNS TABLE</code> definition. But I am selecting <code>NULL AS PostTypeID</code> so why is it not just returning NULL?</p>
  <p>If I run <code>SELECT * FROM utility.rewrite(_postid = 0, _url := 'wikipedia.org')</code> then it works fine. But I don't want <code>0</code> to be returned, I want NULL.</p>