Jana <jana.vasseru@gmail.com> writes:
> I would like to make this ordering on database side since there are two
> appliactions which use the data and both would have to reimplement the
> ordering mechanism. I read several articles on custom sorting, which show
> that i can use any function in the ORDER BY clause, however all the
> examples assume only one input value from which the custom function
> genereates some sort of automatically comparable value. However this
> always involves only a single field - which i cannot use since i need two
> rows to say which one is "higher" and "lower" -
Seems like what you need to do is set up this column as a custom
datatype with its own comparison operators. If you make a btree
index opclass for the datatype then ORDER BY will understand that
that's how it should sort the values.
regards, tom lane