Is CREATE TYPE what you're looking for? http://www.postgresql.org/docs/8.0/static/sql-createtype.html
No. I'll try to give an exemple of what I want:
I suppose I have the following table CREATE TABLE experiment ( distance DOUBLE, time DOUBLE, speed DOUBLE );
I can do the following query : SELECT distance+time+speed FROM experiment;
This is a valid SQL query, but there is no physical meaning.
Now, I suppose I have "extended type". So the table is: CREATE TABLE experiment ( distance DOUBLE(m1), time DOUBLE(s1), speed DOUBLE(m1s-1), );
distance is of type DOUBLE and of unit METER time is of type DOUBLE and of unit SECOND speed is of type DOUBLE and of unit METER/SECOND
SELECT distance+time+speed FROM experiment; Would throw an error : "Incompatible unit M1, S1, M1S-1"
SELECT distance/time+speed FROM experiment; would succeed (obviously).
It may be possible to mess with domain/type to achieve a draft.
But I pretty sure that we need extend the type system to achieve it cleanly.
Cordialement, Jean-Gérard Pailloncy
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster