Newbie table definition question
От | Ken Tozier |
---|---|
Тема | Newbie table definition question |
Дата | |
Msg-id | E32FC6A2-1F9B-11D9-A78B-003065F300E2@comcast.net обсуждение исходный текст |
Ответы |
Re: Newbie table definition question
|
Список | pgsql-general |
I'm a C/Objective C programmer and am having a bit of difficulty figuring out how to define SQL table approximations to things that are very easy to do in C/Objective C 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
В списке pgsql-general по дате отправления: