Re: [GENERAL] Schema design / joins

From: silly sad <sad(at)bankir(dot)ru>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [GENERAL] Schema design / joins
Date: 2010-05-04 12:05:09
Message-ID: 4BE00D75.30204@bankir.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> __Orgs__
> id
> name
>
> __Seasons__
> id
> org_id fk(orgs.id)
> name
>
> __Teams__
> id
> season_id fk(seasons.id)
> name
>
> __TeamFees__
> id
> team_id fk(teams.id)
> *org_id<--- (?put extra fk here to avoid many joins?)

NO.

instead of it
use triggers before insert/update

CREATE FUNCTION foo() RETURNS TRIGGER AS $$
BEGIN
SELECT org_id INTO new.org_id FROM __seasons__ WHERE id=new.season_id;
END;
$$ LANGUAGE plpgsql;

et cetera.

AND now other way lead you to the future.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David Weilers 2010-05-04 13:49:45 Foreign key constraint referencing a parent table
Previous Message Alvaro Herrera 2010-05-03 15:28:47 Re: WAL-files restore and nextval('PK')