Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 49A249FB6D3 for ; Thu, 29 Mar 2007 03:48:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 43449-01 for ; Thu, 29 Mar 2007 03:48:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 1C6F29FB69A for ; Thu, 29 Mar 2007 03:48:39 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l2T6mZv9054849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Mar 2007 23:48:38 -0700 (MST) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l2T6mYem032794; Thu, 29 Mar 2007 00:48:34 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l2T6mYkb032727; Thu, 29 Mar 2007 00:48:34 -0600 (MDT) (envelope-from mfuhr) Date: Thu, 29 Mar 2007 00:48:34 -0600 From: Michael Fuhr To: Phillip Smith Cc: pgsql-sql@postgresql.org Subject: Re: SELECT INSTEAD Message-ID: <20070329064833.GA47987@winnie.fuhr.org> References: <00ab01c771c4$1ec9aa50$9b0014ac@wbaus090> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00ab01c771c4$1ec9aa50$9b0014ac@wbaus090> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/343 X-Sequence-Number: 27981 On Thu, Mar 29, 2007 at 03:35:52PM +1000, Phillip Smith wrote: > I'm trying to create a view of the query below, but I'm being barked at > about "rules on SELECT must have action INSTEAD SELECT". I don't have any > rules in my database, and I don't know how this query is trying to create > one. http://www.postgresql.org/docs/8.2/interactive/rules-views.html "Views in PostgreSQL are implemented using the rule system." > The query does work if I just run it interactively. Any help would be > much appreciated. You showed two queries, not one. The error occurs because you're trying to create a view that creates a temporary table; you'll need to write the two queries as a single query that doesn't use a temporary table. Also, are you sure you need DISTINCT ON (m1.id)? What do you intend for that to do? Is id unique (PRIMARY KEY or UNIQUE)? And unless ORDER BY is necessary to determine the result set (as with DISTINCT ON) then consider leaving it out of the view definition -- if the outermost query (the query that selects from the view) needs a certain order than that's the proper place for ORDER BY. -- Michael Fuhr