【问题标题】:Check if a number is int or float in Amazon Redshift在 Amazon Redshift 中检查数字是整数还是浮点数
【发布时间】:2020-04-15 17:40:36
【问题描述】:

我有一个查询,我需要检查一个数字是整数还是浮点数。在 Amazon Redshift 中似乎没有一种简单的方法可以做到这一点。

有人能指点一下如何做到这一点吗?

isint(<number>) 这样的东西会很棒。

提前非常感谢。

【问题讨论】:

    标签: sql amazon-redshift


    【解决方案1】:

    我也有同样的问题。我已经这样解决了。如果对一个数字进行四舍五入后,得到的数字始终等于原始数字,则为整数;否则,它不是。

    select
    
    case
        when round(0.5, 0) = 0.5 then 'Not Integer'
        when round(1, 0) = 1 then 'Integer'
    end as check
    

    【讨论】:

      【解决方案2】:

      以下内容:

      SELECT pg_typeof(4);
      

      返回integer,而对于4.5,它返回numeric

      文档:https://www.postgresql.org/docs/9.3/functions-info.html

      【讨论】:

      • 感谢您的回答,但这是一个 Postgres 功能,Redshift 不支持。
      猜你喜欢
      • 1970-01-01
      • 2018-03-20
      • 2011-04-22
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多