K
K
Klaus Kater2015-08-31 14:51:22
PostgreSQL
Klaus Kater, 2015-08-31 14:51:22

What is the correct way to use json in PostgreSQL?

Hello, I've run into a problem.
Not so long ago, postgres has support for json data, and I'm trying to use it. But I missed something ..
There is a request, in 2 tables, in one of which there is a json field.

SELECT*
FROM "profile" 
INNER JOIN "util_template" ON ( "profile"."template_id" = "util_template"."id" ) 
WHERE ("profile"."member_id" = 3 AND "profile"."company_id" = 1 
AND (((util_template.list_actions)::json ->'OwnerVehicleViewSet')->>'create') IS NOT NULL )

The problem is that postgresql swears at almost json statements. In this case, it throws an error:
ERROR: invalid input syntax for type json
SQL-состояние: 22P02
Подробности: Expected "," or "]", but found ":".
Контекст: JSON data, line 1: {"OwnerVehicleViewSet":["post":...

Tried options:
((util_roletemplate.list_actions)::json -> "OwnerVehicleViewSet")->>"create")

ERROR:  column "OwnerVehicleViewSet" does not exist
LINE 13: AND (((util_roletemplate.list_actions)::json -> "OwnerVehicl...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klaus Kater, 2015-08-31
@kurojneko

The problem was in the data in the database, a charfield format data column, and of course I wrote incorrect json there. Everything crashed when trying to parse the json from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question