[Dbix-class] Lazy Columns

Bill Moseley moseley at hank.org
Wed May 12 13:16:57 GMT 2010


On Wed, May 12, 2010 at 1:08 AM, Peter Rabbitson
<rabbit+dbic at rabbit.us<rabbit%2Bdbic at rabbit.us>
> wrote:

> Bill Moseley wrote:
> >
> > Is this the "blanket increment/decrement" that's referring to?
> >
> > sqlite> update track set pos =3D pos - 1 where cd =3D 1 and pos > 2;
> >
>
> No need for where conds and the like. The most minimal test case is
> to create a table with 1 column, with a unique constraint, and put
> in the numbers 1..5. Then try:
>
> UPDATE tab SET col =3D col + 1;
>

> and
>
> UPDATE tab SET col =3D col - 1;
>
> On sqlite (at least) on of these fails. Not sure for other databases,
> never had the time to test.
>


Seems to be the + 1 version.

Postgresql has same "problem."

Most of us work in just one or two databases, so indeed hard to test.
 That's why I was asking about a flag so users can tell dbic the approach to
use.

There's this trick, too, that seems to work on pg and sqlite:

UPDATE tab SET col =3D -col;
UPDATE tab SET col =3D -col + 1;

I just checked and our ordered tables tend to be in groups of 100 or less.
 Many less than 20, so it's not a huge issue.  A hundred updates is quite a
few compared to two.  I can't imagine having thousands of rows that I wanted
to have an order on.



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100512/eea=
2d1ba/attachment.htm


More information about the DBIx-Class mailing list