Thread: intersect within a subquery

intersect within a subquery

From
Phil Glatz
Date:
I have a table cdb, indexed by cdb_id.
A second table map_flags to map to some other data.  It has a cdb_id field,
used to link to cdb.

I want to select a subset of cdb where records with a specific cdb_id is
present in two rows in map_flags, so I created a subquery to pull the
records from map_flags, using INTERSECT.  This query runs by itself ok, but
when I use it as a subquery, I get parse error at or near "intersect".

Isn't this legal?

SELECT c.cdb_id,c.company
FROM cdb c
WHERE c.cdb_id IN
   (SELECT m.cdb_id FROM map_flags m
   WHERE m.cflag_id=240
   INTERSECT
   SELECT m.cdb_id FROM map_flags m
   WHERE m.cflag_id=30)
ORDER BY c.company;


Re: intersect within a subquery

From
Tom Lane
Date:
Phil Glatz <phil@glatz.com> writes:
> present in two rows in map_flags, so I created a subquery to pull the
> records from map_flags, using INTERSECT.  This query runs by itself ok, but
> when I use it as a subquery, I get parse error at or near "intersect".

You need a newer PG release, evidently.

            regards, tom lane