Ash FrameworkAF
Ash Framework3y ago
16 replies
Blibs

Support for Postgres generated columns

Postgres supports creating columns that are generated when the row is inserted, updated.

In my case, I have a property that has its address separated into multiple columns and I want to create a special field that will have the concatenation of all these fields.

I was wondering if AshPostgres has support for that feature.

What I tried so far was creating a specific statement to create the field in the migration:

      statement :create_normalized_full_address_field do
        up "alter table properties add column normalized_full_address generated always as (street_name || ' ' || city) stored;"
        down "alter table properties drop column normalized_full_address;"
      end


But I don't know how to add that attribute into the resource in a way that will not create it already when generating the migration file.

Also, it would be great to have a way to do it without using a custom statement, but I'm fine with that.
Was this page helpful?