Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your query is broken in several places. It could look something like this:</p> <pre><code>UPDATE trk2 SET (id, track_id, track_point) = (next_id, x.track_fid, x.wkb_geometry) FROM ( SELECT id ,nextval('seq_id') AS next_id ,track_fid ,wkb_geometry FROM track_points_1 WHERE track_fid = 0 ) x WHERE trk2.id = x.id; -- adapt to your case </code></pre> <p>Or <em>simpler</em> (preferable syntax):</p> <pre><code>UPDATE trk2 SET (id, track_id, track_point) = (nextval('seq_id'), x.track_fid, x.wkb_geometry) FROM track_points_1 x WHERE x.track_fid = 0 AND trk2.id = x.id; -- adapt to your case </code></pre> <h3>Major points:</h3> <ul> <li><p>An <code>UPDATE</code> without a <code>WHERE</code> clause only makes sense if you really need to change each and every row in the table. Else it is wrong or at least sub-optimal.</p> <p>When you retrieve values from another table, you get a <code>CROSS JOIN</code> between target and source if you don't add a <code>WHERE</code> clause connecting target with source - meaning that every row of the target table will be updated with every row in the source table. This can take a very long time and lead to arbitrary results. The last <code>UPDATE</code> wins. In short: this is almost always complete nonsense and extremely expensive at that.</p> <p>In my example I link target and source by the <code>id</code> column. You have to replace that with whatever fits in your case.</p></li> <li><p>You <em>can</em> assign multiple values in one <code>SET</code> clause in an <code>UPDATE</code>, but you can only return a single value from a correlated subselect expression. Therefore, it is strictly not possible to have a subselect in a <code>SET</code> clause with multiple values.</p></li> <li><p>Your initial syntax error comes from a missing pair of parenthesis around your subselect. But adding that only reveals the error mentioned above.</p></li> <li><p>Depending on what you are after, you would include <code>nextval('seq_id')</code> in the subquery or in the <code>SET</code> clause directly. This can lead to very different results, especially when you have rows in the subquery that are not used in the <code>UPDATE</code>. </p> <p>I placed it in the <code>SET</code> clause because I suspect, that's what you want. The sequence of rows is still arbitrary. If you want more control over which numbers are assigned, you need to define what you want and then take a different route.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload