Re: [HACKERS] GSoC 2017

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: [HACKERS] GSoC 2017
Дата
Msg-id 1485528727275-5941383.post@n3.nabble.com
обсуждение исходный текст
Ответ на Re: [HACKERS] GSoC 2017  (Greg Stark <stark@mit.edu>)
Ответы Re: [HACKERS] GSoC 2017  (Greg Stark <stark@mit.edu>)
Список 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.



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] pg_ls_dir & friends still have a hard-coded superuser check
Следующее
От: Robert Haas
Дата:
Сообщение: Re: [HACKERS] pg_ls_dir & friends still have a hard-coded superuser check