如何为雪花 SQL UDF 指定任何类型

时间:2020-12-18 23:10:54

标签: sql user-defined-functions snowflake-cloud-data-platform sql-function

雪花 UDF require 指定输入类型。我想使用像 print("\033[1;32;40m Bright Green \n") ##and print('\033[31m' + 'some red text') 这样的函数,它可以将多种数据类型作为输入。如果我尝试在 BigQuery 中使用的内容:

hash

我收到错误 CREATE FUNCTION hash_mod (x any type) returns int AS $$ hash(x) % 100 $$ ;

1 个答案:

答案 0 :(得分:2)

您可以使用 variant 作为类型:

CREATE FUNCTION hash_mod (x variant) returns int AS
$$
hash(x) % 100
$$
;

select hash_mod(1);
select hash_mod(1.1);