You must a) join the 2 tables on the orderID ... where orderID=15 and then GROUP BY the result by the order ID and concat the orderlines by a custom aggregate function like: http://www.postgresql.org/message-id/db7789b.0309131210.625da358@xxxxxxxxxxxxxxxxxx -- View this message in context: http://postgresql.1045698.n5.nabble.com/Dynamic-insert-into-ARRAY-plpgsql-tp5791090p5791093.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general