clickhouse支持udf,通过ambda表达式使用

    • UDF
      用户可通过添加lambda表达式,创建自定义Function
      CREATE FUNCTION linear_equation AS (x, k, b) -> k*x + b;
      SELECT number, linear_equation(number, 2, 1) FROM numbers(3);
      
      SELECT
          number,
          linear_equation(number, 2, 1)
      FROM numbers(3)
      
      Query id: 9a4a2978-b186-4bc2-ac0c-86daf0328212
      
      ┌─number─┬─plus(multiply(2, number), 1)─┐
      │      0 │                            1 │
      │      1 │                            3 │
      │      2 │                            5 │
      └────────┴──────────────────────────────┘
      
      3 rows in set. Elapsed: 0.002 sec. 
      
      CREATE FUNCTION parity_str AS (n) -> if(n % 2, 'odd', 'even');
      SELECT number, parity_str(number) FROM numbers(3);
      
      SELECT
          number,
          parity_str(number)
      FROM numbers(3)
      
      Query id: 59a97a32-15c4-4417-8444-51cb00a01ac0
      
      ┌─number─┬─if(modulo(number, 2), 'odd', 'even')─┐
      │      0 │ even                                 │
      │      1 │ odd                                  │
      │      2 │ even                                 │
      └────────┴──────────────────────────────────────┘
      
      3 rows in set. Elapsed: 0.002 sec. 

       

上一篇:SQL+ORACLE (笔试面试基础)


下一篇:第14章视图