![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Dear PostgreSQL users, Presume you had a table of employees and the incentive payments they received additionally to their salaries. Now you would like to give someone the information, whether an employee received an incentive or not, but not the exact height of the payment. Is it possible to create a view of the table which converts the column containing the numeric values of the incentives to a column of the data type boolean? Thanks in advance, Julia |
#3
| |||
| |||
|
|
Dear PostgreSQL users, Presume you had a table of employees and the incentive payments they received additionally to their salaries. Now you would like to give someone the information, whether an employee received an incentive or not, but not the exact height of the payment. Is it possible to create a view of the table which converts the column containing the numeric values of the incentives to a column of the data type boolean? |
#4
| |||
| |||
|
|
So, the select would look something like this: select ename, empno,job,mgr,sal,cast(bonus as int)::boolean from emp where deptno=10 order by sal desc; |
|
select case when bonus is not null and bonus > 0 then true else false end from employees would be better. |
#5
| |||
| |||
|
|
Julia Jacobson wrote on 28.08.2010 21:10: Dear PostgreSQL users, Presume you had a table of employees and the incentive payments they received additionally to their salaries. Now you would like to give someone the information, whether an employee received an incentive or not, but not the exact height of the payment. Is it possible to create a view of the table which converts the column containing the numeric values of the incentives to a column of the data type boolean? select case when bonus is not null and bonus > 0 then true else false end from ... Thomas |
#6
| |||
| |||
|
|
Thanks a lot for your answer. Unfortunately, there is one exception where your solution doesn't work: If the bonus is less than 1 dollar, for example 0.50 dollar, your query would indicate that the employee didn't get a bonus. |
#7
| |||
| |||
|
|
This solution is better than mine. My solution doesn't handle null values, despite being more elegant. |
#8
| |||
| |||
|
|
On Sat, 28 Aug 2010 19:55:01 +0000, Mladen Gogala wrote: This solution is better than mine. My solution doesn't handle null values, despite being more elegant. Of course, that can be fixed by using the "coalesce" function, but then the elegance is lost. |
#9
| |||
| |||
|
| Julia Jacobson wrote on 28.08.2010 21:10: Dear PostgreSQL users, Presume you had a table of employees and the incentive payments they received additionally to their salaries. Now you would like to give someone the information, whether an employee received an incentive or not, but not the exact height of the payment. Is it possible to create a view of the table which converts the column containing the numeric values of the incentives to a column of the data type boolean? select case when bonus is not null and bonus > 0 then true else false end from ... |
#10
| |||
| |||
|
|
I would have suggested CASE as well. But is the NULL check really needed? IMHO "bonus > 0" can only be true if bonus is not 0. This is basic SQL standard, isn't it? |

|
Btw, I am not yet familiar with PostgreSQL's security model but the whole exercise might be moot if you cannot prevent access to the base table for those who are only allowed to see the flag version of the incentive. |
![]() |
| Thread Tools | |
| Display Modes | |
| |