0

I have a view. I want a function which returns rows from the view; however, I need to change one value in each of the rows I return.

I can do this using select and writing all the field names in the select clause and listing all the values including the one I change, but this makes the code very obscure.

Seems like I want a very light weight temporary table. I want to write something like:

update { select * from myView where f(row,x,y) }
     set column = y 

where x and y are arguments to my function, column is a column name from myView, and f is another function.

Is there something like this I can write? Thanks.

LenB
  • 1,126
  • 2
  • 14
  • 31

1 Answers1

0

Some pointers:

  • You can do this with another view in which you have to list all your columns separately: CREATE VIEW myViewModified AS SELECT y AS column, ... FROM myView; and after that you can use SELECT * FROM myViewModified WHERE f(row,x,y);
  • You could also write SELECT y AS column1modified, * FROM myView; in the code and use the column1modified. That way you can use the asterisk-symbol.
  • Listing all the values might make the code obscure but if you drive the code through Poor SQL you can make it look quite clean (it also helps if you are accustomed to reading SQL queries).
  • Why is SELECT * considered harmful?
Community
  • 1
  • 1
Simo Kivistö
  • 4,247
  • 3
  • 38
  • 42