You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
2.8 KiB

26 years ago
26 years ago
26 years ago
26 years ago
  1. --------------
  2. CREATE FUNCTION metaphon RETURNS STRING SONAME "udf_example.so"
  3. --------------
  4. Query OK, 0 rows affected
  5. --------------
  6. CREATE FUNCTION myfunc_double RETURNS REAL SONAME "udf_example.so"
  7. --------------
  8. Query OK, 0 rows affected
  9. --------------
  10. CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so"
  11. --------------
  12. Query OK, 0 rows affected
  13. --------------
  14. CREATE FUNCTION lookup RETURNS STRING SONAME "udf_example.so"
  15. --------------
  16. Query OK, 0 rows affected
  17. --------------
  18. CREATE FUNCTION reverse_lookup RETURNS STRING SONAME "udf_example.so"
  19. --------------
  20. Query OK, 0 rows affected
  21. --------------
  22. CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "udf_example.so"
  23. --------------
  24. Query OK, 0 rows affected
  25. --------------
  26. CREATE FUNCTION myfunc_argument_name RETURNS STRING SONAME "udf_example.so"
  27. --------------
  28. Query OK, 0 rows affected
  29. --------------
  30. select metaphon("hello")
  31. --------------
  32. metaphon("hello")
  33. HL
  34. 1 row in set
  35. --------------
  36. select myfunc_double("hello","world")
  37. --------------
  38. myfunc_double("hello","world")
  39. 108.40
  40. 1 row in set
  41. --------------
  42. select myfunc_int(1,2,3),myfunc_int("1","11","111")
  43. --------------
  44. myfunc_int(1,2,3) myfunc_int("1","11","111")
  45. 6 6
  46. 1 row in set
  47. --------------
  48. select lookup("localhost")
  49. --------------
  50. lookup("localhost")
  51. 127.0.0.1
  52. 1 row in set
  53. --------------
  54. select reverse_lookup("127.0.0.1")
  55. --------------
  56. reverse_lookup("127.0.0.1")
  57. localhost
  58. 1 row in set
  59. --------------
  60. create temporary table t1 (a int,b double)
  61. --------------
  62. Query OK, 0 rows affected
  63. --------------
  64. insert into t1 values (1,5),(1,4),(2,8),(3,9),(4,11)
  65. --------------
  66. Query OK, 5 rows affected
  67. Records: 0 Duplicates: 5 Warnings: 0
  68. --------------
  69. select avgcost(a,b) from t1
  70. --------------
  71. avgcost(a,b)
  72. 8.7273
  73. 1 row in set
  74. --------------
  75. select avgcost(a,b) from t1 group by a
  76. --------------
  77. avgcost(a,b)
  78. 4.5000
  79. 8.0000
  80. 9.0000
  81. 11.0000
  82. 4 rows in set
  83. --------------
  84. select a, myfunc_argument_name(a) from t1;
  85. --------------
  86. a myfunc_argument_name(a) myfunc_argument_name(a as b)
  87. 1 a b
  88. 1 a b
  89. 2 a b
  90. 3 a b
  91. 4 a b
  92. 5 rows in set
  93. --------------
  94. drop table t1
  95. --------------
  96. Query OK, 0 rows affected
  97. --------------
  98. DROP FUNCTION metaphon
  99. --------------
  100. Query OK, 0 rows affected
  101. --------------
  102. DROP FUNCTION myfunc_double
  103. --------------
  104. Query OK, 0 rows affected
  105. --------------
  106. DROP FUNCTION myfunc_int
  107. --------------
  108. Query OK, 0 rows affected
  109. --------------
  110. DROP FUNCTION lookup
  111. --------------
  112. Query OK, 0 rows affected
  113. --------------
  114. DROP FUNCTION reverse_lookup
  115. --------------
  116. Query OK, 0 rows affected
  117. --------------
  118. DROP FUNCTION avgcost
  119. --------------
  120. Query OK, 0 rows affected
  121. --------------
  122. DROP FUNCTION myfunc_argument_name;
  123. --------------
  124. Query OK, 0 rows affected
  125. Bye