Re: [SQL] Derived columns / denormalization

2009-01-18 Thread Jamie Tufnell
On 1/17/09, Erik Jones wrote: > On Jan 15, 2009, at 8:06 PM, Tom Lane wrote: >> "Jamie Tufnell" writes: >>> item_count int -- this is derived from (select count(*) from items >>> where group_id = id) >>> ... >> >>> item_count would be updated by insert/update/delete triggers on the >>> items tabl

Re: [SQL] Derived columns / denormalization

2009-01-16 Thread Erik Jones
On Jan 15, 2009, at 8:06 PM, Tom Lane wrote: "Jamie Tufnell" writes: item_count int -- this is derived from (select count(*) from items where group_id = id) ... item_count would be updated by insert/update/delete triggers on the items table, hopefully that would ensure it is always correct

Re: [SQL] Derived columns / denormalization

2009-01-15 Thread Tom Lane
"Jamie Tufnell" writes: > item_count int -- this is derived from (select count(*) from items > where group_id = id) > ... > item_count would be updated by insert/update/delete triggers on the > items table, hopefully that would ensure it is always correct? > I'm wondering is what I'm trying to

[SQL] Derived columns / denormalization

2009-01-15 Thread Jamie Tufnell
Hi, I (think I) want to denormalize an aggregate for performance reasons. I think that is the right terminology, please correct me if not. Consider these two tables: items: id serial (pk), group_id int (fk), ... groups: id serial (pk), item_count int -- this is derived from (select count(*)