-1

In my application I have a very simple sql statement that looks like this:

select state from users;

And it gaves me the following result:

 state 
-------
     5
(1 row)

But I want to have some text in result instead of number. For example:

  • if state is equal to 5 state should be 'imported'
  • if state is equal to 4 state should be 'importing'

How can I do this?

Mateusz Urbański
  • 6,497
  • 13
  • 56
  • 120

1 Answers1

1

You need a simple case clause:

SELECT 
    CASE 
        WHEN state = 5 
            THEN 'imported' 
        WHEN state = 4 
            THEN 'importing' 
    END 
FROM users;
Radu Gheorghiu
  • 19,131
  • 15
  • 70
  • 102
Thanos Markou
  • 2,537
  • 3
  • 23
  • 32