On Sat, 2008-11-01 at 16:38 -0400, Tom Lane wrote:
> Peter Eisentraut <peter_e@gmx.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)