Question about EXISTS

From: Excite Holidays <ehtech1(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Question about EXISTS
Date: 2012-06-25 02:19:43
Message-ID: CAFJQeEMhHh=3Gnw6m8G0ZdjArCqRvT3XQYqn+fe+cuRcqOS7bQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have been making some test with EXISTS and I found I case that I do not
understand too well:

CREATE TABLE testing (
number_id serial,
number1 integer,
number2 integer
);
INSERT INTO testing (number1, number2) VALUES (1,1),(1,2),(2,3);

SELECT *
FROM testing
WHERE EXISTS (SELECT 1 FROM testing WHERE testing.number_id = number_id AND
number1 = 1);

As far I understand the documentation the select query should return row 1
and 2, but it is returning 1, 2 and 3.

Why is this happening ?

PS_ PostgreSQL 9.1.1 on i686-pc-linux-gnu, compiled by gcc (Debian
4.3.2-1.1) 4.3.2, 32-bit

Regards,
Ruben

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-06-25 02:52:39 Re: Question about EXISTS
Previous Message Chris Travers 2012-06-25 01:48:28 Re: Feature discussion: Should syntax errors abort a transaction?