ActiveRecordでPostgreSQLのバージョンを調べる
Ludia 1.5でPostgreSQL 8.3対応が行われ、@@演算子が「%%」に変更になった。これに対応するため、PostgreSQLのバージョンを判別する必要があった。
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#postgresql_version
で取得できる。
# PostgreSQL 8.1.11 Entry.connection.send(:postgresql_version) # => 80111 # PostgreSQL 8.3.1 Entry.connection.send(:postgresql_version) # => 80301