pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Jaime Casanova <el_vigia_ec@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: query with =ALL
Date: Mon, 14 Jun 2004 10:38:04 -0700 (PDT)
Message-ID: <20040614103144.L48103@megazone.bigpanda.com> (raw)
In-Reply-To: <BAY8-F116TMlxRjxUBc0007a4fd@hotmail.com>
References: <BAY8-F116TMlxRjxUBc0007a4fd@hotmail.com>


On Mon, 14 Jun 2004, Jaime Casanova wrote:

> i have an strange result here, i'm using 7.4.2 on redhat 8
>
> i have a query like this
>
> SELECT CPA.rub_codigo, RUB.rub_descripcion, CPA.cpa_valor,
> CPA.cpa_fechavencimiento
> FROM rec_m_cuadropagos CPA, rec_m_rubro RUB
> WHERE RUB.ent_codigo = CPA.ent_codigo AND RUB.rub_codigo = CPA.rub_codigo
> AND
>       CPA.ent_codigo = 1 AND CPA.sec_codigo = 1 AND CPA.ani_codigo =
> '2004-2005' AND
>       CPA.cic_codigo = 1 AND CPA.esp_codigo = 0 AND CPA.cur_codigo = 1 AND
>       CPA.cur_paralelo = ALL (SELECT cur_paralelo FROM aca_t_curso WHERE
> ent_codigo = 1 AND
>
> sec_codigo = 1 AND
>
> ani_codigo = '2004-2005' AND
>
> cic_codigo = 1 AND
>
> esp_codigo = 0 AND
>
> cur_codigo = 1)
>
> that bring no values but if i do this (the same query without the =ALL part)
>
> SELECT CPA.rub_codigo, RUB.rub_descripcion, CPA.cpa_valor,
> CPA.cpa_fechavencimiento
> FROM rec_m_cuadropagos CPA, rec_m_rubro RUB
> WHERE RUB.ent_codigo = CPA.ent_codigo AND RUB.rub_codigo = CPA.rub_codigo
> AND
>       CPA.ent_codigo = 1 AND CPA.sec_codigo = 1 AND CPA.ani_codigo =
> '2004-2005' AND
>       CPA.cic_codigo = 1 AND CPA.esp_codigo = 0 AND CPA.cur_codigo = 1
>
> get a resultset, one would think that the =ALL subquery is filtering out
> that rows but the cur_paralelo has same values in both sides
>
> select distinct cur_paralelo from rec_m_cuadropagos WHERE ent_codigo = 1 AND
>
> sec_codigo = 1 AND
>
> ani_codigo = '2004-2005' AND
>
> cic_codigo = 1 AND
>
> esp_codigo = 0 AND
>
> cur_codigo = 1
> intersect
> SELECT cur_paralelo FROM aca_t_curso WHERE ent_codigo = 1 AND
>
> sec_codigo = 1 AND
>
> ani_codigo = '2004-2005' AND
>
> cic_codigo = 1 AND
>
> esp_codigo = 0 AND
>
> cur_codigo = 1
>
> this query proves that its result is 'A', 'B', 'C'
>
> any idea, is something wrong in my thinking?

AFAIK, The query isn't check all values that meet the other criteria
against all values of the subquery but instead check the value from each
row that meets the other criteria against all the values in the subquery.
If the values in the subquery are distinct, it's not going to return true.




view thread (12+ messages)  latest in thread

Message-ID: <20040614103144.L48103@megazone.bigpanda.com>
Permalink:  ../20040614103144.L48103@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20040614103144.L48103@megazone.bigpanda.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: sszabo@megazone.bigpanda.com, el_vigia_ec@hotmail.com
  Subject: Re: query with =ALL
  In-Reply-To: <20040614103144.L48103@megazone.bigpanda.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