Hello,
How would one go about implementing custom rules for sorting?
I have a table with a column that contains text strings. These are
complex enough that they can't be sorted using plain ASCII/UTF-8, but
they do have ordinality. The entries need to be parsed (split up in
fields, but depending on the format there may be different sub-fields,
each relevant to their order).
Currently I have the sorting logic implemented in python. I
implemented an object to represent a row and then implemented all the
comparison operators for this object. Once this was done I could use
the standard sorted() function.
It would be nice if the database could output the "proper" (read:
custom) order using a simple "ORDER BY <column_name>".
Is there something analogous to python's declaring objects and their
comparison operators in PostgreSQL? Something like defining custom
column type which have custom comparison operators? I would prefer to
implement the comparison logic in C if possible.
--
Kind regards,
Jan Danielsson