Re: GSoC 2017

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: GSoC 2017
Date: 2017-01-27 14:52:07
Message-ID: 1485528727275-5941383.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Stark wrote
> I don't think this even needs to be tied to currencies. I've often
> thought this would be generally useful for any value with units. This
> would prevent you from accidentally adding miles to kilometers or
> hours to parsecs which is just as valid as preventing you from adding
> CAD to USD.

There is already such a concept - not tied to currencies or units in
general. The SQL standard calls it DISTINCT types. And it can prevent
comparing apples to oranges.

I don't have the exact syntax at hand, but it's something like this:

create distinct type customer_id_type as integer;
create distinct type order_id_type as integer;

create table customers (id customer_id_type primary key);
create table orders (id order_id_type primary key, customer_id
customer_id_type not null);

And because those columns are defined with different types, the database
will refuse to compare customers.id with orders.id (just like it would
refuse to compare an integer with a date).

So an accidental join like this:

select *
from orders o
join customers c using (id);

would throw an error because the data types of the IDs can not be compared.

--
View this message in context: http://postgresql.nabble.com/GSoC-2017-tp5938331p5941383.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2017-01-27 14:53:46 Re: pg_ls_dir & friends still have a hard-coded superuser check
Previous Message Tom Lane 2017-01-27 14:42:15 Re: pg_ls_dir & friends still have a hard-coded superuser check