Luís Ramalho

Entrepreneur & Developer

About me

PostgreSQL Case Sensitivity for a Rails Active Record Query 21 June 2012

PostgreSQL has case sensitivity and converts column names to lowercase when trying to do an Active Record Query. An error like the one below will occur:

  PG::Error: ERROR:  column "some_column" does not exist
LINE 1: SELECT "some_table".* FROM "some_table"  WHERE (SOME_UPPERCASE_COLUMN = 'some_value')

In order to solve this problem just escape quotes, likes this:

  Class.all(conditions: ["\"SOME_UPPERCASE_COLUMN\" = ?", 'some_value'])

Problem fixed!