Using Ecto postgrex hstore

Hello here !

I’m trying to use a hstore column but I’m getting

** (Postgrex.Error) ERROR 42704 (undefined_object) type "hstore" does not exist

https://github.com/elixir-ecto/postgrex mark as supported type

is this the correct way?

  def change do
    create table(:services) do
      add :data, :hstore
      timestamps()
    end

thanks in advance!

As far as I know, you need to run CREATE EXTENSION hstore; for each database that you want to use a hstore column.

2 Likes

Hi, I’m just curious :slight_smile: Why hstore, but not jsonb?

Would there be any reason for preferring jsonb over hstore if the requirement was only for text and there are were no nested objects?

thanks NobbZ! it works

Hello Van!,

I only need a key-value thing, it’s there any performance or reason to use jsonb instead of hstore?
I will need to make filters, groupings and aggregations over the values of this column (and will be a huge table)

Thanks in advance

Craig Kerstiens notes in this blog post:

At this point it’s probably worth replacing hstore use with jsonb in all new applications.

2 Likes

@kip already answered :slight_smile: