You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL SQL错误:统计子查询唯一ID时出现double precision输入无效

嵌套SQL统计唯一ID时触发类型转换错误

执行一条包含多层嵌套子查询的SQL语句时,仅在外层尝试统计子查询中的唯一item_id时触发错误,单独运行各子查询均正常。

错误提示:

ERROR: invalid input syntax for type double precision: "promo_email_click"

我对此感到困惑:查询中未显式使用double precision类型,也未涉及"promo_email_click"相关内容。

附上的SQL语句如下:

SELECT 
    COUNT(distinct test_) AS unique_item_ids_in_window
FROM
    (SELECT
         -- only pull item_ids
         int_item_id AS test_
     FROM
         (SELECT
              -- create a binary label for the events, where each event is either in the 30 days after test started window (1) or not (0)
              int_item_id,
              time_of_item_view,
              (CASE 
                   WHEN time_of_item_view > '2015-03-14 00:00:00' 
                        AND time_of_item_view < '2015-04-13 00:00:00' 
                       THEN CAST('1' as INT)
                       ELSE CAST('0' AS INT)
               END) AS In_30_day_window
          FROM
              -- for the view_item events, turn the 'parameter value' from a string  to a float
              (SELECT 
                   CAST (parameter_value AS FLOAT) AS int_item_id,
                   event_time AS time_of_item_view
               FROM 
                   -- select only view_item events
                   (SELECT *
                    FROM dsv1069.events 
                    WHERE events.event_name = 'view_item') AS only_view_items
           ) AS parameter_value_turned_to_float   
       ) AS only_in_30_day_window
WHERE 
    only_in_30_day_window.In_30_day_window = 1) AS ONLY_in_30_day_window_yes
GROUP BY 
    ONLY_in_30_day_window_yes.test_
        -- tried ordering by test_ but keep getting an error

尝试对子查询使用聚合函数时反复出现该错误:

org.postgresql.util.PSQLException: ERROR: invalid input syntax for type double precision: "promo_email_click"

内容的提问来源于stack exchange,提问作者Alexander Saul Goldman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:29:50