Thread: execute incorect query and get data

execute incorect query and get data

From
Marek Wróbel
Date:
PostgreSQL : 8.2
Operating system:  fedora RC4


--------

create table a (a1 integer);
create table b (b1 integer);

insert into a (a1) values (1);
insert into a (a1) values (2);
select a1 from b;

ERROR:  column "a1" does not exist at character 8

but :
select a1 from a where a1 not in (select a1 from b);
a1
---- 1 2
(2 rows)


when b is not empty :

insert into b (b1) values (1);

select a1 from b;
ERROR:  column "a1" does not exist at character 8

but :
select a1 from a where a1 not in (select a1 from b);a1
----
(0 rows)

select a1 from a where a1 in (select a1 from b);a1
---- 1 2
(2 rows)

Re: execute incorect query and get data

From
Tom Lane
Date:
Marek Wróbel <mwrobel@icentrum.pl> writes:
> create table a (a1 integer);
> create table b (b1 integer);
> insert into a (a1) values (1);
> insert into a (a1) values (2);
> select a1 from b;
> ERROR:  column "a1" does not exist at character 8
> but :
> select a1 from a where a1 not in (select a1 from b);

This is not a bug, it's an outer reference.  Read any SQL book ...
        regards, tom lane


Re: execute incorect query and get data

From
Marek Wróbel
Date:
Him,

Tom Lane napisał(a):
> Marek Wróbel <mwrobel@icentrum.pl> writes:
>> create table a (a1 integer);
>> create table b (b1 integer);
>> insert into a (a1) values (1);
>> insert into a (a1) values (2);
>> select a1 from b;
>> ERROR:  column "a1" does not exist at character 8
>> but :
>> select a1 from a where a1 not in (select a1 from b);
>
> This is not a bug, it's an outer reference.  Read any SQL book ...

of course... so sorry... I was such startled off result off this query,
that I can't see that...