Array

Array data

SELECT ARRAY['Lemon', 'Bat Limited Edition' ] AS example_purchased_products;

/*

example_purchased_products
------------------------------
{Lemon, "Bat Limited Edition"}

*/

Unnest array

SELECT UNNEST(ARRAY[123, 456, 789]) AS example_ids;

unested array

This is a great way to add tags to an item in a single column in a better way than using string split on csv values!

Array aggregate

SELECT product_type, ARRAY_AGG(DISTINCT model) AS models FROM products GROUP BY 1;

array_agg

String splitting to array

SELECT STRING_TO_ARRAY('hello there how are you?', ' ');

string to array


Backlinks