In a query I want to order by a column which has values like 'Foo', 'Bar', 'Baz'. Somehow I have to define an order. What I did was to create a small temporary table like so:
n i
'Foo' 1
'Bar' 2
'Baz' 3
I join the tables in my original query with this one on the column 'n', and then order by the column 'i'.
This works. But can I instead of creating a temporary table generate this table on the fly in a with statement for example and then use it? I know generate_series, but can I use that? Or is there another way?