Skip to content
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 index_predicate example to README #832

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,29 @@ book.reload.title # => "Book1" (stayed the same)
book.reload.author # => "Bob Barker" (changed)
```

PostgreSQL Using partial indexes

```ruby
book = Book.create! title: "Book1", author: "George Orwell", published_at: Time.now
book.author = "Bob Barker"

# in migration
execute <<-SQL
CREATE INDEX books_published_at_index ON books (published_at) WHERE published_at IS NOT NULL;
SQL

# PostgreSQL version
Book.import [book], on_duplicate_key_update: {
conflict_target: [:id],
index_predicate: "published_at IS NOT NULL",
columns: [:author]
}

book.reload.title # => "Book1" (stayed the same)
book.reload.author # => "Bob Barker" (changed)
book.reload.published_at # => 2017-10-09 (stayed the same)
```

PostgreSQL Using constraints

```ruby
Expand Down