X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4ADB1D1C4EE for ; Mon, 28 Jul 2003 16:48:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 01783-07 for ; Mon, 28 Jul 2003 13:47:23 -0300 (ADT) Received: from davinci.ethosmedia.com (209-128-84-228.bayarea.net [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 556AED1C4C8 for ; Mon, 28 Jul 2003 13:48:18 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3354109; Mon, 28 Jul 2003 09:48:37 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: oheinz@stud.fbi.fh-darmstadt.de, pgsql-sql@postgresql.org Subject: Re: Problem using Subselect results Date: Mon, 28 Jul 2003 09:47:21 -0700 User-Agent: KMail/1.4.3 References: <1058964708.3f1e84e407a8d@stud.fbi.fh-darmstadt.de> In-Reply-To: <1058964708.3f1e84e407a8d@stud.fbi.fh-darmstadt.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200307280947.21658.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/415 X-Sequence-Number: 14529 Oliver, > CREATE VIEW my_view AS SELECT b,c > (SELECT a, b FROM table2 WHERE b=1) my_ab, > (SELECT c FROM table3, my_ab WHERE table3.a=my_ab.a) my_c; This isn't possible in PostgreSQL, and I'm not sure it's possible anywhere. HOWEVER, if you put your subselects in the FROM clause instead, like so: CREATE VIEW my_sub AS SELECT my_ab.a, my_ab.b, my_c.c FROM (SELECT a, b FROM table2 WHERE b=1) my_ab, (SELECT a,c FROM table3, my_ab) my_c WHERE my_ab.a = my_c.a; OR you can mix-and-match subselect types: CREATE VIEW my_sub AS SELECT my_ab.a, my_ab.b, (SELECT c FROM table3, my_ab WHERE table3.a=my_ab.a) my_c FROM (SELECT a, b FROM table2 WHERE b=1) my_ab; Although in the simplistic examples above there's not much reason to use a subselect at all, of course. -- Josh Berkus Aglio Database Solutions San Francisco