patternMinor
When is a result returned deterministic and when not?
Viewed 0 times
resultreturneddeterministicwhenandnot
Problem
if you execute a statement like this:
then you get a warning like this:
The result returned is non deterministic SQLCode=122
So far it's OK, because in this case you need an "order by" clause here.
But when you use the same statement inside of a BEGIN END block putting the values into some declared variables,
the warning does not come up!
Why?
Is the "order by" clause not needed here? Is this statement suddenly deterministic?...
(using SQL Anywhere 12)
select first field1, field2 from exampleTable where field1 = '1';then you get a warning like this:
The result returned is non deterministic SQLCode=122
So far it's OK, because in this case you need an "order by" clause here.
But when you use the same statement inside of a BEGIN END block putting the values into some declared variables,
BEGIN
declare varField1 varchar;
declare varField2 varchar;
select first field1, field2 into varField1, varField2
from exampleTable
where field1 = '1';
ENDthe warning does not come up!
Why?
Is the "order by" clause not needed here? Is this statement suddenly deterministic?...
(using SQL Anywhere 12)
Solution
Rows are not returned in any specific order in SQL (in reality they are likely to be in the same order most of the time) so without an ORDER BY any of the rows could be returned first. So it is non deterministic because this first record can change each time you run the query.
Wrapping it in a block doesn't make the answer deterministic, it just hides the warning.
Wrapping it in a block doesn't make the answer deterministic, it just hides the warning.
Context
StackExchange Database Administrators Q#11948, answer score: 4
Revisions (0)
No revisions yet.