Note Indices start at 0. Always quote "${arr[@]}" to preserve elements with spaces. ${#arr[@]} gives the length. += appends. unset 'arr[1]' removes an element (but does not reindex). Bash arrays are not available in sh/POSIX shell.
-- PostgreSQLSELECT
order_id,STRING_AGG(product_name,', 'ORDERBY product_name)AS products
FROM order_items oi
JOIN products p ON p.id= oi.product_idGROUPBY order_id;
Note STRING_AGG is standard SQL. MySQL uses GROUP_CONCAT with a default max length of 1024 characters - increase group_concat_max_len if results get truncated.
Frequently asked questions
How do you list values?
This task is covered in 2 stacks on this page: Bash & Linux, SQL. The "Arrays" snippet in Bash & Linux uses `arr=(val1 val2 val3)`.
Which command does the Bash & Linux example use?
The "Arrays" snippet uses `arr=(val1 val2 val3)`, from the Bash Scripting section of the Bash & Linux cheat sheet.
Which stacks cover "list values" on this page?
Bash & Linux, SQL. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Arrays": Indices start at 0. Always quote "${arr[@]}" to preserve elements with spaces. ${#arr[@]} gives the length. += appends. unset 'arr[1]' removes an element (but does not reindex). Bash arrays are not available in sh/POSIX shell.