ERROR: more than one row returned by a subquery used as an expression select distinct on (productkey) productkey ,category ,subcategory ,short_description ,long_description ,price ,weight ,cube ,(case when cube::float < 1 then 12 else (||/ cube::float)*12 end) as cube3 ,altPn ,case_unit ,vendorpn ,get_vendor(vend_key) as vend_name ,getmsg('', '07-0564') as msg ,substitute ,cust_item('', '07-0564') ,case when (productkey in (select productkey from reseller_orderlists where reseller_account = '' and account_id = '6519820627')) then true else false end as in_cart ,(select quantity from reseller_orderlists where reseller_orderlists.productkey = fatproducttable.productkey and reseller_account = '' and account_id = '6519820627') as quantity_in_cart ,(select reseller_orderlist_id from reseller_orderlists where reseller_orderlists.productkey = fatproducttable.productkey and reseller_account = '' and account_id = '6519820627') as id_in_cart from fatproducttable where (upper(productkey) = upper('07-0564') or upper(altPn) = upper('07-0564')) and productkey not in (select productkey from ignore_items_reseller) and productkey in (select productkey from reseller_pricing where account_id = '6519820627' and price is not null and price > 0) and ('f' = 't' or ('f' = 'f' and weight < 151)) and ('f' = 't' or ('f' = 'f' and weight < 151)) limit 1