Re: Implementing DB2's "distinct" types - Mailing list pgsql-general

From Atri Sharma
Subject Re: Implementing DB2's "distinct" types
Date
Msg-id 5F6B5607-CA0B-43FE-BA07-83C46A11DE47@gmail.com
Whole thread Raw
In response to Implementing DB2's "distinct" types  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: Implementing DB2's "distinct" types
List pgsql-general

Sent from my iPad

On 21-Apr-2013, at 16:47, Thomas Kellerer <spam_eater@gmx.net> wrote:

> Hi,
>
> I recently stumbled upon a really cool feature in DB2: distinct types.
>
> DB2 lets you define your own types (just as Postgres) but with the added benefit that you can mark them such that
theyare _not_ comparable, e.g. to avoid comparing "apples to oranges". 
>
> Take the following example:
>
> create type sno as varchar(50)
>  with comparisons;
>  create type pno as varchar(50)
>  with comparisons;
>
> create table s
> (
>   sno    sno         not null primary key,
>   .... other columns
> );
>
> create table p
> (
>   pno    pno           not null primary key,
>   .... other columns
> );
>
> The following query will be rejected because sno and pno are not comparable (even though both are varchar columns):
>
>   select *
>   from p
>     join s on s.sno = p.pno;
>
> I wonder if a  similar behaviour can be achieved with Postgres' types as well.
>
> As a type definition in Postgres can also include comparison functions, I have the feeling that this should be
possible,but I don't have an idea on how to start to be honest. 
>
> Any ideas?
>
> Regards
> Thomas
>
>
>
>
>
>


Please mark this to pgsql-hackers, where you might get much better constructive feedback.

It does sound nice.

Atri

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Implementing DB2's "distinct" types
Next
From: Stefan Kaltenbrunner
Date:
Subject: Re: Roadmap for Postgres on AIX