Skip to content

How to filter on JSON column #910

Closed Answered by dantownsend
n4rk0o asked this question in Q&A
Discussion options

You must be logged in to vote

@n4rk0o Thanks for the kind words.

For filtering JSONB columns, you can try the arrow function.

For a table like this:

class RecordingStudio(Table):
    facilities = JSONB()

You can do:

await RecordingStudio.select().where(RecordingStudio.facilities.arrow('foo') != None)

This doesn't work on JSON columns at the moment. - for JSON columns you can use WhereRaw.

from piccolo.query import WhereRaw

await RecordingStudio.select().where(WhereRaw("facilities->>'some key' IS NOT NULL"))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@n4rk0o
Comment options

Answer selected by n4rk0o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants