开发者

rewriting query in PostgreSQL

开发者 https://www.devze.com 2023-01-14 03:07 出处:网络
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?

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 existin开发者_开发百科g 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消