Convert numeric status fields to readable text

A common problem is that status fields, category fields and similar have a numeric value, and it’s unclear to the user what those value mean.

The below transformation adds a column with a text label.

Example table Orders:

id
title
status
1
Order from ACME
0
2
Return from Company X
1
3
Order from Company Y
1
4
Order from Company Z
2

Following query will add a text column with a readable representation for the status:

SELECT
  *,
  CASE status
    WHEN 0
    THEN 'New order'
    WHEN 1
    THEN 'Processed'
    WHEN 2
    ELSE 'Paid'
  END AS status_name
FROM orders

The resulting table will be:

id
title
status
status_name
1
Order from ACME
0
New order
2
Return from Company X
1
Processed
3
Order from Company Y
1
Processed
4
Order from Company Z
2
Paid

Example in Peliqan:

image

Resulting table:

image