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-27 17:11:16
Message-ID: 46829A34.4090107@wincor-nixdorf.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Joshua D. Drake wrote:
> Martijn van Oosterhout wrote:
>
>> On Wed, Jun 27, 2007 at 02:08:43PM +0200, Michael Enke wrote:
>>
>>> Hello everyone,
>>> I have created a new data type "mychar". How can I specify a limit
>>> for it?
>>>
>>> This (unlimited version) works fine:
>>> create table table_a(col_a mychar);
>>
>>
>> What you want is called "user defined typmod" and I don't beleive any
>> released version has it, but it will be in the next release.
>
>
> I believe he could do it with a domain.
>
> create domain myreal_char as varchar(50);
> create table table_a(col_a myreal_char);

My primary goal is to get quasi numeric ordering on text column, e.g.
1
2
10
Normal order with varchar would be
1
10
2

I can do it of course with lpad:
select * from table_a where lpad(col_a,18,'0') > lpad('12345',18,'0') order by lpad(col_a,18,'0');
but in this case no index can be used.

So I created my own type and operator classes and all works as I want (with use of index)
with the small exception that I can not specify a limit aka "user defined typmod".
Probably this is what I'm looking for.

Thanks,
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2007-06-27 17:42:05 Re: self defined data type "with limit"?
Previous Message Joshua D. Drake 2007-06-27 16:50:03 Re: self defined data type "with limit"?