X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 30FB65282D for ; Mon, 16 May 2005 16:45:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26979-08 for ; Mon, 16 May 2005 19:45:47 +0000 (GMT) Received: from werhmsg.werh.noaa.gov (werhmsg.werh.noaa.gov [198.206.32.236]) by svr1.postgresql.org (Postfix) with ESMTP id 6E5C1528E6 for ; Mon, 16 May 2005 16:45:46 -0300 (ADT) Received: from [198.206.42.50] ([198.206.42.50]) by werhmsg.werh.noaa.gov (Netscape Messaging Server 4.15) with ESMTP id IGLLKA00.T8N for ; Mon, 16 May 2005 15:45:46 -0400 Message-ID: <4288F867.8090600@noaa.gov> Date: Mon, 16 May 2005 15:45:43 -0400 From: "Mark Fenbers" Organization: DoC/NOAA/NWS/OHRFC User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: sub-selects Content-Type: multipart/mixed; boundary="------------090105060904060804060108" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.127 tagged_above=0 required=5 tests=AWL, HTML_40_50, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200505/116 X-Sequence-Number: 21429 This is a multi-part message in MIME format. --------------090105060904060804060108 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Is there a way to make a query more efficient by executing a sub-select only once?

In a query such as:

SELECT a, (select b from c where d = e limit 1), npoints( (select b from c where d = e limit 1) )
    FROM f
    WHERE isValid( (select b from c where d = e limit 1) );

I do the same sub-select 3 times in the query.  I tried the following:

SELECT a, (select b from c where d = e limit 1) AS g, npoints( g )
    FROM f
    WHERE isValid( g );

But this gave an error regarding "column 'g' does not exist".  How can I avoid making the same sub-select 3 times?

Mark
--------------090105060904060804060108 Content-Type: text/x-vcard; charset=utf-8; name="Mark.Fenbers.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Mark.Fenbers.vcf" begin:vcard fn:Mark Fenbers n:Fenbers;Mark org:DoC/NOAA/NWS/OHRFC adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA email;internet:Mark.Fenbers@noaa.gov title:Sr. HAS Meteorologist tel;work:937-383-0430 x246 x-mozilla-html:TRUE url:http://weather.gov/ohrfc version:2.1 end:vcard --------------090105060904060804060108--