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. -- Sent via pgsql-hackers mailing list (firstname.lastname@example.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers