pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Christopher Dedels <cdedels@mygeotivity.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: dynamic rules?
Date: Fri, 4 Jun 2004 11:13:40 -0500
Message-ID: <20040604161340.GA15526@wolff.to> (raw)
In-Reply-To: <20040604043444.845E4D1B1DF@svr1.postgresql.org>
References: <20040604043444.845E4D1B1DF@svr1.postgresql.org>

On Thu, Jun 03, 2004 at 21:32:47 -0700,
  Christopher Dedels <cdedels@mygeotivity.com> 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.



view thread (3+ messages)  latest in thread

Message-ID: <20040604161340.GA15526@wolff.to>
Permalink:  ../20040604161340.GA15526@wolff.to/
Also on:    postgresql.org/message-id/20040604161340.GA15526@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, cdedels@mygeotivity.com
  Subject: Re: dynamic rules?
  In-Reply-To: <20040604161340.GA15526@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox