Re: [sqlite] What is wrong with this trigger?

2013-11-16 Thread Simon Slavin
On 16 Nov 2013, at 3:14pm, James K. Lowden wrote: > On Sun, 10 Nov 2013 14:36:06 -0800 > Igor Korot wrote: > >> Well from strictly mathematical point of view maximum or minimum of >> nothing is nothing. And since nothing is 0, than it is zero. >

Re: [sqlite] What is wrong with this trigger?

2013-11-16 Thread James K. Lowden
On Sun, 10 Nov 2013 14:36:06 -0800 Igor Korot wrote: > Well from strictly mathematical point of view maximum or minimum of > nothing is nothing. And since nothing is 0, than it is zero. Who is the oldest female US president? You largest of a set must be a member of that

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Aleksey Tulinov
On 11/11/2013 12:36 AM, Igor Korot wrote: Well from strictly mathematical point of view maximum or minimum of nothing is nothing. And since nothing is 0, than it is zero. Thank you. max() can't simply pull 0 out of the air, for it 0 is the same random number as 1e-129 which might be also

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Simon Slavin
On 10 Nov 2013, at 10:36pm, Igor Korot wrote: > On Sun, Nov 10, 2013 at 8:44 AM, Simon Slavin wrote: > >> On 10 Nov 2013, at 4:26pm, Igor Korot wrote: >> >>> I'm updating the table when the program exit. >> >> There is not need

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Igor Korot
Simon, On Sun, Nov 10, 2013 at 8:44 AM, Simon Slavin wrote: > > On 10 Nov 2013, at 4:26pm, Igor Korot wrote: > >> I'm updating the table when the program exit. > > There is not need to update the table. In fact there's no need to store the > rank

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread John McKown
If Igor "must have a number" for the "max", even when there are no rows, then I'm certain that the coalesce() function is exactly what he needs to use. coalesce(max(id),0)) will give the maximum "id" value of the result set or 0 if there are no results in the result set (NULL). On Sun, Nov 10,

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Simon Slavin
On 10 Nov 2013, at 4:26pm, Igor Korot wrote: > I'm updating the table when the program exit. There is not need to update the table. In fact there's no need to store the rank values at all. > Now, I would expect for the max() function in this case to be > evaluated to 0

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Igor Korot
Simon et al, On Sun, Nov 10, 2013 at 7:18 AM, Simon Slavin wrote: > > On 10 Nov 2013, at 3:05pm, Igor Tandetnik wrote: > >> That rather depends on what value you deem to be the correct one. You've >> never explained the desired outcome of all this

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Simon Slavin
On 10 Nov 2013, at 3:05pm, Igor Tandetnik wrote: > That rather depends on what value you deem to be the correct one. You've > never explained the desired outcome of all this choreography. He's trying to keep each player's rank in his league table. And he wants the rank

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Igor Tandetnik
On 11/10/2013 12:54 AM, Igor Korot wrote: CREATE TRIGGER playersinleague_insert AFTER INSERT on playersinleague BEGIN UPDATE playersinleague SET current_rank = 1+ (select max( current_rank ) from playersinleague WHERE id = new.id), original_rank = current_rank WHERE id = new.id AND

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Simon Slavin
On 10 Nov 2013, at 12:34pm, John McKown wrote: > If you need a particular "default" value instead of a NULL, use the > coalesce() function. > > select coalesce(max(current_rank),0) FROM playersinleague WHERE id = 1; Purely for clarity's sake, and not to say

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread John McKown
I would expect NULL (empty string) as the result from a max (or any other summary) query which has "no rows". Any particular value wouldn't make too much sense to me. Why any particular value? 0 doesn't really make sense. Well no more or less sense than -1 or even -10372 (picked "at random"). If

Re: [sqlite] What is wrong with this trigger?

2013-11-10 Thread Igor Korot
I just tried to do: SELECT max(current_rank) FROM playersinleague WHERE id = 1; and I got an empty string and not 0. Is this a bug? Should max(field) return 0 if there is no records that satisfy criteria? Thank you. On Sat, Nov 9, 2013 at 9:54 PM, Igor Korot wrote: > Hi,