Set Membership operator -- test group membership

Started by Sophie Yangabout 21 years ago4 messagesgeneral
Jump to latest
#1Sophie Yang
yangsophie@yahoo.com

Say I have a table tbl1 with two columns:
tbl1(a integer, b integer, c integer)

I want to select the rows in which a and b are members
of a list of integer pairs. The SQL in my mind is
something like:
select * from tbl1 where (a, b) in ((1, 20), (2,
30), (3, 50));

I know the SQL above does not work in PostgreSQL. I
wonder what is the proper way to use in PostgreSQL. I
tried "select * from tbl1 where (a, b) in ('{{1, 20},
{2, 30}, {3, 50}}')", and it doesn't work either.

Thanks!
Sophie

__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail

#2Igor Katrayev
igor.katrayev@nprb.org
In reply to: Sophie Yang (#1)
Re: Set Membership operator -- test group membership

Sophie,

The sql like this:
select * from tbl1 where (a, b) in ((1, 20), (2, 30), (3, 50));
works very well in PostgreSQL 8,

Sincerely,

Igor Katrayev, Data Systems Manager
North Pacific Research Board
1007 West Third Avenue, Suite 100
Anchorage, AK 99501
Phone: 907-644-6700
Fax: 907-644-6780
igor.katrayev@nprb.org

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Sophie Yang
Sent: Tuesday, June 14, 2005 11:09 AM
To: pgsql-general@postgresql.org
Cc: pgsql-novice@postgresql.org; pgsql-sql@postgresql.org
Subject: [GENERAL] Set Membership operator -- test group membership

Say I have a table tbl1 with two columns:
tbl1(a integer, b integer, c integer)

I want to select the rows in which a and b are members of a list of
integer pairs. The SQL in my mind is something like:
select * from tbl1 where (a, b) in ((1, 20), (2, 30), (3, 50));

I know the SQL above does not work in PostgreSQL. I wonder what is the
proper way to use in PostgreSQL. I tried "select * from tbl1 where (a,
b) in ('{{1, 20}, {2, 30}, {3, 50}}')", and it doesn't work either.

Thanks!
Sophie

__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

#3Sophie Yang
yangsophie@yahoo.com
In reply to: Igor Katrayev (#2)
Re: Set Membership operator -- test group membership

Thanks! Well, it is time to upgrade my PostgreSQL
7.4.2. :)

Sophie

-----Original Message-----
From: "Igor Katrayev" <igor ( dot ) katrayev ( at )
nprb ( dot ) org>
To: <pgsql-general ( at ) postgresql ( dot ) org>
Subject: Re: Set Membership operator -- test group
membership
Date: Tue, 14 Jun 2005 11:27:30 -0800

--------------------------------------------------------------------------------

Sophie,

The sql like this:
select * from tbl1 where (a, b) in ((1, 20), (2,
30), (3, 50));
works very well in PostgreSQL 8,

Sincerely,

Igor Katrayev, Data Systems Manager
North Pacific Research Board
1007 West Third Avenue, Suite 100
Anchorage, AK 99501
Phone: 907-644-6700
Fax: 907-644-6780
igor ( dot ) katrayev ( at ) nprb ( dot ) org

-----Original Message-----
From: pgsql-general-owner ( at ) postgresql ( dot )
org
[mailto:pgsql-general-owner ( at ) postgresql ( dot )
org] On Behalf Of Sophie Yang
Sent: Tuesday, June 14, 2005 11:09 AM
To: pgsql-general ( at ) postgresql ( dot ) org
Cc: pgsql-novice ( at ) postgresql ( dot ) org;
pgsql-sql ( at ) postgresql ( dot ) org
Subject: [GENERAL] Set Membership operator -- test
group membership

Say I have a table tbl1 with two columns:
tbl1(a integer, b integer, c integer)

I want to select the rows in which a and b are members
of a list of
integer pairs. The SQL in my mind is something like:
select * from tbl1 where (a, b) in ((1, 20), (2,
30), (3, 50));

I know the SQL above does not work in PostgreSQL. I
wonder what is the
proper way to use in PostgreSQL. I tried "select *
from tbl1 where (a,
b) in ('{{1, 20}, {2, 30}, {3, 50}}')", and it doesn't
work either.

Thanks!
Sophie

__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile
phone.
http://mobile.yahoo.com/learn/mail

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#4Oleg Bartunov
oleg@sai.msu.su
In reply to: Sophie Yang (#1)
Re: [SQL] Set Membership operator -- test group membership

Look contrib/intarray

On Tue, 14 Jun 2005, Sophie Yang wrote:

Say I have a table tbl1 with two columns:
tbl1(a integer, b integer, c integer)

I want to select the rows in which a and b are members
of a list of integer pairs. The SQL in my mind is
something like:
select * from tbl1 where (a, b) in ((1, 20), (2,
30), (3, 50));

I know the SQL above does not work in PostgreSQL. I
wonder what is the proper way to use in PostgreSQL. I
tried "select * from tbl1 where (a, b) in ('{{1, 20},
{2, 30}, {3, 50}}')", and it doesn't work either.

Thanks!
Sophie

__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83