On Thu, Feb 13, 2014 at 4:45 AM, Max Vlasov <max.vla...@gmail.com> wrote:

> Hi,
>
> probably was discussed and modified before, but I still can not understand
> some peculiarities with random column values.
>
> The table
>   Create table [TestTable] ([id] integer primary key)
>
> populated with 100 default values (thanks to CTE now made with a single
> query):
>
> with recursive
>   autoinc(id) as
>      (values(1) UNION ALL Select id+1 from autoinc where id < 100)
> insert into TestTable select id from autoinc
>
>
> So the following query
>
> select id, (select id from TestTable where id = abs(random() % 100)) as
> rndid from TestTable where id=rndid
>
> returns a single row (as expected), but this row contains different values
> for id and rndid. I suppose this is because rndid to be shown is calculated
> once, but the one used for comparison is calculated again and again. Is
> this correct behavior?
>

It is undefined behavior, subject to change depending the specific version
of SQLite, compile-time options, optimization settings, and the whim of the
query planner.

By analogy, in C/C++ if you write:

      int x = 1;
      int y = x++/x++;

What is the value for y?  0, 1, or 2?


-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to