jet icon indicating copy to clipboard operation
jet copied to clipboard

[Question] How to use JSONB types in where clauses

Open masterkidan opened this issue 3 years ago • 3 comments

Hello, Thanks for this great lib!. I happen to use a lot of JSONB types for postgres. One of the scenarios I have is to do a WHERE clause on a key value in a jsonb column, this would normally be something like this in postgres

insert into orders values(<valuelist>) on conflict(id) do update set (valuelist) where info ->> 'version' > excluded.info->>'version' 

Whats the JET way of representing the above statement?

masterkidan avatar Jul 28 '22 08:07 masterkidan

Hi @masterkidan. Json expressions are currently not supported. You'll have to use raw expressions:

.WHERE(RawBool("info ->> 'version' > excluded.info->>'version'"))

go-jet avatar Jul 28 '22 15:07 go-jet

@go-jet , is RawBool not available for postgres?

Hmm, you're right RawBool is missing. Use BoolExp(Raw("info ->> 'version' > excluded.info->>'version'") instead. RawBool is just a short hand notation of BoolExp(Raw()).

go-jet avatar Feb 20 '23 10:02 go-jet