From: | Jeff Davis <pgsql(at)j-davis(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov> |
Subject: | Re: Distinct types |
Date: | 2008-11-07 17:39:18 |
Message-ID: | 1226079558.30638.15.camel@jdavis |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, 2008-11-01 at 16:38 -0400, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > On Friday 31 October 2008 17:01:05 Kevin Grittner wrote:
> >> (1) Can you compare a literal of the base type?
>
> > No, unless you create additional casts or operators.
>
> >> (2) Can you explicitly cast to the base type?
>
> > There is an implicit AS ASSIGNMENT cast between the base type and the distinct
> > type in each direction.
>
> Hmm ... so out-of-the-box, a distinct type would have no applicable
> functions/operators whatsoever. You couldn't even create an index on
> it. This seems a bit too impoverished to be useful. And given the
I didn't have any problem creating and using an index on a distinct type
at all.
Regards,
Jeff Davis
postgres=# create type mytype as int;
CREATE DOMAIN
postgres=# create table mytable (foo mytype);
CREATE TABLE
postgres=# insert into mytable values (1),(2);
INSERT 0 2
postgres=# create index myindex on mytable(foo);
CREATE INDEX
postgres=# set enable_seqscan = f;
SET
postgres=# explain select * from mytable order by foo desc;
QUERY
PLAN
---------------------------------------------------------------------------------
Index Scan Backward using myindex on mytable (cost=0.00..12.28 rows=2
width=4)
(1 row)
postgres=# select * from mytable order by foo desc;
foo
-----
2
1
(2 rows)
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2008-11-07 17:44:07 | Re: Distinct types |
Previous Message | Vladimir Sitnikov | 2008-11-07 17:28:53 | Re: Bitmap index - first look |