Custom order

From: Jan Danielsson <jan(dot)m(dot)danielsson(at)gmail(dot)com>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Custom order
Date: 2017-05-25 17:23:13
Message-ID: 1ff2af82-f0f1-5787-9257-9bbf83890108@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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

Browse pgsql-novice by date

  From Date Subject
Next Message William Colls 2017-05-31 02:54:20 Error Relation xxxx does not exist when trying to insert new row
Previous Message David G. Johnston 2017-05-25 01:56:34 Re: Serializable Isolation Level