Re: self defined data type "with limit"?

From: Michael Enke <michael(dot)enke(at)wincor-nixdorf(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: self defined data type "with limit"?
Date: 2007-06-29 13:28:17
Message-ID: 468508F1.2050206@wincor-nixdorf.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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
> anyway.

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;
CREATE DOMAIN
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,
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2007-06-29 13:28:47 Re: [PATCHES] Doc update for pg_start_backup
Previous Message Jim Nasby 2007-06-29 13:13:11 Re: Bgwriter LRU cleaning: we've been going at this all wrong