Thread: [HACKERS] Index expression syntax
I wonder why syntax error is produced in this case:
postgres=# create index metaindex on foo using gin(to_tsvector('english', x)||to_tsvector('english',y));
ERROR: syntax error at or near "||"
LINE 1: ...taindex on foo using gin(to_tsvector('english', x)||to_tsvec...
^
The error can be eliminated if extra surrounding parentheses are added:
postgres=# create index metaindex on foo using gin((to_tsvector('english', x)||to_tsvector('english',y)));
CREATE INDEX
Postgresql documentations says:
postgres=# create index metaindex on foo using gin(to_tsvector('english', x)||to_tsvector('english',y));
ERROR: syntax error at or near "||"
LINE 1: ...taindex on foo using gin(to_tsvector('english', x)||to_tsvec...
^
The error can be eliminated if extra surrounding parentheses are added:
postgres=# create index metaindex on foo using gin((to_tsvector('english', x)||to_tsvector('english',y)));
CREATE INDEX
Postgresql documentations says:
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ]name
] ONtable_name
[ USINGmethod
] ( {column_name
| (expression
) } [ COLLATEcollation
] [opclass
] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ) [ WITH (storage_parameter
=value
[, ... ] ) ] [ TABLESPACEtablespace_name
] [ WHEREpredicate
]
expression:
- An expression based on one or more columns of the table. The expression usually must be written with surrounding parentheses, as shown in the syntax. However, the parentheses can be omitted if the expression has the form of a function call.
- ----------
- So documentations states that sometimes it is possible to avoid parentheses, but it is unclear why I have to use double parentheses...
- I think that either grammar should be fixed, either documentation should be updated.
-- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
- I think that either grammar should be fixed, either documentation should be updated.
On Fri, Sep 29, 2017 at 9:31 AM, Konstantin Knizhnik <k.knizhnik@postgrespro.ru> wrote:
I wonder why syntax error is produced in this case:
postgres=# create index metaindex on foo using gin(to_tsvector('english', x)||to_tsvector('english',y));
ERROR: syntax error at or near "||"
LINE 1: ...taindex on foo using gin(to_tsvector('english', x)||to_tsvec...
^
[ .. ]
expression:
- An expression based on one or more columns of the table. The expression usually must be written with surrounding parentheses, as shown in the syntax. However, the parentheses can be omitted if the expression has the form of a function call.
- So documentations states that sometimes it is possible to avoid parentheses, but it is unclear why I have to use double parentheses...
- I think that either grammar should be fixed, either documentation should be updated.
Your expression is clearly not a function call, it's a concatenation of two of them. The documentation seems perfectly accurate to me?
.m
On 29.09.2017 11:03, Marko Tiikkaja wrote:
O, sorry!On Fri, Sep 29, 2017 at 9:31 AM, Konstantin Knizhnik <k.knizhnik@postgrespro.ru> wrote:I wonder why syntax error is produced in this case:
postgres=# create index metaindex on foo using gin(to_tsvector('english', x)||to_tsvector('english',y));
ERROR: syntax error at or near "||"
LINE 1: ...taindex on foo using gin(to_tsvector('english', x)||to_tsvec...
^
[ .. ]
expression:
- An expression based on one or more columns of the table. The expression usually must be written with surrounding parentheses, as shown in the syntax. However, the parentheses can be omitted if the expression has the form of a function call.
- So documentations states that sometimes it is possible to avoid parentheses, but it is unclear why I have to use double parentheses...
- I think that either grammar should be fixed, either documentation should be updated.
Your expression is clearly not a function call, it's a concatenation of two of them. The documentation seems perfectly accurate to me?
You are right. I just didn't notice extra parenthesis in CREATE INDEX syntax in case of using expressions.
-- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company