Description
In SQL Server, we have Computed Columns to create a virtual column derived from other values in the record. Importantly, these fields can be stored, which then allows indexing. Rails 7 introduced support for virtual columns.
I was looking to add a feature to a Rails app that leveraged SQL Server's spatial indexes, converting lat/lon to a geography::Point
value. Ideally, given a lat/lon, this value is automatically created and indexed.
Ideally this would be able to be described in a rails migration as
add_column :zip_codes, :point, :geography, as: 'geography::Point([lat], [lon], 4326)', stored: true
Now, this specific example also required adding a geography
type mapping, but that's a separate feature.
I reviewed the changes made in the PostgreSQL adapter to support this and I think it seems mostly translatable. I didn't get beyond sniffing out similar concepts and queries between the two.