Get IDs of similar rows by criteria I basically want to query this table: 

CREATE TABLE tbl (id, thing, price, type);
AS VALUES 
  (1, 'apple', 1.00, 'fruit'),
  (2, 'orang', 1.00, 'fruit'),
  (3, 'banan', 1.00, 'fruit'),
  (4, 'potat', 2.00, 'veg'),
  (5, 'carro', 2.00, 'veg'),
  (6, 'onion', 2.00, 'veg');


I want to grab the ids of records with the same attributes (in this case, price and type) so 1, 2, 3 and 4, 5, 6. 

I don't want to have to specify the $1.00 or fruit values, just group by whatever shows up in those columns, if that makes sense.
You can use the aggregate function array_agg() for this purpose.




select price, type, array_agg(id) ids
from   tbl
group by price, type



price | type  | ids    
----: | :---- | :------
 1.00 | fruit | {1,2,3}
 2.00 | veg   | {4,5,6}



dbfiddle here