Ask a Question related to PostgreSQL / PGSQL, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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)
    2. [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...
    3. 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...
    4. 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...
    5. Test::Unit GUI
      nathaniel@NOSPAMtalbott.ws (nathaniel@NOSPAMtalbott.ws) wrote: Hello Nathaniel! Have you considered to include gtk2 patch for Test::Unit...
  3. #2

    Default Re: Extended unit

    On Tue, Jan 25, 2005 at 10:40:15AM +0100, Pailloncy Jean-Gerard wrote:
    > 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 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.
    > I would appreciate to have such system in PostgreSQL.
    >
    > Do you think, it is feasible ? unrealistic ?
    > Any comment ?
    I think it is definitly feasable. There's been discussion before. I
    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]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  4. #3

    Default Re: Extended unit

    # [email]jg@rilk.com[/email] / 2005-01-25 10:40:15 +0100:
    > 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.
    Is CREATE TYPE what you're looking for?
    [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

  5. #4

    Default Re: Extended unit

    > Is CREATE TYPE what you're looking for?
    > [url]http://www.postgresql.org/docs/8.0/static/sql-createtype.html[/url]
    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

    Pailloncy Jean-Gerard Guest

  6. #5

    Default Re: Extended unit

    Martijn van Oosterhout wrote:
    > 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.
    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).

    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

  7. #6

    Default Re: Extended unit

    On Tue, Jan 25, 2005 at 05:17:21PM +0100, Alban Hertroys wrote:
    > 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).
    I think it would be fabulous if it could be implemented as a generic
    extension to the type system, because I'm sure there are even cooler
    uses than what we are thinking of here...
    > OTOH, it's probably not that a good idea to add all kinds of complicated
    > (read: "processor intensive") math to a database engine.
    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. 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]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  8. #7

    Default Re: Extended unit

    Martijn van Oosterhout <kleptog@svana.org> writes:
    > 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.
    .... none of which require any extensions to the core type system.

    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

  9. #8

    Default Re: Extended unit

    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.
    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. 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...
    > 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 guess it's mostly syntactic sugar, but it might normalize the
    varchar(n) and timestamp(n) format.

    Have a nice day,
    --
    Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  10. #9

    Default 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.
    > 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.
    No, but as of 8.0 you don't really need them, assuming that you don't
    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

  11. #10

    Default Re: Extended unit

    > ... none of which require any extensions to the core type system.
    >
    > 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 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.

    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

  12. #11

    Default 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.
    > 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.

    regards, tom lane

    ---------------------------(end of broadcast)---------------------------
    TIP 6: Have you searched our list archives?

    [url]http://archives.postgresql.org[/url]

    Tom Lane Guest

  13. #12

    Default Re: Extended unit

    Tom Lane wrote:
    > 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.
    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.

    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

  14. #13

    Default Re: Extended unit

    On Tue, Jan 25, 2005 at 11:41:28PM +0100, Pailloncy Jean-Gerard wrote:
    > 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.
    Actually, there's no reason to store a string there. Just like for
    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]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  15. #14

    Default Re: Extended unit

    On Wed, Jan 26, 2005 at 09:06:16AM +0000, Richard Huxton wrote:
    > 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.
    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?

    Have a nice day,
    --
    Martijn van Oosterhout <kleptog@svana.org> [url]http://svana.org/kleptog/[/url]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  16. #15

    Default Re: Extended unit

    >> 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?
    I'm glad that some understand that I want to have strong type checking
    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

  17. #16

    Default Re: Extended unit


    On Jan 26, 2005, at 20:06, Pailloncy Jean-Gerard wrote:
    >>> 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?
    > I'm glad that some understand that I want to have strong type checking
    > 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.
    <snip />
    > 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.
    This reminds me of Date and Darwen's possible representations. You
    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

  18. #17

    Default Re: Extended unit

    On Wed, Jan 26, 2005 at 12:06:15PM +0100, Pailloncy Jean-Gerard wrote:
    > 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" ;-)
    Sound very cool. Don't forget en_AU should return "metre" and en_US
    should return "meter". Not to mention "rods/hogshead" :)
    > 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.
    I just thought though, it's going to be impossible to list all possible
    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]
    > 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.
    -----BEGIN PGP SIGNATURE-----
    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

  19. #18

    Default 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:
    > >> 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?
    > I'm glad that some understand that I want to have strong type checking
    > 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

  20. #19

    Default 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

  21. #20

    Default Re: Extended unit

    On Wed, 2005-01-26 at 08:45 -0500, Frank D. Engel, Jr. wrote:
    > -----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]
    I don't intend to start any off-topic threads, but the evidence that you
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139