Ask a Question related to PostgreSQL / PGSQL, Design and Development.
-
Pailloncy Jean-Gerard #1
Extended unit
Hi,
My question is purely theoretical.
I add use in my time in University some software that use "extended
type".
For each variable, we define the mandatory "classic type" as integer,
float, double array of.
And we define an optional "extended type" as the unit in the MKSA
system (Meter, Kilogram, Second, Ampere) or any other unit we would
have previously define (eg. Currency).
This "extended type" was wonderful, because there was warning/error if
"extend type" does not match in any computation: you can not add apple
to orange.
I would appreciate to have such system in PostgreSQL.
Do you think, it is feasible ? unrealistic ?
Any comment ?
Cordialement,
Jean-Gérard Pailloncy
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
[url]http://archives.postgresql.org[/url]
Pailloncy Jean-Gerard Guest
-
changing unit
Hi. How can I make the unit of FH, centimeter? I want to make 6 squares(7 * 7 centimeter) inside A4.(FH 10 USER) -
[OT] Unit Tests and Encapsulation
This may be off-topic in a Ruby list, although I have noticed that a lot of folks involved with Ruby are also fond of Unit Testing so it may not be... -
Test::Unit in 1.8
So far I've noticed two changes in the Test::Unit included with 1.8. They've probably been in Test::Unit for I long time, but I'm just encountering... -
How to unit test CGI methods?
On Wed, Jul 30, 2003 at 10:08:35PM +0900, David Heinemeier Hansson wrote: Have a look at the source of ruby-fcgi from RAA (lib/fcgi.rb, class... -
Test::Unit GUI
nathaniel@NOSPAMtalbott.ws (nathaniel@NOSPAMtalbott.ws) wrote: Hello Nathaniel! Have you considered to include gtk2 patch for Test::Unit... -
Martijn van Oosterhout #2
Re: Extended unit
On Tue, Jan 25, 2005 at 10:40:15AM +0100, Pailloncy Jean-Gerard wrote:
I think it's a wonderful idea. You could use a similar mechanism to> Hi,
>
> My question is purely theoretical.
>
> I add use in my time in University some software that use "extended
> type".
> For each variable, we define the mandatory "classic type" as integer,
> float, double array of.
> And we define an optional "extended type" as the unit in the MKSA
> system (Meter, Kilogram, Second, Ampere) or any other unit we would
> have previously define (eg. Currency).
>
> This "extended type" was wonderful, because there was warning/error if
> "extend type" does not match in any computation: you can not add apple
> to orange.
implement:
- Currencies (so you can't add dollars to pounds)
- Timezone aware timestamps (so a time in Australia looks differet from
a time in Europe)
Probably much more.
I think it is definitly feasable. There's been discussion before. I> I would appreciate to have such system in PostgreSQL.
>
> Do you think, it is feasible ? unrealistic ?
> Any comment ?
think the best way syntax-wise would be to extend the type system
generically to have subtypes. For example currency(gbp) and siunit(A).
This would simplify operators. You could create a simple add operator
that checked the subtype and complained if they didn't match. A
multiply operator for siunit might even return the appropriate derived
unit. An advanced add unit for currency might lookup an exchange rate
table.
However, I think this might be a tricky (but very worthwhile) project.
Maybe create a subtypes table with the columns (oid, supertypeid,
subtypename) and use the oid here to identify the subtype in storage.
To be complete it would need to change:
- The parser to idenify the new type definitions
- pg_dump to dump these types
- input/output functions for these types
- handle storage
But with a bit of work it could be a nice project.
Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB9h3IY5Twig3Ge+YRAhluAKDfASkZAuZj+SV28i8QAH SmdNP/wACfYqYa
C9kmEz+fxX/v9XD2NCmd+TE=
=dbvl
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Roman Neuhauser #3
Re: Extended unit
# [email]jg@rilk.com[/email] / 2005-01-25 10:40:15 +0100:
Is CREATE TYPE what you're looking for?> I add use in my time in University some software that use "extended
> type".
> For each variable, we define the mandatory "classic type" as integer,
> float, double array of.
> And we define an optional "extended type" as the unit in the MKSA
> system (Meter, Kilogram, Second, Ampere) or any other unit we would
> have previously define (eg. Currency).
>
> This "extended type" was wonderful, because there was warning/error if
> "extend type" does not match in any computation: you can not add apple
> to orange.
>
> I would appreciate to have such system in PostgreSQL.
[url]http://www.postgresql.org/docs/8.0/static/sql-createtype.html[/url]
--
If you cc me or remove the list(s) completely I'll most likely ignore
your message. see [url]http://www.eyrie.org./~eagle/faqs/questions.html[/url]
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email]majordomo@postgresql.org[/email])
Roman Neuhauser Guest
-
Pailloncy Jean-Gerard #4
Re: Extended unit
> Is CREATE TYPE what you're looking for?
No. I'll try to give an exemple of what I want:> [url]http://www.postgresql.org/docs/8.0/static/sql-createtype.html[/url]
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
Pailloncy Jean-Gerard Guest
-
Alban Hertroys #5
Re: Extended unit
Martijn van Oosterhout wrote:
Indeed, you could even add a way to convert between different types if> On Tue, Jan 25, 2005 at 10:40:15AM +0100, Pailloncy Jean-Gerard wrote:>>>This "extended type" was wonderful, because there was warning/error if
>>"extend type" does not match in any computation: you can not add apple
>>to orange.
>
> I think it's a wonderful idea. You could use a similar mechanism to
> implement:
>
> - Currencies (so you can't add dollars to pounds)
> - Timezone aware timestamps (so a time in Australia looks differet from
> a time in Europe)
>
> Probably much more.
they are in the same categories; for example convert between dollars and
euro's or between degrees Celsius and degrees Fahrenheit (that's a
trickier one, the shell command 'units' returns wrong results there).
Of course, it's still not possible to add dollars and degrees
Fahrenheit... (hence the category concept I mentioned)
You could even determine that if you divide a quantity in meters by a
quantity in seconds that you're talking about a speed... I think there
are quite a few people on this planet who would be happy about that.
OTOH, it's probably not that a good idea to add all kinds of complicated
(read: "processor intensive") math to a database engine.
Just my 0.02 Euro.
--
Regards,
Alban Hertroys
MAG Productions
P: +31(0)53 4346874
F: +31(0)53 4346876
E: [email]alban@magproductions.nl[/email]
W: [url]http://www.magproductions.nl[/url]
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [email]majordomo@postgresql.org[/email]
Alban Hertroys Guest
-
Martijn van Oosterhout #6
Re: Extended unit
On Tue, Jan 25, 2005 at 05:17:21PM +0100, Alban Hertroys wrote:
I think it would be fabulous if it could be implemented as a generic> Martijn van Oosterhout wrote:>> >I think it's a wonderful idea. You could use a similar mechanism to
> >implement:
> >
> >- Currencies (so you can't add dollars to pounds)
> >- Timezone aware timestamps (so a time in Australia looks differet from
> >a time in Europe)
> >
> >Probably much more.
> Indeed, you could even add a way to convert between different types if
> they are in the same categories; for example convert between dollars and
> euro's or between degrees Celsius and degrees Fahrenheit (that's a
> trickier one, the shell command 'units' returns wrong results there).
extension to the type system, because I'm sure there are even cooler
uses than what we are thinking of here...
We're talking here about a database with indexes to speed up> OTOH, it's probably not that a good idea to add all kinds of complicated
> (read: "processor intensive") math to a database engine.
intersection tests for arbitrary polygons, extensions to handle
encryption, full text indexing and even builtin XML support. I think
arguing excessive use of CPU cycles is a bit late :)
I think the argument is that if it helps people do their work
"correctly" then it's worth supporting. As long as it doesn't hamper
anybody else.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB9pY0Y5Twig3Ge+YRAizTAKDFAggJRq+pWBH9glCiDg 7EpT8r7wCfQfoA
9WMjAyrDRtJCKY8jKzvA120=
=VJ8J
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Tom Lane #7
Re: Extended unit
Martijn van Oosterhout <kleptog@svana.org> writes:
.... none of which require any extensions to the core type system.> We're talking here about a database with indexes to speed up
> intersection tests for arbitrary polygons, extensions to handle
> encryption, full text indexing and even builtin XML support.
AFAICS this could easily be implemented as a user-defined type, along
the lines of
CREATE TYPE measurement AS (value double, units text);
and if you want to constrain a particular column to contain only one
value of units, use CHECK.
The argument that we should extend the type system for this would become
a lot more credible if there were a widely-used extension in existence
for it to prove that there's sufficient demand.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [email]majordomo@postgresql.org[/email] so that your
message can get through to the mailing list cleanly
Tom Lane Guest
-
Martijn van Oosterhout #8
Re: Extended unit
On Tue, Jan 25, 2005 at 02:31:40PM -0500, Tom Lane wrote:
I've tried this but I can't work out how to make it work. For composite> AFAICS this could easily be implemented as a user-defined type, along
> the lines of
>
> CREATE TYPE measurement AS (value double, units text);
>
> and if you want to constrain a particular column to contain only one
> value of units, use CHECK.
types you can't specify input and output functions. It's all record_in
but it's not working for me:
# CREATE TYPE measurement AS (value float, units text);
CREATE TYPE
# select '(5,a)'::measurement;
ERROR: Cannot cast type "unknown" to measurement
# select measurement(5,'a');
ERROR: Function measurement(integer, "unknown") does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
# select cast( (5,'a') as measurement);
ERROR: parser: parse error at or near "as" at character 22
# select cast( '5' as measurement);
ERROR: Cannot cast type "unknown" to measurement
This is 7.3 though, is it better in later versions? I can't find any
examples anywhere. Composite types don't seems to be used much.
However, it appears you could just update pg_type to change the
input/output functions...
I guess it's mostly syntactic sugar, but it might normalize the> The argument that we should extend the type system for this would become
> a lot more credible if there were a widely-used extension in existence
> for it to prove that there's sufficient demand.
varchar(n) and timestamp(n) format.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB9qt/Y5Twig3Ge+YRAggGAJ0exwHSmXaAxJV8J8d4CEP8f55V1wCg2K 9O
2BFWfntuZXSsvWmJFFiHt6E=
=Bpp1
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Tom Lane #9
Re: Extended unit
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Tue, Jan 25, 2005 at 02:31:40PM -0500, Tom Lane wrote:>> AFAICS this could easily be implemented as a user-defined type, along
>> the lines of
>> CREATE TYPE measurement AS (value double, units text);
>> and if you want to constrain a particular column to contain only one
>> value of units, use CHECK.No, but as of 8.0 you don't really need them, assuming that you don't> I've tried this but I can't work out how to make it work. For composite
> types you can't specify input and output functions.
mind some parentheses around your output.
regression=# CREATE TYPE measurement AS (value float, units text);
CREATE TYPE
regression=# select cast( (5,'a') as measurement);
row
-------
(5,a)
(1 row)
Or you can implement it as a scalar type if you really want to define
your own I/O functions.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email]majordomo@postgresql.org[/email])
Tom Lane Guest
-
Pailloncy Jean-Gerard #10
Re: Extended unit
> ... none of which require any extensions to the core type system.
I have begining to put all the SI unit in a table.>
> AFAICS this could easily be implemented as a user-defined type, along
> the lines of
>
> CREATE TYPE measurement AS (value double, units text);
>
> and if you want to constrain a particular column to contain only one
> value of units, use CHECK.
>
> The argument that we should extend the type system for this would
> become
> a lot more credible if there were a widely-used extension in existence
> for it to prove that there's sufficient demand.
I am writing the function to check the unit in a standard way.
I plan to use the user-defined type proposed by Tom Lane.
The check are done at execution time.
But I object that what I am doing is just a proof of concept and not
the right thing to do.
I do not want for each column and each row to store the value and the
unit.
I do want to put the unit in the definition of the column and the check
on the parser before any execution.
Cordialement,
Jean-Gérard Pailloncy
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Pailloncy Jean-Gerard Guest
-
Tom Lane #11
Re: Extended unit
Pailloncy Jean-Gerard <jg@rilk.com> writes:
> I do not want for each column and each row to store the value and the
> unit.If you do that, you foreclose the ability to store mixed values in a> I do want to put the unit in the definition of the column and the check
> on the parser before any execution.
single column, in return for what? Saving a couple of bytes per value?
(I suppose that in a serious implementation we'd store the units as some
sort of reference, not as a string.) Compare the implementation of the
NUMERIC type: you *can* constrain a column to have a fixed precision,
but you do not *have* to.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
[url]http://archives.postgresql.org[/url]
Tom Lane Guest
-
Richard Huxton #12
Re: Extended unit
Tom Lane wrote:
It strikes me that the right level of constraint is the quantity being> Pailloncy Jean-Gerard <jg@rilk.com> writes:
>>>>I do not want for each column and each row to store the value and the
>>unit.
>>>>I do want to put the unit in the definition of the column and the check
>>on the parser before any execution.
>
> If you do that, you foreclose the ability to store mixed values in a
> single column, in return for what? Saving a couple of bytes per value?
> (I suppose that in a serious implementation we'd store the units as some
> sort of reference, not as a string.) Compare the implementation of the
> NUMERIC type: you *can* constrain a column to have a fixed precision,
> but you do not *have* to.
represented: length / mass / time / velocity.
Then you could store any of: '1inch', '2m', '3km', '4light-years' in a
"length" column.
I was about to say this is similar to the interval type, but of course
there are issues there with month/year not being a consistent length.
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Richard Huxton Guest
-
Martijn van Oosterhout #13
Re: Extended unit
On Tue, Jan 25, 2005 at 11:41:28PM +0100, Pailloncy Jean-Gerard wrote:
Actually, there's no reason to store a string there. Just like for> I have begining to put all the SI unit in a table.
> I am writing the function to check the unit in a standard way.
> I plan to use the user-defined type proposed by Tom Lane.
> The check are done at execution time.
>
> But I object that what I am doing is just a proof of concept and not
> the right thing to do.
> I do not want for each column and each row to store the value and the
> unit.
> I do want to put the unit in the definition of the column and the check
> on the parser before any execution.
timezones, I was proposing having a table listing all the timezones
postgresql knows about and using the oid of that row as the timezone
identifier. This only requires four bytes per field, not unreasonable.
So, you have 1=Amps, 2=Volts, 3=Ohms, etc... It's a little more
querying but if you wrote the functions in C I think you could get it
all fairly performant.
Now, how to store the relationships between them to handle
multiplication and division. Probably go back to base types...
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB93EtY5Twig3Ge+YRAq9wAJ0YJ00fDyawgo0qQCgB1D 0E0/WV2wCgkp6B
PEaFbEMhglUON8EVBsHGfIA=
=fgeP
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Martijn van Oosterhout #14
Re: Extended unit
On Wed, Jan 26, 2005 at 09:06:16AM +0000, Richard Huxton wrote:
Ofcourse, only one of those is in SI units :) Just like the interval> Tom Lane wrote:>> >If you do that, you foreclose the ability to store mixed values in a
> >single column, in return for what? Saving a couple of bytes per value?
> >(I suppose that in a serious implementation we'd store the units as some
> >sort of reference, not as a string.) Compare the implementation of the
> >NUMERIC type: you *can* constrain a column to have a fixed precision,
> >but you do not *have* to.
> It strikes me that the right level of constraint is the quantity being
> represented: length / mass / time / velocity.
>
> Then you could store any of: '1inch', '2m', '3km', '4light-years' in a
> "length" column.
type, all this could be handled by the parser. Define some costant
conversions, after all a light-year is about 9.5e15 metres.
The question is, if you put one inch in, do you expect to get one inch
out?
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB93JOY5Twig3Ge+YRAh+KAJ9nxOpzCh2Mkux6kzjOZt V1/FryuACdHljU
1z8Icql8rD70TRx0Ca+9nvU=
=0SB6
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Pailloncy Jean-Gerard #15
Re: Extended unit
>> It strikes me that the right level of constraint is the quantity being
I'm glad that some understand that I want to have strong type checking>>> represented: length / mass / time / velocity.
>>
>> Then you could store any of: '1inch', '2m', '3km', '4light-years' in a
>> "length" column.
> Ofcourse, only one of those is in SI units :) Just like the interval
> type, all this could be handled by the parser. Define some costant
> conversions, after all a light-year is about 9.5e15 metres.
>
> The question is, if you put one inch in, do you expect to get one inch
> out?
and not multiform filed (with special compound type).
I want that whater is the unit in, the data is coherent.
And the output will be format with convert function.
If I have a column with "speed DOUBLE(m1s-1)"
I want to be able to put in in any unit format.
If I want special output, I would have a function
doubleunit_to_char(speed,'si') that will output "3 m/s" and
doubleunit_to_char(speed,'si','fr') that will output "3 mètre/seconde"
and
doubleunit_to_char(speed,'si','en') that will output "3 meter/second"
and
doubleunit_to_char(speed,'british','en') that will output "xxx
yard/day" ;-)
I am in the process of writing such function to convert from test to an
internal format.
But the problem is that all the work I am doing is about coupound type
(double, unit)
the unit type is an integer with for table for the definition of unit,
convertion and translation in human form.
Cordialement,
Jean-Gérard Pailloncy
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [email]majordomo@postgresql.org[/email] so that your
message can get through to the mailing list cleanly
Pailloncy Jean-Gerard Guest
-
Michael Glaesemann #16
Re: Extended unit
On Jan 26, 2005, at 20:06, Pailloncy Jean-Gerard wrote:
<snip />> I'm glad that some understand that I want to have strong type checking>>>>> It strikes me that the right level of constraint is the quantity
>>> being
>>> represented: length / mass / time / velocity.
>>>
>>> Then you could store any of: '1inch', '2m', '3km', '4light-years' in
>>> a
>>> "length" column.
>> Ofcourse, only one of those is in SI units :) Just like the interval
>> type, all this could be handled by the parser. Define some costant
>> conversions, after all a light-year is about 9.5e15 metres.
>>
>> The question is, if you put one inch in, do you expect to get one inch
>> out?
> and not multiform filed (with special compound type).
>
> I want that whater is the unit in, the data is coherent.
> And the output will be format with convert function.
This reminds me of Date and Darwen's possible representations. You> I am in the process of writing such function to convert from test to
> an internal format.
> But the problem is that all the work I am doing is about coupound type
> (double, unit)
> the unit type is an integer with for table for the definition of unit,
> convertion and translation in human form.
might be interested in some of their writings, in particular "The Third
Manifesto", though they have some papers online as well. Most of what
they discuss is at a more theoretical level rather than implementation,
but it provides some food for thought. Here's a couple of sites. The
second is also includes writings by Fabien Pascal.
[url]http://www.thethirdmanifesto.com/[/url]
[url]http://www.dbdebunk.com/index.html[/url]
Neat stuff, in my opinion.
Michael Glaesemann
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Michael Glaesemann Guest
-
Martijn van Oosterhout #17
Re: Extended unit
On Wed, Jan 26, 2005 at 12:06:15PM +0100, Pailloncy Jean-Gerard wrote:
Sound very cool. Don't forget en_AU should return "metre" and en_US> If I have a column with "speed DOUBLE(m1s-1)"
> I want to be able to put in in any unit format.
> If I want special output, I would have a function
> doubleunit_to_char(speed,'si') that will output "3 m/s" and
> doubleunit_to_char(speed,'si','fr') that will output "3 mètre/seconde"
> and
> doubleunit_to_char(speed,'si','en') that will output "3 meter/second"
> and
> doubleunit_to_char(speed,'british','en') that will output "xxx
> yard/day" ;-)
should return "meter". Not to mention "rods/hogshead" :)
I just thought though, it's going to be impossible to list all possible> I am in the process of writing such function to convert from test to an
> internal format.
> But the problem is that all the work I am doing is about coupound type
> (double, unit)
> the unit type is an integer with for table for the definition of unit,
> convertion and translation in human form.
unit types in a table. There are essentially infinite of them. For
example, the gravitational constant is m3 kg-1 s-2, Plancks constant is
m2 kg s-1, none of which appear in the standard list of derived units.
Unfortunatly, the only bolution I can think of is to encode the units
as numbers in a bitfield. There's only seven base units anyway so if
you allocate 4 bits for each you can fit it all in 32 bits. If you
wanted more units you could cut the usage of mol and cd to two bits
since they don't really need powers from +7 to -8.
You still need the table to do lookups for input and output but it is a
little more flexible.
Any chance of seeing the code, I'd love to play with it...
--
Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]-----BEGIN PGP SIGNATURE-----> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see [url]http://www.gnupg.org[/url]
iD8DBQFB94mUY5Twig3Ge+YRAnB1AKCJLvWtTLmXtREwPWVt+a WMuXFzBwCfQ57l
so10YnGEsZmaYWCCZ/Fy5Lo=
=6dHr
-----END PGP SIGNATURE-----
Martijn van Oosterhout Guest
-
Csaba Nagy #18
Re: Extended unit
Hi all,
I wonder if it makes sense to implement the units as separate data types
? Cause that's what they are really.
So "amper" would be a data type which aliases one of the numeric data
types (depending on what precision range you need), but does not allow
to be added with anything else than "amper". Any other interaction with
other units (read data types) would be achieved by defining the needed
operators on the respective data types (read units).
And all the "unit" stuff could be added as an extension.
Is this a workable solution ?
Cheers,
Csaba.
On Wed, 2005-01-26 at 12:06, Pailloncy Jean-Gerard wrote:> I'm glad that some understand that I want to have strong type checking> >> >> It strikes me that the right level of constraint is the quantity being
> >> represented: length / mass / time / velocity.
> >>
> >> Then you could store any of: '1inch', '2m', '3km', '4light-years' in a
> >> "length" column.
> > Ofcourse, only one of those is in SI units :) Just like the interval
> > type, all this could be handled by the parser. Define some costant
> > conversions, after all a light-year is about 9.5e15 metres.
> >
> > The question is, if you put one inch in, do you expect to get one inch
> > out?
> and not multiform filed (with special compound type).
>
> I want that whater is the unit in, the data is coherent.
> And the output will be format with convert function.
>
> If I have a column with "speed DOUBLE(m1s-1)"
> I want to be able to put in in any unit format.
> If I want special output, I would have a function
> doubleunit_to_char(speed,'si') that will output "3 m/s" and
> doubleunit_to_char(speed,'si','fr') that will output "3 mètre/seconde"
> and
> doubleunit_to_char(speed,'si','en') that will output "3 meter/second"
> and
> doubleunit_to_char(speed,'british','en') that will output "xxx
> yard/day" ;-)
>
> I am in the process of writing such function to convert from test to an
> internal format.
> But the problem is that all the work I am doing is about coupound type
> (double, unit)
> the unit type is an integer with for table for the definition of unit,
> convertion and translation in human form.
>
> Cordialement,
> Jean-Gérard Pailloncy
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to [email]majordomo@postgresql.org[/email] so that your
> message can get through to the mailing list cleanly
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [email]majordomo@postgresql.org[/email] so that your
message can get through to the mailing list cleanly
Csaba Nagy Guest
-
Frank D. Engel, Jr. #19
Re: Extended unit
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
That's not necessarily a constant; there is evidence to suggest that
the speed of light is slowing down over time. If that is indeed the
case, then as light travels more slowly, a light year will become
shorter.
[url]http://www.ldolphin.org/speedo.html[/url]
[url]http://www.ldolphin.org/cdkalan.html[/url]
[url]http://www.answersingenesis.org/docs2002/0809_cdk_davies.asp[/url]
On Jan 26, 2005, at 5:34 AM, Martijn van Oosterhout wrote:- -----------------------------------------------------------> Define some costant
> conversions, after all a light-year is about 9.5e15 metres.
Frank D. Engel, Jr. <fde101@fjrhome.net>
$ ln -s /usr/share/kjvbible /usr/manual
$ true | cat /usr/manual | grep "John 3:16"
John 3:16 For God so loved the world, that he gave his only begotten
Son, that whosoever believeth in him should not perish, but have
everlasting life.
$
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFB957r7aqtWrR9cZoRAsCHAJ4ukBZtXZ4yhNvS8Im9Bx 6AV8oHBQCfdlWa
CdDrwfaHS8SJsMjphYyMZ7s=
=Rjfk
-----END PGP SIGNATURE-----
__________________________________________________ _________
$0 Web Hosting with up to 120MB web space, 1000 MB Transfer
10 Personalized POP and Web E-mail Accounts, and much more.
Signup at [url]www.doteasy.com[/url]
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email]majordomo@postgresql.org[/email])
Frank D. Engel, Jr. Guest
-
Robby Russell #20
Re: Extended unit
On Wed, 2005-01-26 at 08:45 -0500, Frank D. Engel, Jr. wrote:
I don't intend to start any off-topic threads, but the evidence that you> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> That's not necessarily a constant; there is evidence to suggest that
> the speed of light is slowing down over time. If that is indeed the
> case, then as light travels more slowly, a light year will become
> shorter.
>
> [url]http://www.ldolphin.org/speedo.html[/url]
> [url]http://www.ldolphin.org/cdkalan.html[/url]
> [url]http://www.answersingenesis.org/docs2002/0809_cdk_davies.asp[/url]
sighted seems to suggest that the speed of light is slowing down, but it
doesn't explain how it can only be 6,000 years old when scientists are
able to observe the light of stellar objects more than 6,000 light years
away. This would be evidence that would contradict the information that
you have referenced... as it would mean that the age of our universe is
several billions of years old.
I would be more than happy to discuss this off-list with you as I don't
think the postgresql list is the place to debate what is constant or
not..at least not in terms of mythology and mans creation of metaphors
which we overuse to try to explain what all of this is...when we really
haven't the foggiest idea. ;-)
Cheers,
Robby
--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | [url]www.planetargon.com[/url]
* Portland, OR | [email]robby@planetargon.com[/email]
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now hosting PostgreSQL 8.0! ---
****************************************/
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Robby Russell Guest



Reply With Quote

