IN/NOT IN operators

Started by Sergei Chernevover 27 years ago4 messagesgeneral
Jump to latest

Hello,
I want to ask you if there are the way to do:
select * from aa where (bb, ff) IN ((2,3),(4,5));
ERROR: parser: parse error at or near "2" :((

I see that it works with subselect:
select * from aa where (bb, ff) IN (select (bb,ff) from zz);

Thank you,
---------------------------
Sergei Chernev
Internet: ser@nsu.ru
Phone: +7-3832-397354

#2Jackson, DeJuan
djackson@cpsgroup.com
In reply to: Sergei Chernev (#1)
RE: [GENERAL] IN/NOT IN operators

This may not be the answer you want to hear but you could just
restructure it into an and-or query.
select * from aa where (bb = 2 and ff = 3) or (bb = 4 and ff = 5);
-DEJ

Show quoted text

-----Original Message-----
From: Sergei Chernev [SMTP:ser@nsu.ru]
Sent: Wednesday, September 30, 1998 4:15 AM
To: pgsql-general@hub.org
Subject: [GENERAL] IN/NOT IN operators

Hello,
I want to ask you if there are the way to do:
select * from aa where (bb, ff) IN ((2,3),(4,5));
ERROR: parser: parse error at or near "2" :((

I see that it works with subselect:
select * from aa where (bb, ff) IN (select (bb,ff) from zz);

Thank you,
---------------------------
Sergei Chernev
Internet: ser@nsu.ru
Phone: +7-3832-397354

#3Taral
taral@mail.utexas.edu
In reply to: Jackson, DeJuan (#2)
CNF vs DNF

select * from aa where (bb = 2 and ff = 3) or (bb = 4 and ff = 5);

I've been told that the system restructures these in CNF (conjunctive normal
form)... i.e. the above query turns into:

select * from aa where (bb = 2 or bb = 4) and (ff = 3 or bb = 4) and (bb = 2
or ff = 5) and (ff = 3 or ff = 5);

Much longer and much less efficient, AFAICT. Isn't it more efficient to do a
union of many queries (DNF) than an intersection of many subqueries (CNF)?
Certainly remembering the subqueries takes less memory... Also, queries
already in DNF are probably more common than queries in CNF, requiring less
rewrite.

Can someone clarify this?

Taral

#4Bruce Momjian
bruce@momjian.us
In reply to: Sergei Chernev (#1)
Re: [GENERAL] IN/NOT IN operators

[Charset koi8-r unsupported, filtering to ASCII...]

Hello,
I want to ask you if there are the way to do:
select * from aa where (bb, ff) IN ((2,3),(4,5));
ERROR: parser: parse error at or near "2" :((

I see that it works with subselect:
select * from aa where (bb, ff) IN (select (bb,ff) from zz);

Thank you,
---------------------------
Sergei Chernev
Internet: ser@nsu.ru
Phone: +7-3832-397354

select * from aa where (bb, ff) IN
(
select 2,3
union
select 4,5
)

Does this work?

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026