With this kind of error, I typically use a subquery to do my dirty work. After playing around with this for a few minutes on
SQL Fiddle[^][
^], I came up with the SQL script below.
CREATE TABLE item
(
itemid integer,
item character varying(50)
);
INSERT INTO item(itemid, item)VALUES (1, 'pizza');
INSERT INTO item(itemid, item)VALUES (2, 'cake');
INSERT INTO item(itemid, item)VALUES (3, 'sandwich');
select string_agg(itemid || '-' || item,' | ') FROM ((SELECT DISTINCT item, itemid FROM item ORDER BY itemid)) t;