X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 06ECC9FA5BE for ; Thu, 15 Jun 2006 18:23:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 52629-06 for ; Thu, 15 Jun 2006 18:23:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from jandor.look.ca (theta1.look.ca [207.136.80.122]) by postgresql.org (Postfix) with ESMTP id 2E8B49FA13E for ; Thu, 15 Jun 2006 18:23:23 -0300 (ADT) Received: from 209-161-214-225.dsl.look.ca ([209.161.214.225]) by jandor.look.ca with esmtp (Exim 4.20) id 1FqzJB-00085N-KE; Thu, 15 Jun 2006 21:23:21 +0000 From: Rod Taylor To: operationsengineer1@yahoo.com Cc: "pgsql-sql@postgresql.org" In-Reply-To: <20060615205922.4834.qmail@web33301.mail.mud.yahoo.com> References: <20060615205922.4834.qmail@web33301.mail.mud.yahoo.com> Date: Thu, 15 Jun 2006 17:21:46 -0400 Message-Id: <1150406506.777.468.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.6.2 FreeBSD GNOME Team Port X-SA-Exim-Mail-From: pg@rbt.ca Subject: Re: SQL Technique Question Content-Type: text/plain Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 3.1 (built Tue Feb 24 05:09:27 GMT 2004) X-SA-Exim-Scanned: Yes X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/186 X-Sequence-Number: 25422 On Thu, 2006-06-15 at 13:59 -0700, operationsengineer1@yahoo.com wrote: > i frequently join certain tables together in various > tables. > is it a good practice to leave this included in the > queries, as is, or should i factor it out somehow? if > i should factor it, how do i do so? Future proofing selects queries is difficult because they never throw errors. They just give different results. What you really want is an ASSERTION to disallow bad entries from being created in the first place but PostgreSQL doesn't do those yet. Yes, you can do it with triggers but those are annoying to create by the hundreds for development only purposes. I would tend to add all of the columns to select be selected out and have assertions in the code. This way you can detect incorrect values in development and disable those safety's for production. select t_inspect_result.inspect_result_pass , t_inspect.serial_number_id , t_serial_number.serial_number_id ... assert(t_inspect.serial_number_id = t_serial_number.serial_number_id); --