Search code examples
postgresqlpostgisjsonb

Postgis: Get value from json type column


I have column with lat/lon values in this format:

{ "lat": 35.910067092299997, "lon": -79.074502748100002 }

I think that is JSON format so I try using some example I found, including this type of operators ->> @> ... but nothing works, the query still not executes.

What I'm doing wrong? Example of errors I get:

ERROR:  operator does not exist: character varying @> unknown

Solution

  • Your error told you that your left side of your equation is "character varying" (text data type with fixed length) so you cannot use json operators on it. First, you have to cast it to json or jsonb type and then all work perfectly fine.

    select '{ "lat": 35.910067092299997, "lon": -79.074502748100002 }'::json->'lat'