[英]PostgreSQL interval invalidate
select date,
to_char(shares, '99g999g999g999') as shares,
to_char(trades, '99g999g999') as trades,
to_char(dollars, 'L99g999g999g999') as dollars
from facebook
where date >= '2017-02-01' + interval '1 months'
order by date;
message: ERROR: invalid input syntax for type interval: "2017-02-01"
LINE 6: where date >= '2017-02-01' + interval '1 months
I know there is one way to do it by declare a date variable.我知道有一种方法可以通过声明一个日期变量来实现。 so the code would be
所以代码是
date >= date: 'Variable' + interval '1 month'
But I don't know how to set a date variable in PGadmin.但我不知道如何在 PGadmin 中设置日期变量。
'2017-02-01'
is treated as a string literal, not as a date literal. '2017-02-01'
被视为字符串文字,而不是日期文字。 To make Postgres recognize it as a proper date
value, use a proper date literal.要使 Postgres 将其识别为正确的
date
值,请使用正确的日期文字。
I prefer using ANSI date literals, which are strings prefixed with the keyword date
我更喜欢使用 ANSI 日期文字,它们是以关键字
date
为前缀的字符串
where date >= date '2017-02-01' + interval '1 months'
Note that your choice of the column name date
makes this quite confusing.请注意,您选择的列名
date
会使这非常混乱。 The date
on the left side refers to the column .左侧的
date
是指列。 The date
prefixing the string literal refers to the data type name.字符串文字前缀的
date
是指数据类型名称。 To avoid the confusion, don't use reserved words (eg data types) as column names.为避免混淆,请勿使用保留字(例如数据类型)作为列名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.