redshift中的日志功能

时间:2018-10-18 14:43:18

标签: sql amazon-redshift

我正在尝试运行以下查询。

CREATE TEMP TABLE tmp_variables AS SELECT 
   0.99::numeric(10,8) AS y ;

select y, log(y) from tmp_variables

它给了我以下错误。有办法解决这个问题吗?

[Amazon](500310) Invalid operation: Specified types or functions (one per INFO message) not supported on Redshift tables.;
Warnings:
Function "log(numeric,numeric)" not supported.

2 个答案:

答案 0 :(得分:1)

一种解决方法是改用“ float”。

CREATE TEMP TABLE tmp_variables AS SELECT 
   0.99::float AS y ;
select y, log(y) from tmp_variables

工作正常并返回

  

y日志

     

0.99 -0.004364805402450088

答案 1 :(得分:1)

LOG函数需要一个数据类型为“ double precision”的参数。您的代码传入的数据类型为“数字”,这就是为什么您遇到错误。

这将起作用:

CREATE TEMP TABLE tmp_variables AS 
   SELECT 0.99::numeric(10,8) AS y ;

select y, log(cast(y as double precision)) from tmp_variables;