PostgreSQL – Mimicing CHOOSE() function?

  Kiến thức lập trình

Good afternoon! Looking for some advice specific to Postgres. It does not have an equivalent to CHOOSE(), but I would like to use it to pick a random string from a list. I.e.:

 SELECT CHOOSE ('red', 'yellow', 'blue', 'green');

Is there an efficient way of replicating this in Postgres? Thanks!

Attempted to use CHOOSE() but it is not present in Postgres nor a known equivalent. Considering using RANDOM() to generate a value and making CASE statements to pick a string based on the value.

New contributor

ChrisD97 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.