0

I have a table I don't want to touch, but from this table I want to create many views that will serve different purposes/analyses.

In one case, I need to change a value based on a condition (-1 become some positive value).

Is it even possible to do that in PostgreSQL?

For example, -1 in the table will become 1 in the view if Col3='B':

+------+------+------+    +------+------+------+
| Col1 | Col2 | Col3 |    | Col1 | Col2 | Col3 |
+------+------+------+ >  +------+------+------+
|    1 |  3.5 | A    | >  |    1 |  3.5 | A    |
|    2 |   -1 | B    | >  |    2 |    1 | B    |
|    3 |   -1 | A    |    |    3 |   -1 | A    |
+------+------+------+    +------+------+------+

1 Answer 1

1

You need to modify the view an put the logic in the query:

select col1,
       (case when col3 = 'B' and col2 = -1 then 1 else col2 end) as col2,
       col3
from . . .
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.