此查询按预期工作:
# select start_date + (duration * (interval '1 second')) from mytable;
?column?
---------------------
2016-06-30 19:00:00
(1 row)
但是当尝试用它创建表达式索引时,会出现语法错误:
# create index on mytable (start_date + (duration * (interval '1 second')));
ERROR: syntax error at or near "+"
LINE 1: ...reate index on mytable (start_date + (duratio...
答案 0 :(得分:4)
您还需要一组额外的括号。这有点尴尬,但是postgres知道如何将其解析为表达式:
# create index on mytable (start_date + (duration * (interval '1 second')));
ERROR: syntax error at or near "+"
# create index on mytable ((start_date + (duration * (interval '1 second'))));
CREATE INDEX