Basically what I'm confused about is how to simulate arrays of structs in Postgres. For example, if I define a C struct like so
typedef struct Fruit { char name[32]; float price; }Fruit;
typedef struct Veggies { char name[32]; float price; } Veggies;
typedef struct GroceryBill { unsigned long date; long veggieCount; Veggies *veggies; long fruitCount; Fruit *fruits; } GroceryBill;
The nice thing in C is that I can assign an arbitrary array of identically structured "fruits" or "veggies" to a single field in a parent data structure. Is this possible in SQL?
My best guess would be to do something like this:
CREATE TABLE veggies ( name varchar(32) primary key, price real );
CREATE TABLE fruit ( name varchar(32) primary key, price real );
CREATE TABLE groceries ( date date; veggies varchar(32) references veggies, fruit varchar(32) references fruit, );
But it seems like the "veggies" and "fruit" fields within the "groceries" table would only reference a single entry in the "fruits" and "veggies" tables. Is there a way to have a field reference multiple entries in the fruits or veggies tables? Is there a better way to handle the whole problem?
Thanks for any help.
Ken
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster