Joseph S <jks(at)selectacast(dot)net> writes:
> Actually sacode is an int2.
Ah. 8.2 is not very good at proving cross-type predicate conditions,
because it lacks the concept of an operator family. You need to declare
the index this way:
create index d2i on d2 (sgcode, sacode)
WHERE sacode IS NOT NULL AND sacode > 0::int2;
(As previously noted, you don't really need the IS NOT NULL part of the
condition, but that isn't what's causing the problem here.)
regards, tom lane