title: Update with function called once for each row in Postgres 8.4
body: <p>I have the following UPDATE statement:</p>
  
  <pre><code>update mytable
     set a = first_part(genid()),
         b = second_part(genid()),
         c = third_path(genid())
   where package_id = 10;
  </code></pre>
  
  <p>In this example the function <code>genid()</code> is called three times for each row, which is wrong - I want it to be called only once for each row of <code>mytable</code>.</p>
  
  <p>I'm using PostgreSQL 8.4 database. How to write the correct update?</p>
  
  <p>I've tried something like this:</p>
  
  <pre><code>update mytable
     set a = first_part(g),
         b = second_part(g),
         c = third_path(g)
   where package_id = 10
    from genid() as g;
  </code></pre>
  
  <p>But it didn't work, because <code>genid()</code> has been called only <strong>once</strong> for the whole update statement.</p>