tags:

views:

34

answers:

1

After a db schema change, what was a column is now computed in stored procedure. Is it possible to make this change seamless for application programs?

So that when a program sends a query like

SELECT id, 
       value 
  FROM table

...it instead gets a result of

SELECT id, 
       compute_value() AS value
  FROM table

I thought I could use a RULE, but it is not possible to create SELECT rule on existing table.

So the only other option seems to me to create a new table and a view with the name of the existing one. Which, because of the need for INSERT/UPDATE triggers for the view is too complicated. Then I'd rather update all the client applications.

+2  A: 

If you know you want to return value, you use a function rather than a stored procedure. Then you'd reference it like:

SELECT id,
       your_function_name(parameter) AS value
  FROM TABLE 

There's an example under "SQL Functions on Composite Types" in the documentation.

Creating a view using the statement above is ideal if your application needs the computed value constantly, otherwise I wouldn't bother.

OMG Ponies
Yep, a VIEW is the way to go.
Frank Heikens