-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
  • 7,352
  • 15
  • 68
  • 133

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
  • 20,049
  • 16
  • 72
  • 107
Thanos Markou
  • 2,587
  • 3
  • 25
  • 32