DISTINCT FROM to compare NULL-able values in Postgres
It turns out I’ve been comparing potentially null values in postgres the wrong way for years. Any comparisons will a null value result in null so null <> 3 isn’t true it’s null. To avoid this I would do something like coalesce(potentially_null_field, 0) <> 3 when I could have instead done potentially_null_field IS DISTINCT FROM 3. For example I want to find books written by authors from a different country and include results where country is listed on the author or book, but null on the other table.
Sagemaker Aurora Postgres Terraform
This post will outline a minimal end to end sagemaker setup using terraform. This setup includes setting up the sagemaker domain, notebook instance, endpoint, and all the associated roles and policies. At the end of this post you should have a trained sagemaker model deployed that can be accessed through an aurora postgres stored procedure call. How cool is that.
TIL Selecting the last item in a postgres array
To get the last item from a postgres array SELECT errors[array_upper(errors, 1)] FROM oban.oban_jobs Oban is a great elixir job processing library. It tracks job attempts and errors with a full stack trace in a postgres errors array column. This is great to have but hard to reason about looking at the giant blob. The above snippet let’s you limit it to just the most recent error which is really all you care about.
TIL Elixir - Inspect.Opts, deep cuts
Since the day I started picking up elixir I’ve been using IO.inspect/2’s to debug and check code outputs. Because it will return whatever its passed, you can paste |> IO.inspect()’s pretty much anywhere without changing the program. Even though I’ve been using this for years I recently learned about some new options to fine tune the inspect behavior. See all the options here: https://hexdocs.pm/elixir/Inspect.Opts.html Options I have pretty much always used :label