You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, I have only encountered the problem on column with position as name.
Expected behavior
This should dump properly the index the schema.rb.
Something like t.index ["position"], name: "gin_index_position_on_players", opclass: :gin_trgm_ops, using: :gin
Actual behavior
It creates an index wihtout an opclass in the db/schema.rb. Here is what is created: t.index ["position"], name: "gin_index_position_on_positions", using: :gin
Investigations done on my own
Creating indexes seems fine.
However, while checking the created indexes in db using
select *
from pg_indexes
where tablename = 'players';
The indexdef of the index related to the position column is different. The colum name is wrapped with double quotes. indexdef:CREATE INDEX gin_index_position_on_players ON public.players USING gin ("position" gin_trgm_ops)
I did not find out why this particular word is wrapped up (other postgres reserved words are not wrapped up, other built-in functions are not wrapped up).
The issue occurs while parsing the indexdef in activerecord-5.2.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:127.
It could be fixed by adding this edge case to the regexp.
The text was updated successfully, but these errors were encountered:
ThomBian
changed the title
opclass is not parsed whenever the indexed column in the indexdef is wrapped by quotes
opclass is not parsed whenever the indexed column in the indexdef is wrapped by quotes
Nov 20, 2018
Steps to reproduce
Add a gin index on a colum with a name
position
.At the moment, I have only encountered the problem on column with
position
as name.Expected behavior
This should dump properly the index the
schema.rb
.Something like
t.index ["position"], name: "gin_index_position_on_players", opclass: :gin_trgm_ops, using: :gin
Actual behavior
It creates an index wihtout an
opclass
in thedb/schema.rb
. Here is what is created:t.index ["position"], name: "gin_index_position_on_positions", using: :gin
Investigations done on my own
Creating indexes seems fine.
However, while checking the created indexes in db using
The
indexdef
of the index related to theposition
column is different. The colum name is wrapped with double quotes.indexdef
:CREATE INDEX gin_index_position_on_players ON public.players USING gin ("position" gin_trgm_ops)
I did not find out why this particular word is wrapped up (other postgres reserved words are not wrapped up, other built-in functions are not wrapped up).
The issue occurs while parsing the
indexdef
inactiverecord-5.2.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:127
.It could be fixed by adding this edge case to the regexp.
Why does this occurs
After deeper explanations, I land on https://www.postgresql.org/docs/current/sql-keywords-appendix.html and it seems that this behavior happens on the
non reserved (cannot be function or type)
keyword.System configuration
Rails version: 5.2.1
Ruby version: 2.5.3
The text was updated successfully, but these errors were encountered: