Calculation dependencies in views

From: Rick Delaney <rick(at)consumercontact(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Calculation dependencies in views
Date: 2000-01-05 00:14:26
Message-ID: 38728CE2.C1756D3E@consumercontact.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a table with, say, a dozen fields and I want to end up with a view with
around 50 fields, calculated from the original dozen.

So it would be something like this:

CREATE VIEW final AS
SELECT
x, y, z,
(x + y) as a,
(y + z) as b,
(x + y) * z as c,
(y + z) * x as d,
(x + y) * z + x as e,
(y + z) * x + x as f
FROM my_table;

except my expressions are longer and more complicated. However, my expressions
do have similar dependencies and redundancies.

My question is what is a good way of dealing with this? I was going to do
something like

CREATE VIEW one AS
SELECT
id,
(x + y) as a,
(y + z) as b,
FROM my_table;

CREATE VIEW two AS
SELECT
m.id,
o.a * m.z as c,
o.b * m.x as d,
FROM my_table m, one o
WHERE m.id = o.id;

etc. but I'll end up with a lot of levels and joins going this route which I
expect will be pretty slow.

Can someone recommend anything to me? Should I be approaching this from a
completely different angle i.e other than views?

I'm pretty new at this so any pointers will be appreciated.

--Rick

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message omid omoomi 2000-01-05 00:37:42 Re: [SQL] datetime fields have '60' in seconds field
Previous Message Matthew Hagerty 2000-01-04 19:27:52 Re: [SQL] Triggers