【问题标题】:PostgreSQL-Error in 'yyyy;-Value should be integerPostgreSQL-'yyyy 中的错误;-值应该是整数
【发布时间】:2017-12-26 03:41:14
【问题描述】:

我在 PostgreSQL 上写了以下命令:

create table Daily_Winners as (
    select d.* from 
    (
        select row_number() over(partition by "request_date",
                                              "revised_circle" 
                                 order by "earned_score" desc,
                                          "count_of_attempts" asc) rn,
                * 
        from 
        (
            select a.*,b.count_of_attempts, last_que_attempt 
            from
            (
                select msisdn, revised_circle, 
                       to_date(left(a.request_date,10),'yyyy-mm-dd')request_date,
                       sum(cast(score as numeric(10,0))) Earned_Score 
                from Airtel_season13_circles_final a  
                where upper(a.ans_type)='CA' 
                group by Revised_Circle, 
                         to_date(left(a.request_date,10),'yyyy-mm-dd'),
                         msisdn
            )a 
            join 
            (
                select distinct revised_circle, 
                       to_date(left(a.request_date,10),'yyyy-mm-dd')request_date,
                       msisdn,
                       count(distinct transaction_id) count_of_attempts, 
                       max(to_timestamp(request_date, 'YYYY-MM-DD HH24:MI:SS')::timestamp without time zone)last_que_attempt 
                from Airtel_season13_circles_final a 
                group by revised_circle, 
                         to_date(left(a.request_date,10),'yyyy-mm-dd'),
                         msisdn
            )b 
            on a.msisdn=b.msisdn and a.revised_circle=b.revised_circle
            and a.request_date=b.request_date
        )c
    )d 
     where d.rn<=20)

这个执行给了我以下错误:

错误:“yyyy”的值“requ”无效
详细信息:值必须是 整数。

有人可以帮忙吗?任何建议将不胜感激。谢谢。

【问题讨论】:

    标签: postgresql date datetime postgresql-9.3


    【解决方案1】:

    您的字段request_date 似乎是一个文本,并且对于至少一行,最左边的 4 个字符不是 4 位数字,而是字符串 REQU。

    当您尝试将字符串转换为日期时,您指定了格式,并且没有与您指定的格式兼容的值

    --> 你必须要么过滤你的坏数据,要么修正你的字符串精确度,或者更好的是,将日期保存在 date 字段中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 2011-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多