在函数调用中声明日期和空值
Declaring Dates and Nulls in function calls
当我调用函数时,例如
SELECT * FROM TABLE(FN_ABC(NULL::DATE , '2022-04-07'::DATE ))
Snowflake 强制我将传递给数据类型(例如 DATE)的参数绑定到上述所有 NULL。
有没有办法避免绑定它们?我已经在我的函数中将它们声明为 DATES
即不带数据类型直接调用它
SELECT * FROM TABLE(FN_ABC(NULL, '2022-04-07'))
原因是这些参数是作为 NULL 或 2022-04-07 从网页传递的
谢谢
你的 sql 不是两个日期,它是一个未定义的类型,和一个 string/text/varchar.
select
null as a
,'2022-04-07' as b
,system$typeof(a) as t_a
,system$typeof(b) as t_b
,a::date as d_a
,b::date as d_b
,system$typeof(d_a) as t_da
,system$typeof(d_b) as t_db
A
B
T_A
T_B
D_A
D_B
T_DA
T_DB
null
2022-04-07
NULL[LOB]
VARCHAR(10)[LOB]
null
2022-04-07
DATE[SB4]
DATE[SB4]
因此使用这些值会给您带来错误:
001044 (42P13): SQL compilation error: error line 1 at position 21
Invalid argument types for function 'FN_ABC': (NULL, VARCHAR(10))
但是如果你已经有DATE
个值,就没有问题了:
with data as (
select
null as a
,'2022-04-07' as b
,system$typeof(a) as t_a
,system$typeof(b) as t_b
,a::date as d_a
,b::date as d_b
,system$typeof(d_a) as t_da
,system$typeof(d_b) as t_db
)
SELECT
f.*
FROM data as d
,table(fn_abc(d.d_a, d.d_b)) f;
运行,很好
X
Y
null
2022-04-07
当我调用函数时,例如
SELECT * FROM TABLE(FN_ABC(NULL::DATE , '2022-04-07'::DATE ))
Snowflake 强制我将传递给数据类型(例如 DATE)的参数绑定到上述所有 NULL。
有没有办法避免绑定它们?我已经在我的函数中将它们声明为 DATES
即不带数据类型直接调用它
SELECT * FROM TABLE(FN_ABC(NULL, '2022-04-07'))
原因是这些参数是作为 NULL 或 2022-04-07 从网页传递的
谢谢
你的 sql 不是两个日期,它是一个未定义的类型,和一个 string/text/varchar.
select
null as a
,'2022-04-07' as b
,system$typeof(a) as t_a
,system$typeof(b) as t_b
,a::date as d_a
,b::date as d_b
,system$typeof(d_a) as t_da
,system$typeof(d_b) as t_db
A | B | T_A | T_B | D_A | D_B | T_DA | T_DB |
---|---|---|---|---|---|---|---|
null | 2022-04-07 | NULL[LOB] | VARCHAR(10)[LOB] | null | 2022-04-07 | DATE[SB4] | DATE[SB4] |
因此使用这些值会给您带来错误:
001044 (42P13): SQL compilation error: error line 1 at position 21
Invalid argument types for function 'FN_ABC': (NULL, VARCHAR(10))
但是如果你已经有DATE
个值,就没有问题了:
with data as (
select
null as a
,'2022-04-07' as b
,system$typeof(a) as t_a
,system$typeof(b) as t_b
,a::date as d_a
,b::date as d_b
,system$typeof(d_a) as t_da
,system$typeof(d_b) as t_db
)
SELECT
f.*
FROM data as d
,table(fn_abc(d.d_a, d.d_b)) f;
运行,很好
X | Y |
---|---|
null | 2022-04-07 |