The KM2MILES and MILES2KM Functions

Moderator: NorbertKrupa

Post Reply
User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

The KM2MILES and MILES2KM Functions

Post by JimKnicely » Thu Dec 13, 2012 2:19 pm

1 mile equals 1.6093440000000016479682560000017 kilometers and 1 kilometer equals 0.62137119223733333333333333333333 miles…

But who wants to remember those facts?

If we need to do either of these conversions in the database, we can simply use the KM2MILES function to convert kilometers to miles and the MILES2KM function to convert miles to kilometers!

Examples:

Code: Select all

cognos=> SELECT KM2MILES(300),
cognos->        MILES2KM(186.4113576712);
    KM2MILES    | MILES2KM
----------------+----------
186.4113576712  |     300
(1 row)

Code: Select all

dbadmin=> SELECT MILES2KM(70)        "PA Turnpike Speed Limit (Km)",
dbadmin->        KM2MILES(8850)      "Great Wall of China Length (Miles)",
dbadmin->        KM2MILES(4.5061632) "Pacific Ocean Average Depth (Miles)";
 PA Turnpike Speed Limit (Km) | Great Wall of China Length (Miles) | Pacific Ocean Average Depth (Miles)
------------------------------+------------------------------------+-------------------------------------
                    112.65408 |                   5499.13505130041 |                                 2.8
(1 row)
Note: These functions are not available by default. You'll have to install the Geospatial SQL Functions! Check the SQL Reference manual to see how to install them.
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica Tips, Lessons and Examples”