Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set datatype on END AS in CASE ELSE statement – PostgreSQL

I want to make INT be the data type for this column I’m creating. How do I do that? I tried adding AS INT to the end of END AS "salary_deviation" but that does not work. I tried wrapping END AS in CAST() but that didnt work either.

   CASE 
        WHEN c.salary = pair.salary THEN '6'
        
        WHEN c.salary-pair.salary <= 25000 THEN '5'
        
        WHEN c.salary-pair.salary <= 50000 THEN '4'
        
        WHEN c.salary-pair.salary <= 75000 THEN '3'

        WHEN c.salary-pair.salary <= 100000 THEN '2'
        
    ELSE
        '1'
    END AS "salary_deviation"

Any ideas on the syntax to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

   CASE 
        WHEN c.salary = pair.salary THEN 6 :: integer
        WHEN c.salary-pair.salary <= 25000 THEN 5
        WHEN c.salary-pair.salary <= 50000 THEN 4
        WHEN c.salary-pair.salary <= 75000 THEN 3
        WHEN c.salary-pair.salary <= 100000 THEN 2
    ELSE 1
    END AS "salary_deviation"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading