【问题标题】:Can anyone explain :: meaning in postgresql? [duplicate]谁能解释postgresql中的 :: 含义? [复制]
【发布时间】:2015-01-12 22:08:44
【问题描述】:

我有以下查询可以正常工作,但不知道 :: 在 postgresql 中的含义和用法。

select (
    select ( 
        case when 1 > 0 then 1::float / (
            select count(id) from transactions_products where transaction_id in (
            select id from transactions_transactions tt 
            where status = 3 and fi = 355 
                and (invoice_date >= 1420754400) 
                and (invoice_date <= 1421099999) 
                and (tt.division_id = 107) 
                and (tt.department_id = 210) 
        ) and is_vehicle = 1 
    )::float else 0 end)
 limit 1) as f_4

【问题讨论】:

标签: postgresql


【解决方案1】:

:: 是 PostgreSQL 的 cast 运算符。

【讨论】:

  • 在mysql中是不可能的吗?
  • 是的 - 使用cast()
  • 而且 CAST() 也是标准 SQL,适用于许多支持某种形式的 SQL 的数据库。
【解决方案2】:

简短、轻松的回答:它将值转换为浮点数。

【讨论】:

  • 您可能需要详细说明您的答案。仅仅说它会产生价值并不是很有用。为什么要转换一个值?有没有更好的用例示例?
  • 我明白你的意思,但是这篇文章只会变成对类型转换的目的、优点和缺点的一般性讨论。
  • 您无需深入了解该级别的详细信息,只需解释您为什么要使用一个或为 OP 继续提供一些东西。你假设每个人都知道什么是铸造。请注意,最重要的答案包含指向更多信息的链接。
  • 这确实是一个更好的答案。感谢您的反馈!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-27
相关资源
最近更新 更多