Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Example 1:</p> <pre><code>update kalksad1 set brred=_brred from ( select row_number() over ( order by brred&lt;2 desc, brred=4 desc, brred&gt;=2 desc, brred ) as _brred, kalk_id as _kalk_id from kalksad1 where brkalk=2 order by _kalk_id ) as _ where kalk_id=_kalk_id and brred!=_brred; </code></pre> <p>Example 2:</p> <pre><code>update kalksad1 set brred=_brred from ( select row_number() over ( order by brred&lt;4 desc, brred!=1 desc, brred&gt;=4 desc, brred ) as _brred, kalk_id as _kalk_id from kalksad1 where brkalk=2 order by _kalk_id ) as _ where kalk_id=_kalk_id and brred!=_brred; </code></pre> <p>If you have unique index on <code>(brkalk,brred)</code> then it would be more complicated, as during renumbering there'll be duplicate <code>brred</code>.</p> <hr> <p>But for many rows I'd recommend using something which was very useful in the days of BASIC language on 8bit computers - number your rows with gaps.</p> <p>So instead of:</p> <pre><code>(26, 2, 1, 'text index 26 doc 2 row 1'), (30, 2, 2, 'text index 30 doc 2 row 2'), (42, 2, 3, 'text index 42 doc 2 row 3'), (43, 2, 4, 'text index 43 doc 2 row 4'), (12, 2, 5, 'text index 12 doc 2 row 5'), </code></pre> <p>use:</p> <pre><code>(26, 2, 1024, 'text index 26 doc 2 row 1'), (30, 2, 2048, 'text index 30 doc 2 row 2'), (42, 2, 3072, 'text index 42 doc 2 row 3'), (43, 2, 4096, 'text index 43 doc 2 row 4'), (12, 2, 5120, 'text index 12 doc 2 row 5'), </code></pre> <p>Then your examples would just look like:</p> <p> <li>Example 1: <code>update kalksad1 set brred=(2048+1024)/2 where kalk_id=43</code>, which would change it to:</p> <pre> (26, 2, 1024, 'text index 26 doc 2 row 1'), (43, 2, 1536, 'text index 43 doc 2 row 4'), (30, 2, 2048, 'text index 30 doc 2 row 2'), (42, 2, 3072, 'text index 42 doc 2 row 3'), (12, 2, 5120, 'text index 12 doc 2 row 5'), </pre> <p><li>Example 2: <code>update kalksad1 set brred=(4096+3072)/2 where kalk_id=43</code>, which would change it to:</p> <pre> (30, 2, 2048, 'text index 30 doc 2 row 2'), (42, 2, 3072, 'text index 42 doc 2 row 3'), (26, 2, 3584, 'text index 26 doc 2 row 1'), (43, 2, 4096, 'text index 43 doc 2 row 4'), (12, 2, 5120, 'text index 12 doc 2 row 5'), </pre> <p></p> <p>Only when there's no gap between rows where the target should be, you'd need to first renumber rows using for example:</p> <pre><code>update kalksad1 set brred=_brred*1024 from ( select row_number() over (order by brred) as _brred, kalk_id as _kalk_id from kalksad1 where brkalk=2 order by _brred desc ) as _ where kalk_id=_kalk_id; </code></pre> <p>This would be much aster than changing every row between source and target. But this'll only matter when there may be many rows to change.</p>
    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.
 

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