If you have a :string or :text field, you should pair it with a model validation that restricts its length...
TL;DR PostgreSQL handles Rails 4+ text and string columns the same. Some libraries may still reflect on the column...
We can use ActiveRecord's where to add conditions to a relation. But sometimes our condition is not on the...
PostgreSQL and ActiveRecord have a good support for storing dynamic attributes (hashes) in columns of type JSONB. But sometimes you...
It's every developer's nightmare: SQL queries that get large and unwieldy. This can happen fairly quickly with the...
There is an issue with when restoring a PostgreSQL dump created with pg_dump < v11 with pg_restore > v10:
As an application exists, data accumulates. While you'll be loosely monitoring the main models' record count, some supportive database...
Travis changed their default distribution from Ubuntu 14.04 (trusty) to 16.04 (precise). This might break your test setup for new...
When doing some meta-programming magic and you want to do something for all attributes of a class, you may...
If you have a PostgreSQL dump in the custom format you can can view the text format dump (plain SQL...
For searching in large database tables we usually use PostgreSQL's fulltext search capabilities. While this works reasonably well for...
When restoring a PostgreSQL dump using pg_restore, you usually add the --clean flag to remove any existing data from...
To remove all tables from a database (but keep the database itself), you have two options. Option 1: Drop the...
When projects run for many years, they require special regular maintenance to stay fresh. This kind of maintenance is usually...
Setting array columns When using PostgreSQL array columns, you can set an array attribute to a value with square brackets...
When you need to store structured data (like Ruby hashes) in a single database column with ActiveRecord, a simple way...
When you have a large PG database, you may want to find out which tables are consuming the most disk...
Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot...
geordi delete_dumps [directory] Recursively search for files ending in *.dump and offer to delete those. When no...
Your default postgres user is named like your linux user. That default user has limited access privileges, which can cause...
This is an extension to PostgreSQL vs MySQL: How to UPDATE using a JOIN. UPDATE employees SET department_name = departments.name...
This is a small example on how you can check if your Postgres index can be used by a specific...
PostgreSQL's Common Table Expressions (CTEs) can be used to extract sub-queries from bulky SQL statements into a temporary...
PostgreSQL supports the SQL OVERLAPS operator. You can use it to test if two date ranges overlap: => SELECT ('2001-02...