Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using "AND" in where clause get error "argument must be type boolean"

Tags:

sql

postgresql

Error: argument of AND must be type boolean, not type character varying

SELECT 
    partno, 
    count(manufacturer) 
FROM 
    components 
WHERE 
    partno IN (SELECT partno FROM productions 
               WHERE 
                    year = 2005
                AND attr is NULL
              ) 
GROUP BY partno
UNION
SELECT 
    partno, 
    count(manufacturer) 
FROM components 
WHERE 
    partno IN (SELECT partno FROM productions 
               WHERE 
                   year = 2005
               AND attr is NULL
              ) 
GROUP BY partno
) 
AND (
        partno NOT IN (SELECT partno FROM components
    )
); 

The part after the union is to include all partno from components that are not in productions (they should be counted as 0)

like image 301
Celeritas Avatar asked Oct 02 '12 07:10

Celeritas


1 Answers

You have one bracket too many (after the attr IS NULL) and you have an aggregate function (the count in the second part) without a group by. Do you mean this:

select partno, count(manufacturer) 
from components 
where partno in 
(
   select partno from productions where year=2005 and attr is NULL
) 
group by partno

UNION

select partno, count(manufacturer) 
from components 
where partno in 
(
    select partno from productions where year=2005 and attr is NULL
) 
AND partno not in (select partno from components)
group by partno; 
like image 86
davek Avatar answered Nov 20 '22 21:11

davek