Home > other >  How can I get the length of a property in a jsonb in postgres?
How can I get the length of a property in a jsonb in postgres?

Time:11-27

product
---------------------------
{"id":1, "code": "1231313"}

this is the query i made, but it doesn't work

SELECT * FROM public.order WHERE "product" ->> LENGTH('code') = '7';

I would like to know how I can get the length of the value of this property from a jsonb, please help me, thanks.

CodePudding user response:

Below is the way to use the ->> operator to extract field from a column of type JSON(B) and then apply length() to get the text length.

select * from public.order where length(product->>'code') >= 7

See the various operators/functions to get data from JSON(B) column type, Postgresql documentation

  • Related