pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Bono <postgresql@aranya.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Bryce Nesbitt <bryce1@obviously.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Can function results be used in WHERE?
Date: Mon, 10 Jul 2006 23:11:16 -0500
Message-ID: <bf05e51c0607102111u63847a04i4d0b446dc7c91ebf@mail.gmail.com> (raw)
In-Reply-To: <8088.1152589020@sss.pgh.pa.us>
References: <44B29376.2030107@obviously.com>
	<bf05e51c0607101302w271c7773tdec47e76b192f2c9@mail.gmail.com>
	<44B2CFC7.7060101@obviously.com>
	<8088.1152589020@sss.pgh.pa.us>

On 7/10/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>
> But as far as the underlying misconception goes, you seem to think that
> "4" in the WHERE clause might somehow be taken as referring to the
> fourth SELECT result column (why you don't think that the "1" would
> likewise refer to the first result column isn't clear).  This is not so.
> "4" means the numeric value four.  There is a special case in ORDER BY
> and GROUP BY that an argument consisting of a simple integer literal
> constant will be taken as a reference to an output column.  This is an
> ugly kluge IMHO, but it's somewhat defensible on the grounds that
> neither ordering nor grouping by a simple constant has any possible
> real-world use; so the special case doesn't break anything of interest.
> This would certainly not be so if we were to randomly replace integer
> constants in general WHERE conditions with non-constant values.


I agree whole heartedly with Tom, using the number in the ORDER BY is ugly
and not recommended.  Using column names is much easier to read and is much
more maintainable by team members.  I have to admit the 4 < 1 did confuse me
at first.

-Aaron Bono

view thread (10+ messages)  latest in thread

Message-ID: <bf05e51c0607102111u63847a04i4d0b446dc7c91ebf@mail.gmail.com>
Permalink:  ../bf05e51c0607102111u63847a04i4d0b446dc7c91ebf@mail.gmail.com/
Also on:    postgresql.org/message-id/bf05e51c0607102111u63847a04i4d0b446dc7c91ebf@mail.gmail.com

 · 

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: postgresql@aranya.com, tgl@sss.pgh.pa.us, bryce1@obviously.com
  Subject: Re: Can function results be used in WHERE?
  In-Reply-To: <bf05e51c0607102111u63847a04i4d0b446dc7c91ebf@mail.gmail.com>

* 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