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 76315D1B489 for ; Fri, 4 Jun 2004 13:08:05 -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 90732-03 for ; Fri, 4 Jun 2004 16:08:03 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 50672D1B467 for ; Fri, 4 Jun 2004 13:08:02 -0300 (ADT) Received: (qmail 15700 invoked by uid 500); 4 Jun 2004 16:13:40 -0000 Date: Fri, 4 Jun 2004 11:13:40 -0500 From: Bruno Wolff III To: Christopher Dedels Cc: pgsql-sql@postgresql.org Subject: Re: dynamic rules? Message-ID: <20040604161340.GA15526@wolff.to> Mail-Followup-To: Christopher Dedels , pgsql-sql@postgresql.org References: <20040604043444.845E4D1B1DF@svr1.postgresql.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040604043444.845E4D1B1DF@svr1.postgresql.org> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/34 X-Sequence-Number: 17979 On Thu, Jun 03, 2004 at 21:32:47 -0700, Christopher Dedels wrote: > Is it possible to create a select rule that returns results depending on a > where clause in the original select statement? > > For Example (oversimplified): > > CREATE TABLE one (data int); > CREATE TABLE two (data int); > > I make the query: > SELECT data FROM number WHERE type=1; > > If the type is 1 (type=1) I want to return 'SELECT data FROM one;' > If the type is 2 (type=2) I want to return 'SELECT data FROM two;' If you don't need to do updates, you can do this with a view. It would look something like: CREATE VIEW number (data, type) AS SELECT one.data, 1 FROM one UNION SELECT two.data, 2 FROM two; I didn't test the command so there might be a syntax error in it, but the approach should work.