I have a table orders
whose structure is like this:
create table orders (id serial primary key, created_at timestamp, updated_at timestamp, product_id varchar[]);
I for the product_id I am inserting data like this:
insert into orders values (1,now(),now(),'{"1","2"}');
the product_id
holds the different products that were ordered in a particular order. There is a entry in products
table for each of the product_id
.
Now I want to get the counts of the product_id
for a particular order.
Example: For the above insertion I made, I should get something like:
Id Count
1 2
How is it possible is postgresql?
Edit: Sorry for messing with the create table
query. It's a varchar[] instead of varchar(255)