sangeethailango
How to use postgrex interval datatype
Hey fellow learners,
I have a field called estimated_hours in one of my Ash resource called tasks. I want the datatype of this field to be Postgres interval. I want to calculate how many hours does user wants to complete a task and i will also calculate the sum of these estimated hours.
I found the documentation below from Hex Docs:
https://hexdocs.pm/postgrex/Postgrex.Interval.html
I have also searched for Postgres interval datatype and went through the below tutorial.
However, I couldn’t figure out how to apply it in my Ash resource.
Please help me to find out how I can do it.
Most Liked
zachdaniel
Hello!
So in Ash, the primary drive for this would be a custom type. Something like:
defmodule MyApp.Interval do
use Ash.Type
def storage_type(_), do: :interval # you'll have to experiment with what the appropriate storage_type is here
# define cast_input, cast_stored, dump_to_native
end
I haven’t wrapped a built in Postgrex type in quite some time, but take a look at the docs for Ash.Type for info on defining a custom type, that may be enough to get it over the line ![]()







