Re: Oddity with NOT IN - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: Oddity with NOT IN
Date
Msg-id 87oa55dc1l.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: Oddity with NOT IN  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Oddity with NOT IN  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Re: Oddity with NOT IN  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-hackers
>>>>> "Pavel" == Pavel Stehule <pavel.stehule@gmail.com> writes:
>> Well now I feel dumb...>> >> It would be very useful if we had some way to warn users about stuff>> like this.
Emittinga NOTICE comes to mind.
 
Pavel> This can be valid query

It can be, but it essentially never is. The cases where you genuinely
want a correlated IN query are rare, but even then there would be
something in the targetlist that referenced the inner query.

The easy to catch case, I think, is when the targetlist of the IN or NOT
IN subquery contains vars of the outer query level but no vars of the
inner one and no volatile functions. This can be checked for with a
handful of lines in the parser or a couple of dozen lines in a plugin
module (though one would have to invent an error code, none of the
existing WARNING sqlstates would do).

Maybe David Fetter's suggested module for catching missing WHERE clauses
could be expanded into a more general SQL-'Lint' module?

-- 
Andrew (irc:RhodiumToad)



pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: No longer possible to query catalogs for index capabilities?
Next
From: Jim Nasby
Date:
Subject: Re: Oddity with NOT IN