--
-- ### Verification of view with aggregation  ( failed before 2.49.23 )
-- 
--


drop if exists table t1;
create table t1 (
    a int,
    b int,
    c int);

insert into t1 values ( 1, 1, 10 );
insert into t1 values ( 1, 2, 20 );
insert into t1 values ( 2, 1, 5 );
insert into t1 values ( 2, 2, 42 );
insert into t1 values ( 2, 3, 42 );
insert into t1 values ( 3, 1, 1 );
insert into t1 values ( 3, 2, 65 );
insert into t1 values ( 3, 2, 12 );

drop if exists view v1;
create view v1 as
select
    a as a,
    b as b,
    sum ( c) as csum
from t1 group by a, b;


@
create procedure checkSelect001(msg out string(20)) return string(10)
begin
	var res string(10) = 'ERROR';
	var a int;
	var b int;
	var csum int;
	
	
	cursor xCur as

	       select a, b, csum from v1 where a = 3 and b = 2 and csum = 77;


        if fetch xCur into ( :a, :b, :csum ) = true
        then 
	     if :csum = 77 
	     then
		:res = 'ok';
	     end;
	end;
	close xCur;

	:msg = 'Aggregation view';

	return :res;
end;
@


:r = call checkSelect001(:msg);
insert into checklog values ('GATE-I', :msg, :r);

drop procedure checkSelect001;

drop if exists table t1;	
drop if exists view v1;


