title: Casting NULL type when updating multiple rows
body: <p>I have a problem when I try to update many rows at the same time. </p>
  
  <p>Here is the table and query I use (simplified for better reading):</p>
  
  <p><strong>table</strong></p>
  
  <pre><code>CREATE TABLE foo
  (
      pkid integer,
      x integer,
      y integer
  )
  </code></pre>
  
  <p><strong>query</strong></p>
  
  <pre><code>UPDATE foo SET x=t.x, y=t.y FROM
  (VALUES (50, 50, 1),
          (100, 120, 2))
  AS t(x, y, pkid) WHERE foo.pkid=t.pkid
  </code></pre>
  
  <p>This query works perfectly, but when I try to execute a query where all <strong>x</strong> or <strong>y</strong> values are null, I get an error:</p>
  
  <p><strong>query with nulls</strong></p>
  
  <pre><code>UPDATE foo SET x=t.x, y=t.y FROM
  (VALUES (null, 20, 1),
          (null, 50, 2))
  AS t(x, y, pkid) WHERE foo.pkid=t.pkid
  </code></pre>
  
  <p><strong>error</strong></p>
  
  <pre><code>ERROR:  column "x" is of type integer but expression is of type text
  LINE 1: UPDATE foo SET x=t.x FROM
  </code></pre>
  
  <p>The only way to fix that is to change at least one of the values <code>(null, 20, 1)</code> to <code>(null:int, 50, 2)</code> but I can't do that, since I have a function which generates these "update multiple rows" query and it doesn't know anything about the column types.</p>
  
  <p>What's the best solution here? Is there any better update query for multiple rows? Is there any function or syntax like <code>AS t(x:gettype(foo.x), y:gettype(foo.y), pkid:gettype(foo.pkid))</code>?</p>