Postgres, like Elixir, has both floating point division and integer division. In the example you show, you are asking Postgres to do integer division because both operands are integers. And the result of 424 / 1256 will therefore be 0 and casting 0 to float will be, as you saw, 0.0.
Therefore you’ll need to cast the columns sum_of_post_words and total_posts into floats before the division.
Something like (not tested):
Post
|> select_merge([p], %{post_length_avg: fragment("sum_of_post_words::double / total_posts::double)})
|> Repo.all()