From jkanter@virginia.edu Wed Jan 23 18:05:10 2002 Received: from mail.virginia.edu (mail.Virginia.EDU [128.143.2.9]) by postgresql.org (8.11.3/8.11.4) with SMTP id g0NI59l42266 for ; Wed, 23 Jan 2002 13:05:10 -0500 (EST) (envelope-from jkanter@virginia.edu) Received: from smtp.mail.virginia.edu by mail.virginia.edu id aa11626; 23 Jan 2002 13:04 EST Received: from jlk3xpc (d-128-19-222.bootp.Virginia.EDU [128.143.19.222]) by smtp.mail.Virginia.EDU (8.9.3/8.9.3) with SMTP id NAA17452 for ; Wed, 23 Jan 2002 13:04:49 -0500 Message-ID: <00d301c1a438$c30bd160$de138f80@virginia.edu> From: Jodi Kanter To: Postgres Admin List Subject: sub selects Date: Wed, 23 Jan 2002 13:07:03 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00D0_01C1A40E.DA171DD0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Archive-Number: 200201/148 X-Sequence-Number: 3035 This is a multi-part message in MIME format. ------=_NextPart_000_00D0_01C1A40E.DA171DD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I hope this is not too confusing..... I left my column names and table name= s as is but you should get the idea... I am doing the following: select usf_fk from am_spots where ams_pk in ((select min(ams_pk) from am_sp= ots where am_fk>135),(select max(ams_pk) from am_spots where am_fk>135); It works fine but I originally tried this: select usf_fk from am_spots where ams_pk in (select min(ams_pk), max(ams_pk= ) from am_spots where am_fk>135); I received an error saying that my subselect has too many fields. Did I use= the wrong syntax or is it just a postgres rule that you can't pull more th= an one field back in a sub select? Also, I need to now embed this entire select statement into another select = statement such as: select spot_identifier from al_spots where als_pk in (SELECT STATMENT ABOVE) Can I do this? Is there any easier way that I cannot see? Any suggestions w= ould be appreciated. Thanks Jodi ------=_NextPart_000_00D0_01C1A40E.DA171DD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I hope this is not too confusing..... I left my column names and table= =20 names as is but you should get the idea...
 
I am doing the following:
 
select usf_fk from am_spots where ams_pk in ((select min(ams_pk) from= =20 am_spots where am_fk>135),(select max(ams_pk) from am_spots where=20 am_fk>135);
 
It works fine but I originally tried this:
 
select usf_fk from am_spots where ams_pk in (select min(ams_pk),=20 max(ams_pk) from am_spots where am_fk>135);
 
I received an error saying that my subselect has too many fields. Did = I use=20 the wrong syntax or is it just a postgres rule that you can't pull more tha= n one=20 field back in a sub select?
 
Also, I need to now embed this entire select statement into another se= lect=20 statement such as:
 
select spot_identifier from al_spots where als_pk in (SELECT= =20 STATMENT ABOVE)
 
Can I do this? Is there any easier way that I cannot see? Any suggesti= ons=20 would be appreciated.
Thanks
Jodi
------=_NextPart_000_00D0_01C1A40E.DA171DD0-- From tgl@sss.pgh.pa.us Wed Jan 23 19:05:23 2002 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0NJ5Nl72120 for ; Wed, 23 Jan 2002 14:05:23 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g0NJ5Mf04553; Wed, 23 Jan 2002 14:05:22 -0500 (EST) To: Jodi Kanter cc: Postgres Admin List Subject: Re: sub selects In-reply-to: <00d301c1a438$c30bd160$de138f80@virginia.edu> References: <00d301c1a438$c30bd160$de138f80@virginia.edu> Comments: In-reply-to Jodi Kanter message dated "Wed, 23 Jan 2002 13:07:03 -0500" Date: Wed, 23 Jan 2002 14:05:21 -0500 Message-ID: <4550.1011812721@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200201/149 X-Sequence-Number: 3036 Jodi Kanter writes: > select usf_fk from am_spots where ams_pk in (select min(ams_pk), max(ams_pk= > ) from am_spots where am_fk>135); > I received an error saying that my subselect has too many fields. Did I use= > the wrong syntax or is it just a postgres rule that you can't pull more th= > an one field back in a sub select? It's an SQL92 rule: if you are doing "foo IN (subselect)" then the subselect must return one column to compare to foo. You are confusing this case with "foo IN (scalar expression, scalar expression, ...)" which is actually quite a different construct. regards, tom lane From waruna@nirmani.com Wed Sep 25 14:26:27 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0F6B2475F54 for ; Wed, 25 Sep 2002 10:26:27 -0400 (EDT) Received: from kumudu.nslk.com (kumudu.nslk.com [64.247.55.254]) by postgresql.org (Postfix) with ESMTP id 6D57147628C for ; Wed, 25 Sep 2002 10:26:23 -0400 (EDT) Received: from [203.94.94.112] (helo=W) by kumudu.nslk.com with asmtp (Exim 3.36 #1) id 17uD7O-0006Yb-00 for pgsql-admin@postgresql.org; Wed, 25 Sep 2002 10:26:23 -0400 Message-ID: <003701c2649f$a5f6fc80$705e5ecb@A.GEEKIYANAGE> Reply-To: "Waruna Geekiyanage" From: "Waruna Geekiyanage" To: Subject: Sub SELECTS Date: Wed, 25 Sep 2002 20:27:11 +0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0034_01C264D1.ED428FA0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - kumudu.nslk.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [0 0] X-AntiAbuse: Sender Address Domain - nirmani.com X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/291 X-Sequence-Number: 5830 This is a multi-part message in MIME format. ------=_NextPart_000_0034_01C264D1.ED428FA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a select query with 2 sub selects. When I run that query CPU usage goes to 98% for postgres. Does sub selects eat more resources and slower the queries? Is there any alternatives to sub selects? ------=_NextPart_000_0034_01C264D1.ED428FA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have a select query with 2 sub=20 selects.
When I run that query CPU usage goes = to 98%=20 for postgres.
Does sub selects eat more resources a= nd slower=20 the queries?
Is there any alternatives to sub=20 selects?
------=_NextPart_000_0034_01C264D1.ED428FA0-- From sszabo@megazone23.bigpanda.com Fri Sep 27 16:15:33 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3D313476452 for ; Fri, 27 Sep 2002 12:15:33 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id CB0AC4763DD for ; Fri, 27 Sep 2002 12:15:32 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 05F96D61C; Fri, 27 Sep 2002 09:15:34 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id EFC3D5C02; Fri, 27 Sep 2002 09:15:34 -0700 (PDT) Date: Fri, 27 Sep 2002 09:15:34 -0700 (PDT) From: Stephan Szabo To: Waruna Geekiyanage Cc: Subject: Re: Sub SELECTS In-Reply-To: <003701c2649f$a5f6fc80$705e5ecb@A.GEEKIYANAGE> Message-ID: <20020927091506.X40745-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/299 X-Sequence-Number: 5838 On Wed, 25 Sep 2002, Waruna Geekiyanage wrote: > I have a select query with 2 sub selects. > When I run that query CPU usage goes to 98% for postgres. > Does sub selects eat more resources and slower the queries? > Is there any alternatives to sub selects? It depends on what you're doing. The query and table schema would be useful.