Using Ecto postgrex hstore

ecto
phoenix

#1

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!


#2

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


#3

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


#4

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


#5

thanks NobbZ! it works


#6

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


#7

Craig Kerstiens notes in this blog post:

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


#8

@kip already answered :slight_smile: