pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: silly sad <sad@bankir.ru>
To: pgsql-sql@postgresql.org
Subject: Re: [GENERAL] Schema design / joins
Date: Tue, 04 May 2010 16:05:09 +0400
Message-ID: <4BE00D75.30204@bankir.ru> (raw)
In-Reply-To: <7027958f-bbe6-4571-9659-71dc4b317344@e2g2000yqn.googlegroups.com>
References: <7027958f-bbe6-4571-9659-71dc4b317344@e2g2000yqn.googlegroups.com>

> __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.



view thread (2+ messages)

Message-ID: <4BE00D75.30204@bankir.ru>
Permalink:  ../4BE00D75.30204@bankir.ru/
Also on:    postgresql.org/message-id/4BE00D75.30204@bankir.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sad@bankir.ru
  Subject: Re: [GENERAL] Schema design / joins
  In-Reply-To: <4BE00D75.30204@bankir.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox