Re: self defined data type "with limit"? - Mailing list pgsql-hackers

From Michael Enke
Subject Re: self defined data type "with limit"?
Date
Msg-id 46829A34.4090107@wincor-nixdorf.com
Whole thread Raw
In response to Re: self defined data type "with limit"?  ("Joshua D. Drake" <jd@commandprompt.com>)
Responses Re: self defined data type "with limit"?  (Heikki Linnakangas <heikki@enterprisedb.com>)
List 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


pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: self defined data type "with limit"?
Next
From: Heikki Linnakangas
Date:
Subject: Re: self defined data type "with limit"?