Re: SQL Technique Question

From: Rod Taylor <pg(at)rbt(dot)ca>
To: operationsengineer1(at)yahoo(dot)com
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SQL Technique Question
Date: 2006-06-15 21:21:46
Message-ID: 1150406506.777.468.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 2006-06-15 at 13:59 -0700, operationsengineer1(at)yahoo(dot)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);

--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Glaesemann 2006-06-15 21:41:08 Re: SQL Technique Question
Previous Message Andrew Sullivan 2006-06-15 21:03:22 Re: SQL Technique Question