大写SQL语句在Snowflake存储过程中不起作用

时间:2019-11-20 21:38:24

标签: snowflake-data-warehouse

在下面的示例中,working_one存储过程起作用,而broken_one不起作用。两者之间的唯一区别是SQL语句的字母大小写。

create table tmp (
  raw_json variant
);

-- 2019-01-01 = 1546347600000
-- 2018-01-01 = 1514811600000
insert into tmp select parse_json('{ "timestamp":1514811600000}');

create or replace procedure working_one(TIME_VALUE varchar)
returns varchar
language javascript
as
$$
var stmtString = "delete from tmp where to_timestamp(raw_json:timestamp::string) < to_timestamp(:1);"
var stmt = snowflake.createStatement({sqlText: stmtString, binds: [TIME_VALUE]})
var rs = stmt.execute()
rs.next()
return rs.getColumnValue(1)
$$;

create or replace procedure broken_one(TIME_VALUE varchar)
returns varchar
language javascript
as
$$
var stmtString = "DELETE FROM TMP WHERE TO_TIMESTAMP(RAW_JSON:TIMESTAMP::STRING) < TO_TIMESTAMP(:1);"
var stmt = snowflake.createStatement({sqlText: stmtString, binds: [TIME_VALUE]})
var rs = stmt.execute()
rs.next()
return rs.getColumnValue(1)
$$;

call broken_one('1546347600000');
call working_one('1546347600000');

1 个答案:

答案 0 :(得分:3)

我认为问题不在于SQL的区分大小写,甚至不在于存储过程。问题在于JSON中的属性区分大小写。尝试一下,告诉我是否更适合您。

create or replace procedure fixed_one(TIME_VALUE varchar)
returns varchar
language javascript
as
$$
var stmtString = "DELETE FROM TMP WHERE TO_TIMESTAMP(RAW_JSON:timestamp::STRING) < TO_TIMESTAMP(:1);"
var stmt = snowflake.createStatement({sqlText: stmtString, binds: [TIME_VALUE]})
var rs = stmt.execute()
rs.next()
return rs.getColumnValue(1)
$$;