Question

excuse the disturbance, but a comparison does not give me a boolean value, because the sum of the attributes does not return an integer value, but bigint. How do you add up the values of three queries? I tried with 'UNION' and with + but it gives me error.

case when(--for example 8=8
/*8=*/      (select count(*) from voto where new.data=voto.data and 
voto_palese='favorevole') =(
/*=8*/       ((
    (select count(*) from voto where new.data=voto.data and 
voto_palese='favorevole')
     UNION(select count(*) from voto where new.data=voto.data and 
voto_palese='contrario') UNION 
     (select count(*) from voto where new.data=voto.data and 
voto_palese='astenuto'))/2)+1) and 
      (select count(*) from voto where new.data=voto.data 
 and(voto.ddl=new.ddl or voto.mozione=new.mozione))
           )
 then new.esito='approvato'
 else new.esito='non approvato'
 end, --esito, 


ERRORE:  l'argomento di AND deve essere di tipo booleano, non bigint
LINE 34:           (select count(*) from voto where new.data=voto.dat...
               ^
QUERY:  insert into public.votazione(
       mozione,
       ddl,
       codice,
       favorevoli,
       votanti,
       contrari,
       astenuti,
       esito,
       tipo_assemblea,
       seduta_numero,
       data,
       assenti,
       missione)                
 values((select codice from mozione where codice=new.mozione and 
 mozione.data=new.data),--mozione, 
 (select titolo from ddl where titolo=new.ddl), --ddl, 
 (select codice from ddl where new.ddl=ddl.titolo), --codice, 
 (select count(*) from voto where new.data=voto.data and
                               voto_palese='favorevole'), --favorevoli, 
 ((select count(*) from voto where new.data=voto.data and
                               voto_palese='favorevole')
 UNION(select count(*) from voto where new.data=voto.data and
                               voto_palese='contrario') UNION 
       (select count(*) from voto where new.data=voto.data and
                               voto_palese='astenuto')), --votanti, 
 (select voto_palese from voto where data=new.data and 
 voto_palese='contrario'), --contrari, 
 (select voto_palese from voto where data=new.data and 
  voto_palese='astenuto'), -- astenuti, 
 case when(--for example 8=8
/*8=*/      (select count(*) from voto where new.data=voto.data and 
voto_palese='favorevole') =(
 /*=8*/       ((
    (select count(*) from voto where new.data=voto.data and 
 voto_palese='favorevole')
     UNION(select count(*) from voto where new.data=voto.data and 
 voto_palese='contrario') UNION 
     (select count(*) from voto where new.data=voto.data and 
 voto_palese='astenuto'))/2)+1) and 
      (select count(*) from voto where new.data=voto.data 
 and(voto.ddl=new.ddl or voto.mozione=new.mozione))
           )
 then new.esito='approvato'
 else new.esito='non approvato'
 end, --esito, 
 (select tipo_assemblea from ordine_del_giorno_ass_cam_e_sen where 
 data=voto.data), --tipo_assemblea, 
 (select seduta_numero from ordine_del_giorno_ass_cam_e_sen where 
 data=voto.data), --seduta_numero, 
 (SELECT data from ordine_del_giorno_ass_cam_e_sen where  
   new.tipo_assemblea=ordine_del_giorno_ass_cam_e_sen.tipo_assemblea and 
 ordine_del_giorno_ass_cam_e_sen.data=voto.data), --data, 
 (select count(*) from timbratura_giornaliera where presenze='Assente' and 
 new.data=timbratura_giornaliera.data), --assenti, 
 (select count(*) from timbratura_giornaliera where presenze='In missione' 
 and new.data=timbratura_giornaliera.data) -- missione
 )
  CONTEXT:  funzione PL/pgSQL inserimento_votazione() riga 4 a istruzione SQL

  ********** Error **********

  ERRORE: l'argomento di AND deve essere di tipo booleano, non bigint
   SQL state: 42804
  Context: funzione PL/pgSQL inserimento_votazione() riga 4 a istruzione SQL
Was it helpful?

Solution

You should use a comparison operator like > < = >= <=

create table t (id int);
select case when (select count(*) from t) then 1 else 0 end

ERROR: argument of CASE/WHEN must be type boolean, not type bigint LINE 1: select case when (select count(*) from t) then 1 else 0 end

select case when (select count(*) from t) > 0 then 1 else 0 end
                                          ^^^
| case |
| ---: |
|    0 |

db<>fiddle here

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top