How can i create a schema to the database?

Hi, how can i create a column which is an array of objects like
id: string;
name: string;
artist: string[];
cover: string;
id: string;
name: string;
artist: string[];
cover: string;
Thanks
10 Replies
garyaustin
garyaustin3y ago
In the dashboard table UI you just select text type and check array. In SQL you just use text [] when creating the table or ALTER TABLE candidate ADD COLUMN my_array_col text[]
Talajax
TalajaxOP3y ago
So i can create it as text[] and i won't have any problems?
garyaustin
garyaustin3y ago
Maybe I'm missing what you want to do. Are you wanting an array of the whole thing you showed, or is that your table you are looking for? If the whole thing you showed is an object and you want an array of those, then you would be looking at json or jsonb array column
Talajax
TalajaxOP3y ago
Yes, what i want is an array of that whole object
Talajax
TalajaxOP3y ago
So this should do the work?
No description
garyaustin
garyaustin3y ago
If you plan to search it then you probably should use jsonb.
Talajax
TalajaxOP3y ago
I see Thank you!
garyaustin
garyaustin3y ago
I'm not sure you even want an array column depending on what you are doing. A json/b column will take json including arrays inside the json.
garyaustin
garyaustin3y ago
Kamya
Learn | Hevo
How to Query JSONB Array of Objects in PostgreSQL
Learn how to Query JSONB Array of Objects in PostgreSQL and perform CRUD operations like CREATE, INSERT, SELECT, UPDATE, DELETE on the objects.
Medium
Working with a JSONB Array of Objects in PostgreSQL
Get, Add and Remove JSON Objects from an Array
Talajax
TalajaxOP3y ago
Thanks, i'll definatelly read it!

Did you find this page helpful?