From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Implementing DB2's "distinct" types |
Date: | 2013-04-21 11:17:59 |
Message-ID: | kl0hrp$bm0$1@ger.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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 they are _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
From | Date | Subject | |
---|---|---|---|
Next Message | Atri Sharma | 2013-04-21 11:37:48 | Re: Implementing DB2's "distinct" types |
Previous Message | Adrian Klaver | 2013-04-21 00:08:36 | Re: Memory usage after upgrade to 9.2.4 |