Re: order of clauses

From: Michael Fork <mfork(at)toledolink(dot)com>
To: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: order of clauses
Date: 2001-02-16 18:59:20
Message-ID: Pine.BSI.4.21.0102161352130.26187-100000@glass.toledolink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You didn't mention what version of Postgres, but in 7.1beta, you could do
the following (pretty sure on the syntax):

SELECT a.x/b.y FROM vals a, (SELECT y FROM vals WHERE y > 0) b WHERE (a.x
/ b.y) > 1;

In anything else, you could try a view:

CREATE VIEW valid_vals AS SELECT y FROM vals WHERE y > 0;
SELECT a.x/b.y FROM vals a, valid_vals b WHERE (a.x
/ b.y) > 1

Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio

On Wed, 14 Feb 2001, Patrick Welche wrote:

> create table vals (
> x float,
> y float
> );
> insert into vals values (2,4);
> insert into vals values (2,2);
> insert into vals values (2,1);
> insert into vals values (2,0);
> select x/y from vals where y>0 and x/y>1;
>
> will give a divide by zero error as A=(y>0) and B=(x/y>1) can be evaluated in
> any order (A and B = B and A). I obviously would like (y>0) to happen first,
> but I don't see how this can be achieved.. Any ideas?
>
> Cheers,
>
> Patrick
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rod Taylor 2001-02-16 19:01:07 SPI_finish()
Previous Message Mitch Vincent 2001-02-16 18:48:16 Re: Postgres slowdown on large table joins