From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Christopher Dedels <cdedels(at)mygeotivity(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: dynamic rules? |
Date: | 2004-06-04 16:13:40 |
Message-ID: | 20040604161340.GA15526@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Thu, Jun 03, 2004 at 21:32:47 -0700,
Christopher Dedels <cdedels(at)mygeotivity(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2004-06-04 17:05:13 | Re: ERROR: duplicate key violates unique constraint |
Previous Message | Bruno Wolff III | 2004-06-04 15:23:44 | Re: Difference between two times as a numeric value in a stored procedure. |