Postgresql 错误:运算符不存在:日期~~未知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42449756/
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
Postgresql ERROR: operator does not exist: date ~~ unknown
提问by pmiranda
When I do this query, I have no problems:
当我做这个查询时,我没有问题:
SELECT a.value, b.label AS campo, 'date' AS tipo
FROM contenido.field_value_textarea a
JOIN estructura.field b ON a.field=b.id
WHERE a.value LIKE '%aaa%'
contenido.field_value_textarea is character varying(2000)
contenido.field_value_textarea 是 character varying(2000)
But if I try to select from:
但是,如果我尝试从以下选项中进行选择:
contenido.field_value_fecha which type is date
I got this error message:
contenido.field_value_fecha 哪种类型是date
我收到此错误消息:
ERROR: operator does not exist: date ~~ unknown
错误:运算符不存在:日期~~未知
What I'm trying to do is searching between different tables, each query select FROM it's table. Some tables use text values, textarea values, integer values, and it works, but when the value is date
all fails. What can I do?
我想要做的是在不同的表之间搜索,每个查询从它的表中选择。一些表使用文本值、文本区域值、整数值,它可以工作,但是当值date
全部失败时。我能做什么?
EDIT: By the way, my date values are like this: 2009-05-01
编辑:顺便说一下,我的日期值是这样的:2009-05-01
回答by joanolo
The ~~
operator is actually the LIKE
operator.
该~~
运营商实际上是LIKE
运营商。
You are trying to use an expression that looks like:
您正在尝试使用如下所示的表达式:
contenido.field_value_fecha.value LIKE '%aaaa%'
That is, you're trying to compare a date with a string (which, without the adequate context, is considered to be of type 'unknown'), and decide if the date looks like something.
也就是说,您试图将日期与字符串(如果没有足够的上下文,被认为是“未知”类型)进行比较,并确定日期是否看起来像某个东西。
If you actually want to do such a comparison, you need to convert the date to a string, which can be done by means of:
如果你真的想做这样的比较,你需要将日期转换为字符串,可以通过以下方式完成:
contenido.field_value_fecha.value::text LIKE '%aaaa%'
or (using standard SQL):
或(使用标准 SQL):
CAST(contenido.field_value_fecha.value AS text) LIKE '%aaaa%'
This will be syntactically correct... Whether it is meaningful or not, is a different part of the story.
这在句法上是正确的……它是否有意义,是故事的不同部分。