Search code examples
peeweepostgresql-9.4jsonb

Join query for Postgres 9.4 JSONB field using Peewee ORM


Am using peewee in one of my projects and being from a Django background, i like it great.

Am planning to use the newly introduced JSONB in postgres 9.4 extensively. However, I have no clue to how can I perform a join operation using JSONB keys.

I assume an example would be excellent for the whole community.


Solution

  • You can write something like this:

    User.select().join(Metadata, on=Metadata.data['user_id'] == User.id)
    

    Where Metadata.data is a JSON field.