how to resolve function datediff(unknown, timestamp without time zone, timestamp without time zone) does not exist

huangapple go评论67阅读模式
英文:

how to resolve function datediff(unknown, timestamp without time zone, timestamp without time zone) does not exist

问题

"SELECT "reviewedAt", "createdAt", DATEDIFF('hour', "createdAt"::timestamp, "reviewedAt"::timestamp) as hours_approved from "yadda$prod"."Application""

"error [42883] ERROR: function datediff(unknown, timestamp without time zone, timestamp without time zone) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 36"

英文:
SELECT "reviewedAt", "createdAt", DATEDIFF('hour', "createdAt"::timestamp, "reviewedAt"::timestamp) as hours_approved from "yadda$prod"."Application" 

error [42883] ERROR: function datediff(unknown, timestamp without time zone, timestamp without time zone) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 36

答案1

得分: 5

尝试这个:

SELECT 
    "reviewedAt",
    "createdAt",
    DATE_PART('day', "reviewedAt"::timestamp - "createdAt"::timestamp) * 24 + DATE_PART('hour', "reviewedAt"::timestamp - "createdAt"::timestamp) AS hours_approved 
FROM "yadda$prod"."Application"
英文:

Try This:

SELECT 
"reviewedAt",
"createdAt",
DATE_PART('day', "reviewedAt"::timestamp - "createdAt"::timestamp) * 24 + DATE_PART('hour', "reviewedAt"::timestamp - "createdAt"::timestamp) AS hours_approved 
FROM "yadda$prod"."Application"

答案2

得分: 1

以下是翻译好的部分:

另一种解决方案:

    选择
        "reviewedAt",
        "createdAt",
        (提取("reviewedAt" :: timestamp - "createdAt" :: timestamp的时间差的秒数/3600)::int2 AS hours_approved
    从 "yadda$prod"."Application";
英文:

One more solution:

SELECT 
    "reviewedAt",
    "createdAt",
    (EXTRACT(EPOCH FROM "reviewedAt"::timestamp - "createdAt"::timestamp)/3600)::int2 AS hours_approved
FROM "yadda$prod"."Application";

huangapple
  • 本文由 发表于 2020年1月6日 23:35:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定