Creating an Identity referencing a key within a :map attribute (postgres-stored jsonb)
I have a resource with these attributes:
I'd like to create an identity on the resource that uses a key within the map. Is that possible?
Specifically, I'd like to upsert using this identity. I'm seeing recommendations for Ecto to just do it manually in the database and wondering if there's an Ash Way.
3 Replies
There is not currently a great way to do this with ash_postgres 😦
You can create the unique constraint easily enough using the custom_indexes tools in ash_postgres
But upserting on it is not likely going to work.
Well, it definitely won’t, but is unlikely to be something we can make work in the near future.
ok, got it.
so for reference what I'm doing right now (as a "workaround", but it works the same) is just extracting the values I want to key on from the json before sending it all to ash, and I have those keys as real attributes in the resource with an identity defined on them. Working great. Those specific keys should be stable.
I /would/ like, in another area, to /select and filter/ based on the contents of the jsonb, which is why I figured I'd try to jump right in with upserting on it. Is reading, filtering, etc supported?
(The data has over five hundred fields in an unstable "schema", that's why I'm using jsonb. I've been informed postgres wouldn't take kindly to that many columns.)
Yep! You can use bracket access in expressions , I.e
map[:key]