union in subselect?

Поиск
Список
Период
Сортировка
От Gary Stainburn
Тема union in subselect?
Дата
Msg-id 01073115421207.11590@gary.ringways.co.uk
обсуждение исходный текст
Ответы Re: union in subselect?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi all,

Can you use (or work around towards) a union in a subquery?

I have :-

Members
mid int4;
mnec bool; -- many NEC members

Positions (one position = one holder - excludes  NEC)
posn    char(4);
pholder int4; -- refers to mid

Actions
caction  char(4) -- e.g. UPDT = update team
cposn    char(4) -- refers to posn
clevle    int4 -- increasing permission level

select 'NEC'  as posn from members where mid = 81 and mnec = true;posn
------NEC
(1 row)

select posn from positions where pholder = 81;posn
------MSECITAREG
(3 rows)

select posn from positions where pholder = 81 union select 'NEC' as posn from 
members where mnec = true and mid = 81;posn
------ITAMSECNECREG
(4 rows)

So far so good.
select * from actions where cposn in (select posn from positions where 
pholder = 81);caction | cposn | clevel
---------+-------+--------ENQT    | REG   |      2ENQM    | REG   |      2AMET    | REG   |      2AMET    | ITA   |
3
 

Still works - looking good

select * from actions where cposn in (select posn from positions where pholder
= 81 union select 'NEC' as posn from members where mnec = true and mid = 81);

gives me:

ERROR:  parser: parse error at or near "union" 

-- 
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Big table - using wrong index - why?
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Get name of columns in a table