Postgresql: trigram indexes for searching
When full text search is overkill and like queries do not deliver this might be an approach you could try...
Related cards:
Trigram indexing as an alternative to PostgreSQL fulltext search
For searching in large database tables we usually use PostgreSQL's fulltext search capabilities.
While this works reasonably well for content primarily consisting of prose, it is not necessarily a good solution for all use case...
A simple example with a GIN index in Rails for optimizing a ILIKE query
You can improve your LIKE
/ ILIKE
search queries in PostgreSQL by adding a GIN index with an operate class ("opclass") to split the [words into trigr...
PostgreSQL cheat sheet for MySQL lamers
So you're switching to PostgreSQL from MySQL? Here is some help...
General hints on PostgreSQL
-
\?
opens the command overview -
\d
lists things:\du
lists users,\dt
lists tables etc
Command comparison
| Description | MySQL comm...
Understanding race conditions with duplicate unique keys in Rails
validates_uniqueness_of
is not sufficient to ensure the uniqueness of a value. The reason for this is that in production, multiple worker processes can cause race conditions:
- Two concurrent requests try to create a user with the same name (a...
Performance analysis of MySQL's FULLTEXT indexes and LIKE queries for full text search
When searching for text in a MySQL table, you have two choices:
- The LIKE operator
- [FULLTEXT](http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html...
MySQL: How to create columns like "bigint" or "longtext" in Rails migrations, and what :limit means for column migrations
Rails understands a :limit
options when you create columns in a migration. Its meaning depends on the column type, and sometimes the supplied value.
[The documentation](http://apidock.com/rails/ActiveRecord/ConnectionAdapters/TableDefinition/co...
PostgreSQL: How to add/remove/modify array values (and how to replace 1 value with multiple values)
PostgreSQL's array data type is pretty useful, but manipulating values of arrays can be awkward because of its syntax.
Consider the following users
table which each example below will sta...
How to query PostgreSQL's json fields from Rails
PostgreSQL offers a really handy field type: json
. You can store any JSON there, in any structure.
While its flexibility is great, there is no syntactic sugar in Rails yet. Thus, you need to manually query the database.
Demo
# Given...
PostgreSQL: Ordering, NULLs, and indexes
When using ORDER BY "column"
in PostgreSQL, NULL
values will come last.
When using ORDER BY "column" DESC
, NULL
s will come first. This is often not useful.
Luckily, you can tell PostgeSQL where you want your NULL
s, by saying
......
Rails index route for resources named after uncountable substantives
Using uncountable resources is not recommended as it breaks Rails' magic, e.g. when using form_for
. You'll always be better off using simple pluralizable resources.
Rails automatically creates path names for routes defined via the `res...