运算符不存在:interval> integer

wal*_*ing 5 sql postgresql

我有一个查询适用于Postgresql 7.4但不适用于具有相同数据库的Postgresql 8.3.

查询:

SELECT * FROM login_session WHERE (now()-modified) > timeout;
Run Code Online (Sandbox Code Playgroud)

获取以下错误:

ERROR:  operator does not exist: interval > integer
LINE 1: ...ELECT * FROM login_session WHERE (now()-modified) > timeout ...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

modified是a timestamp并且timeoutinteger.

我需要在服务器上更改一些设置吗?

我正在新服务器(ubuntu)上为客户端安装应用程序,因此我无法在应用程序中更改查询.

Mil*_*dev 7

7.4和8.3之间有很多变化.一些最激烈的是删除一些自动演员阵容.

我想"超时"是几秒钟?如果是这样,您可以将查询更改为:

SELECT
    *
FROM
    login_session
WHERE
    (CURRENT_TIMESTAMP - modified) > (timeout * '1 sec'::interval);
Run Code Online (Sandbox Code Playgroud)


geo*_*car 3

create or replace function int2interval (x integer) returns interval as $$ select $1*'1 sec'::interval $$ language sql;
create cast (integer as interval) with function int2interval (integer) as implicit;
Run Code Online (Sandbox Code Playgroud)

应该这样做。