I tried to download sqlite3-3.1.1beta.bin.gz to see if
this problem still exists, but my browser and wget both
report that the file is empty.

The following is from version 3.1.0. It is perhaps an
unusual use of a correlated subquery. If it's a bug that
someone wants to address, let me know and I'll create a
bug ticket (or maybe 2?).

sqlite> .schema t1
CREATE TABLE t1 (val  int, period text primary key, sumval int);
sqlite> select * from t1 ;
val         period      sumval    
----------  ----------  ----------
5           2001-3      --        
10          2001-4      --        
15          2002-1      --        
5           2002-2      --        
10          2002-3      --        
15          2002-4      --        
10          2003-1      --        
5           2003-2      --        
25          2003-3      --        
5           2003-4      --
sqlite> select a.period,
   ...>        (select sum(val) from t1
   ...>         where period between a.period and '2002-4') vsum
   ...> from t1 a where a.period between '2002-1' and '2002-4' ;
period      vsum      
----------  ----------
2002-1      45        
2002-2      30        
2002-3      25        
2002-4      15
sqlite> select period, vsum from
   ...> (select a.period,
   ...>         (select sum(val) from t1
   ...>          where period between a.period and '2002-4') vsum
   ...>  from t1 a where a.period between '2002-1' and '2002-4') 
   ...> where vsum < 45 ;
SQL error: no such column: val

Also, while playing around with this query, I entered
some bad SQL and got a segfault instead of an error:

sqlite> select a.period,
   ...>        (select sum(val) from t1
   ...>         where period between a.period and '2002-4') vsum
   ...> from t1 a where a.period between '2002-1' and '2002-4'
   ...>                 and vsum < 45 ;
Segmentation fault


Regards,
Kurt Welgehausen

Reply via email to