What is the best way to store lists in postgresql? What kind of field do I have to use? do I have to serialize it?
This is an example of data that I want to store:
id ( number ), name ( text ), events ( list )
1, john connor, ["aaa","bbb","ccc"]
2, jack bush, ["ttt","hhh","lll"]
...
How about using arrays? They are declared with [] for any size and [3] for array with 3 cells.
CREATE TABLE test1 (
id integer,
name text,
events text[]);
INSERT into test1 (id, name, events)
values(1, 'john connor', '{"aaa", "bbb","ccc"}'),
(2, 'jack bush', '{"ttt", "hhh","lll"}');
When inputting arrays, everything has to be enclosed in curly braces AND the curly braces have to be enclosed in single quotes. Finally, strings inside arrays must use double quotes.
Here's what the table looks like:
id name events
1 john connor {aaa,bbb,ccc}
2 jack bush {ttt,hhh,lll}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With