Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wa4Zx-0004QB-NX for pgsql-general@arkaria.postgresql.org; Tue, 15 Apr 2014 14:43:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wa4Zw-0007Ed-8a for pgsql-general@arkaria.postgresql.org; Tue, 15 Apr 2014 14:43:16 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZoXt-0003GV-5L; Mon, 14 Apr 2014 21:37:02 +0000 Received: from mxout-07.mxes.net ([216.86.168.182]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZoXk-0000Fb-4h; Mon, 14 Apr 2014 21:35:58 +0000 Received: from X201.home (unknown [193.251.178.45]) by smtp.mxes.net (Postfix) with ESMTPA id 499BB22E253; Mon, 14 Apr 2014 17:35:54 -0400 (EDT) Date: Mon, 14 Apr 2014 23:35:53 +0200 From: Vincent Veyron To: Robert DiFalco Cc: "pgsql-performance@postgresql.org" , "pgsql-general@postgresql.org" Subject: Re: Approach to Data Summary and Analysis Message-Id: <20140414233553.626524a7bb8718a451499a7f@libremen.org> In-Reply-To: References: X-Mailer: Sylpheed 3.2.0 (GTK+ 2.24.10; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.0 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On Mon, 14 Apr 2014 09:27:29 -0700 Robert DiFalco wrote: > I have several related tables that represent a call state. > > And so on for calls_connected, calls_completed, call_errors, etc. > > So for my question -- is the choice between these a personal preference > sort of thing or is there a right or wrong approach? Am I missing another > approach that would be better? Hi Robert, I guess a call state is subject to change, in which case you would have to shuffle records between tables when that happens? ISTM you should consider using only a 'calls' table, and add an 'id_call_state' field to it that references the list of possible states. This would make your queries simpler. create table call_state( id_call_state text PRIMARY KEY, libelle text); INSERT INTO call_state (id_call_state, libelle) VALUES ('calls_connected', 'Connected'), ('calls_completed', 'Completed'), ('call_errors', 'Error'); > CREATE TABLE calls ( > id BIGINT NOT NULL, // sequence generator id_call_state INTEGER NOT NULL REFERENCES call_state, > user_id BIGINT NOT NULL, > called TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, > > PRIMARY KEY (id), > FOREIGN KEY (user_id) REFERENCES my_users(id) ON DELETE CASCADE > ); -- Regards, Vincent Veyron http://libremen.com/ Legal case, contract and insurance claim management software -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general