If you want ORDER BY on the column to default to your custom ordering,
the only way is a distinct datatype that you can make your custom
opclass be the default for.

The domain idea might work, I'm not totally sure.  Defining
functions/operators on a domain is a bit ticklish because anything but
an exact match will get smashed to the domain base type and thus not
match your function.  I think though that in this case you might get
away with it because it would be an exact match --- it's worth a try

I gave it a try but

a) my original problem appeared: I can not specify a limit for a domain type:

  db=> create domain vchar as varchar;
  db=> create temp table a(a vchar(10));
  ERROR:  syntax error at or near "(" at character 28
  LINE 1: create temp table a(a vchar(10));

b) the sort order is the same as for varchar with my custom opclass (creating 
with default for type vchar).

So I will end up with my own type (for in/out functions simply calling that 
ones from varchar)
and using "user defined typmod" if available in an upcoming release.

Would it be a nice feature for standard postgres to support such a type? ;-)
The compare function simply would be:
if(len_left < len_right) return -1;
else if(len_left > len_right) return 1;
else return strncmp(left, right, len_left);

Thank you for discussion,

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at


Reply via email to