pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddynamic rules?
3+ messages / 2 participants
[nested] [flat]
* dynamic rules?
@ 2004-06-04 04:32 Christopher Dedels <cdedels@mygeotivity.com>
0 siblings, 1 reply; 3+ messages in thread
From: Christopher Dedels @ 2004-06-04 04:32 UTC (permalink / raw)
To: pgsql-sql
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;'
Thanks,
Chris
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: dynamic rules?
@ 2004-06-04 16:13 Bruno Wolff III <bruno@wolff.to>
parent: Christopher Dedels <cdedels@mygeotivity.com>
0 siblings, 1 reply; 3+ messages in thread
From: Bruno Wolff III @ 2004-06-04 16:13 UTC (permalink / raw)
To: Christopher Dedels <cdedels@mygeotivity.com>; +Cc: pgsql-sql
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: dynamic rules?
@ 2004-06-04 18:18 Bruno Wolff III <bruno@wolff.to>
parent: Bruno Wolff III <bruno@wolff.to>
0 siblings, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2004-06-04 18:18 UTC (permalink / raw)
To: Christopher Dedels <cdedels@mygeotivity.com>; +Cc: pgsql-sql
On Fri, Jun 04, 2004 at 09:16:04 -0700,
Christopher Dedels <cdedels@mygeotivity.com> wrote:
> Bruno,
>
> Thanks for the response.
You should keep the discussion copied to the list as long as it is on topic.
That way other people can help out.
> I was wondering if I was possible to union the tables if necessary. So, if
> I choose type=1 it selects from only the 'one' table and likewise with 2.
> However, if I query type=1 or type=2 it will union the two and return the
> results from both tables.
That is a planner issue. I suspect that currently postgres won't be able
to see that a union isn't necessary. However unless performance is a real
problem for you, you are better off using simpler code to help maintainance.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-06-04 18:18 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-06-04 04:32 dynamic rules? Christopher Dedels <cdedels@mygeotivity.com>
2004-06-04 16:13 ` Bruno Wolff III <bruno@wolff.to>
2004-06-04 18:18 ` Bruno Wolff III <bruno@wolff.to>
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