postgresql 如何解决“错误:运算符不存在:”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28474419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:47:19  来源:igfitidea点击:

How to solve 'ERROR: operator does not exist: '?

sqlpostgresqltimestampcomparison-operatorsbigint

提问by Stephan

I have a table created like this:

我有一个这样创建的表:

CREATE TABLE revinfo
(
   rev integer NOT NULL,
   revtstmp bigint,
   CONSTRAINT revinfo_pkey PRIMARY KEY (rev)
)

Inside this table, I have data like this:

在这张表中,我有这样的数据:

rev  |revtstmp 
40815|1390021342972
40816|1390021401403
40817|1390021409057
40818|1390021409914
40819|1390021411074
40821|1390021463885
40822|1390021467889
40824|1390021469035
40826|1390021470065
40827|1390021472134
...

I want to list all revisions made after the 10th of February 2015. I tried this request:

我想列出 2015 年 2 月 10 日之后所做的所有修订。我尝试了这个请求:

select rev
from revinfo
where revtstmp > '2015-02-10 00:00:00'::timestamp

I hit this error:(see translation below)

我遇到了这个错误:(见下面的翻译)

ERREUR:  l'opérateur n'existe pas : bigint > timestamp without time zone
LINE 3: where revtstmp > '2015-02-12 00:00:00'::timestamp
                       ^
HINT:  Aucun opérateur ne correspond au nom donné et aux types d'arguments.
Vous devez ajouter des conversions explicites de type.
********** Erreur **********

ERREUR: l'opérateur n'existe pas : bigint > timestamp without time zone
état SQL :42883
Astuce : Aucun opérateur ne correspond au nom donné et aux types d'arguments.
Vous devez ajouter des conversions explicites de type.
Caractère : 47

How can I change my query ?

如何更改我的查询?



Translation (powered by Google Translate)

翻译(由谷歌翻译提供支持)

ERROR: operator does not exist: bigint> timestamp without time zone
LINE 3: where revtstmp> '2015-02-12 0:00:00' :: timestamp
^
HINT: No operator matches the given name and argument types.
You must add explicit type conversions.
********** ********** Error

ERROR: operator does not exist: bigint> timestamp without time zone
SQL State: 42883
Tip: No operator matches the given name and argument types.
You must add explicit type conversions.
Character: 47

回答by a_horse_with_no_name

Your column revtstmpis not a timestamp, so you cannot compare it to one.

您的列revtstmp不是时间戳,因此您无法将其与时间戳进行比较。

Assuming that it is a "unix epoch" value, you can however convert a timestamp to a bigint quite easily:

假设它是一个“unix epoch”值,你可以很容易地将时间戳转换为 bigint:

select rev
from revinfo
where revtstmp > extract(epoch from '2015-02-10 00:00:00'::timestamp);

But in general it's better to store the information as a timestampcolumn, not as a bigint. That makes many queries a lot easier to write (and to read & understand)

但一般来说,最好将信息存储为timestamp列,而不是 bigint。这使得许多查询更容易编写(以及阅读和理解)

回答by Mladen Uzelac

You are storing revtstmp as bigint. You cannot compare timestamp and bigint. Convert your revtstmp to timestamp or use the same format when you declare timestamp in comparisons

您将 revtstmp 存储为 bigint。您无法比较时间戳和 bigint。将您的 revtstmp 转换为时间戳或在比较中声明时间戳时使用相同的格式