-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Expression Indexes and Operator Classes support for PostgreSQL #23393
Conversation
r? @kaspth (@rails-bot has picked a reviewer for you, use r? to override) |
90a0bb8
to
807cf0c
Compare
e7ca3b4
to
790b9ca
Compare
bcb0904
to
82b0ba4
Compare
82b0ba4
to
7c67195
Compare
7c67195
to
d3cef16
Compare
Added opclasses support. |
Using a proc suggests that we expect a dynamic result, rather than using the special value to indicate an expression index. How would this compare to using an new keyword argument, like create_table :users do |t|
t.string :name
t.index expression: 'lower(name)'
t.index opclass: 'name varchar_pattern_ops'
end |
Expressions and opclasses can be specified at the same time. http://www.postgresql.org/docs/9.5/static/sql-createindex.html
create_table :users do |t|
t.string :first_name
t.string :last_name
t.index -> { <<-EXPRESSIONS }
first_name || last_name,
upper(first_name) varchar_pattern_ops,
lower(last_name) varchar_pattern_ops
EXPRESSIONS
end |
Gotcha. In that case, compare with e.g. create_table :users do |t|
t.string :first_name
t.string :last_name
t.index expression: <<-EXPRESSIONS
first_name || last_name,
upper(first_name) varchar_pattern_ops,
lower(last_name) varchar_pattern_ops
EXPRESSIONS
end |
We already have using procs syntax for schema and attribute default expression. Do we prefer new |
Good point. Generally prefer keyword arguments for new constant-value arguments. Using a proc has worked well to bypass quoting or indicate SQL literals. So it makes sense to stick with them. This usage looks a lot more like passing a block to an index method, though. The other cases are keyword arg values, clear that they're 'special' values vs passing a proc/block. |
d3cef16
to
b4b28af
Compare
Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes rails#19090. Fixes rails#21765. Fixes rails#21819. Fixes rails#24359.
b4b28af
to
099e9d0
Compare
I changed implementation in This PR. This does not introduce new syntax now. create_table :users do |t|
t.string :first_name
t.string :last_name
t.index <<-EXPRESSIONS
first_name || last_name,
upper(first_name) varchar_pattern_ops,
lower(last_name) varchar_pattern_ops
EXPRESSIONS
end How about it? |
Merged edc2b77 😊 |
Example:
Fixes #19090.
Fixes #21765.
Fixes #21819.
Fixes #24359.