I need to compare 2 strings that contains number and possibly text. for example I have this table:
id | label 1 | label 2 | 1 | 12/H | 1 | 2 | 4/A | 41/D | 3 | 13/A | 3/F | 4 | 8/A | 8/B | ..
I need to determine the direction so that if Label 1 < Label2 then Direction is W (with) else it is A (against). So I have to build a view that presents data this way:
id | Direction 1 | A | 2 | W | 3 | A | 4 | W | ..
I’m using postgres 9.2.
I split the two parts with
split_part()and check with an ad-hoc row type to check which label is bigger.The cases where both labels are equal or where either one is NULL have not been defined.
The CTE is not necessary, it’s just to make it easier to read.
-> sqlfiddle