Using VSQL as a Calculator: Quick Tip

Posted January 18, 2019 by James Knicely, Vertica Field Chief Technologist

A calculator is something used for making mathematical calculations, in particular a small electronic device with a keyboard and a visual display. VSQL mostly fits that description!

Example: dbadmin=> SELECT 325.25 * 1.60934 "Miles to Kilometers"; Miles to Kilometers --------------------- 523.4378350 (1 row) dbadmin=> SELECT 119.25 * 0.25 "Excellent Waitress's Tip"; Excellent Waitress's Tip -------------------------- 29.8125 (1 row) dbadmin=> SELECT to_char(525 * 40 * 52, '$9,999,999.00') "My Yearly Compensation"; My Yearly Compensation ------------------------ $ 1,092,000.00 (1 row) And for fun, you can also astound your friends using this old calculator trick!

1. Have a buddy pick a number between 1 and 9.

2. Now have him or her use a calculator (i.e. VSQL) to first multiply their number by 9, and then multiply it by 12,345,679 (note there is no 8 in this number).

3. Have the person show you the result so you can tell them the original number they selected!

dbadmin=> SELECT LEFT((1 /* One is my original Number */ * 9 * 12345679)::VARCHAR, 1) "You picked!"; You picked! ------------- 1 (1 row) dbadmin=> SELECT LEFT((2 /* Two is my original Number */ * 9 * 12345679)::VARCHAR, 1) "You picked!"; You picked! ------------- 2 (1 row) dbadmin=> SELECT LEFT((5 /* Five is my original Number */ * 9 * 12345679)::VARCHAR, 1) "You picked!"; You picked! ------------- 5 (1 row) Helpful Link:

https://www.vertica.com/docs/latest/HTML/Content/Authoring/SQLReferenceManual/LanguageElements/Operators/MathematicalOperators.htm

Have fun!