Search Postgresql Archives

Implementing DB2's "distinct" types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux